| 1 | <?php |
||
| 7 | class SimpleHandlerFactory implements HandlerFactoryInterface |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | private $handlers; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param array $handlers |
||
| 16 | */ |
||
| 17 | 4 | public function __construct(array $handlers = []) |
|
| 21 | |||
| 22 | /** |
||
| 23 | * @inheritdoc |
||
| 24 | */ |
||
| 25 | 4 | public function get($handler) |
|
| 26 | { |
||
| 27 | 4 | $route = $this->getHandler($handler); |
|
| 28 | 4 | if (!$route) { |
|
| 29 | 1 | throw HandlerException::notFound($handler); |
|
| 30 | } |
||
| 31 | |||
| 32 | 3 | if (is_string($route) && class_exists($route)) { |
|
| 33 | 1 | $route = new $route; |
|
| 34 | 1 | } |
|
| 35 | |||
| 36 | 3 | if (is_callable($route)) { |
|
| 37 | 2 | return $route; |
|
| 38 | } |
||
| 39 | |||
| 40 | 1 | throw HandlerException::invalidHandler($handler); |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Get the handler |
||
| 45 | * |
||
| 46 | * @param string $handler |
||
| 47 | * |
||
| 48 | * @return mixed|null |
||
| 49 | */ |
||
| 50 | 4 | private function getHandler($handler) |
|
| 54 | } |
||
| 55 |