-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimpleRouter.php
More file actions
31 lines (28 loc) · 865 Bytes
/
SimpleRouter.php
File metadata and controls
31 lines (28 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
namespace DesignPatterns\Creational\FactoryMethod\SimpleApplication;
use DesignPatterns\Creational\FactoryMethod\RequestInterface;
use DesignPatterns\Creational\FactoryMethod\RouterInterface;
/**
* It corresponds to `ConcreteProduct` in the Factory Method pattern.
*
* @author Vlad Riabchenko <contact@vria.eu>
*/
class SimpleRouter implements RouterInterface
{
/**
* @param RequestInterface $request
* @return callable
* @throws \Exception
*/
public function resolveHandler(RequestInterface $request)
{
switch ($request->getRequestURL()) {
case '/':
return [SimpleController::class, 'homeAction'];
case '/contact.html':
return [SimpleController::class, 'contactAction'];
default:
throw new \Exception("404");
}
}
}