1 | <?php |
||
39 | class Router implements RouterInterface |
||
40 | { |
||
41 | /** |
||
42 | * Array for storing known routes |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $routes = []; |
||
47 | |||
48 | /** |
||
49 | * String containing the basis host of the application, if this is set |
||
50 | * this parameter will be removed from the hostname before hostparameters are extracted, |
||
51 | * so having a low parameter count won't falsify the parameters by using the basic host as parameters |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $baseHost = null; |
||
56 | |||
57 | /** |
||
58 | * @var LoggerInterface |
||
59 | */ |
||
60 | protected $log; |
||
61 | |||
62 | /** |
||
63 | * @var ContainerInterface |
||
64 | */ |
||
65 | protected $container; |
||
66 | |||
67 | /** |
||
68 | * @param LoggerInterface $log |
||
69 | * @param ContainerInterface $container |
||
70 | */ |
||
71 | public function __construct(LoggerInterface $log, ContainerInterface $container) |
||
76 | |||
77 | /** |
||
78 | * add route to list of known routes |
||
79 | * |
||
80 | * @param String $route beginning string of the route |
||
81 | * @param String $class to be used for this route |
||
82 | * @param String $action method to be called |
||
83 | * @param string[] $parameters list of parameters that should be retrieved from url |
||
84 | * @param array $hostparameters - allows to use subdomains as parameters |
||
85 | * @return self |
||
86 | */ |
||
87 | public function addRoute($route, $class, $action, $parameters = [], $hostparameters = []) |
||
99 | |||
100 | /** |
||
101 | * method to set the basicHost for hostparameters in routing |
||
102 | * |
||
103 | * @see King23_Router::$basicHost |
||
104 | * @param String $baseHost |
||
105 | * @return self |
||
106 | */ |
||
107 | public function setBaseHost($baseHost = null) |
||
113 | |||
114 | /** |
||
115 | * @param ServerRequestInterface $request |
||
116 | * @param RequestHandlerInterface $next |
||
117 | * @return ResponseInterface |
||
118 | * @throws \King23\Controller\Exceptions\ActionDoesNotExistException |
||
119 | */ |
||
120 | public function process(ServerRequestInterface $request, RequestHandlerInterface $next) : ResponseInterface { |
||
139 | |||
140 | /** |
||
141 | * Handle a regular route |
||
142 | * |
||
143 | * @param array $info |
||
144 | * @param ServerRequestInterface $request |
||
145 | * @param string $route |
||
146 | * @return ResponseInterface |
||
147 | * @throws \King23\Controller\Exceptions\ActionDoesNotExistException |
||
148 | */ |
||
149 | private function handleRoute($info, ServerRequestInterface $request, $route) : ResponseInterface |
||
177 | |||
178 | /** |
||
179 | * @param array $info |
||
180 | * @param array $params |
||
181 | * @return array |
||
182 | */ |
||
183 | private function filterParameters($info, $params) |
||
195 | |||
196 | /** |
||
197 | * extract parameters from hostname |
||
198 | * |
||
199 | * @param ServerRequestInterface $request |
||
200 | * @param array $info |
||
201 | * @return array |
||
202 | */ |
||
203 | private function extractHostParameters($request, $info) |
||
216 | |||
217 | /** |
||
218 | * will get hostname, and clean basehost off it |
||
219 | * |
||
220 | * @param ServerRequestInterface $request |
||
221 | * @return string |
||
222 | */ |
||
223 | private function cleanHostName(ServerRequestInterface $request) |
||
238 | } |
||
239 |