1 | <?php |
||
29 | class SplashDefaultRouter implements MiddlewareInterface |
||
30 | { |
||
31 | /** |
||
32 | * The container that will be used to fetch controllers. |
||
33 | * |
||
34 | * @var ContainerInterface |
||
35 | */ |
||
36 | private $container; |
||
37 | |||
38 | /** |
||
39 | * List of objects that provide routes. |
||
40 | * |
||
41 | * @var UrlProviderInterface[] |
||
42 | */ |
||
43 | private $routeProviders = []; |
||
44 | |||
45 | /** |
||
46 | * The logger used by Splash. |
||
47 | * |
||
48 | * @var LoggerInterface |
||
49 | */ |
||
50 | private $log; |
||
51 | |||
52 | /** |
||
53 | * Splash uses the cache service to store the URL mapping (the mapping between a URL and its controller/action). |
||
54 | * |
||
55 | * @var CacheItemPoolInterface |
||
56 | */ |
||
57 | private $cachePool; |
||
58 | |||
59 | /** |
||
60 | * The default mode for Splash. Can be one of 'weak' (controllers are allowed to output HTML), or 'strict' (controllers |
||
61 | * are requested to return a ResponseInterface object). |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | private $mode; |
||
66 | |||
67 | /** |
||
68 | * In debug mode, Splash will display more accurate messages if output starts (in strict mode). |
||
69 | * |
||
70 | * @var bool |
||
71 | */ |
||
72 | private $debug; |
||
73 | |||
74 | /** |
||
75 | * @var ParameterFetcher[] |
||
76 | */ |
||
77 | private $parameterFetcherRegistry; |
||
78 | |||
79 | /** |
||
80 | * The base URL of the application (from which the router will start routing). |
||
81 | * |
||
82 | * @var string |
||
83 | */ |
||
84 | private $rootUrl; |
||
85 | |||
86 | /** |
||
87 | * (optional) Handles HTTP 400 status code. |
||
88 | * |
||
89 | * @var Http400HandlerInterface |
||
90 | */ |
||
91 | private $http400Handler; |
||
92 | |||
93 | /** |
||
94 | * (optional) Handles HTTP 404 status code (if no $out provided). |
||
95 | * |
||
96 | * @var Http404HandlerInterface |
||
97 | */ |
||
98 | private $http404Handler; |
||
99 | |||
100 | /** |
||
101 | * (optional) Handles HTTP 500 status code. |
||
102 | * |
||
103 | * @var Http500HandlerInterface |
||
104 | */ |
||
105 | private $http500Handler; |
||
106 | |||
107 | /** |
||
108 | * @Important |
||
109 | * |
||
110 | * @param ContainerInterface $container The container that will be used to fetch controllers. |
||
111 | * @param UrlProviderInterface[] $routeProviders |
||
112 | * @param ParameterFetcherRegistry $parameterFetcherRegistry |
||
113 | * @param CacheItemPoolInterface $cachePool Splash uses the cache service to store the URL mapping (the mapping between a URL and its controller/action) |
||
114 | * @param LoggerInterface $log The logger used by Splash |
||
115 | * @param string $mode The default mode for Splash. Can be one of 'weak' (controllers are allowed to output HTML), or 'strict' (controllers are requested to return a ResponseInterface object). |
||
116 | * @param bool $debug In debug mode, Splash will display more accurate messages if output starts (in strict mode) |
||
117 | * @param string $rootUrl |
||
118 | */ |
||
119 | public function __construct(ContainerInterface $container, array $routeProviders, ParameterFetcherRegistry $parameterFetcherRegistry, CacheItemPoolInterface $cachePool = null, LoggerInterface $log = null, string $mode = SplashUtils::MODE_STRICT, bool $debug = true, string $rootUrl = '/') |
||
130 | |||
131 | /** |
||
132 | * @param Http400HandlerInterface $http400Handler |
||
133 | */ |
||
134 | public function setHttp400Handler($http400Handler) |
||
140 | |||
141 | /** |
||
142 | * @param Http404HandlerInterface $http404Handler |
||
143 | */ |
||
144 | public function setHttp404Handler($http404Handler) |
||
150 | |||
151 | /** |
||
152 | * @param Http500HandlerInterface $http500Handler |
||
153 | */ |
||
154 | public function setHttp500Handler($http500Handler) |
||
160 | |||
161 | /** |
||
162 | * Process an incoming request and/or response. |
||
163 | * |
||
164 | * Accepts a server-side request and a response instance, and does |
||
165 | * something with them. |
||
166 | * |
||
167 | * If the response is not complete and/or further processing would not |
||
168 | * interfere with the work done in the middleware, or if the middleware |
||
169 | * wants to delegate to another process, it can use the `$out` callable |
||
170 | * if present. |
||
171 | * |
||
172 | * If the middleware does not return a value, execution of the current |
||
173 | * request is considered complete, and the response instance provided will |
||
174 | * be considered the response to return. |
||
175 | * |
||
176 | * Alternately, the middleware may return a response instance. |
||
177 | * |
||
178 | * Often, middleware will `return $out();`, with the assumption that a |
||
179 | * later middleware will return a response. |
||
180 | * |
||
181 | * @param ServerRequestInterface $request |
||
182 | * @param ResponseInterface $response |
||
183 | * @param null|callable $out |
||
184 | * |
||
185 | * @return null|ResponseInterface |
||
186 | */ |
||
187 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null) |
||
211 | |||
212 | /** |
||
213 | * @param ServerRequestInterface $request |
||
214 | * @param ResponseInterface $response |
||
215 | * @param callable|null $out |
||
216 | * |
||
217 | * @return ResponseInterface |
||
218 | */ |
||
219 | private function route(ServerRequestInterface $request, ResponseInterface $response, callable $out = null, $retry = false) : ResponseInterface |
||
335 | |||
336 | /** |
||
337 | * Purges the cache if one of the url providers tells us to. |
||
338 | */ |
||
339 | private function purgeExpiredRoutes() |
||
360 | |||
361 | /** |
||
362 | * Returns the list of all SplashActions. |
||
363 | * This call is LONG and should be cached. |
||
364 | * |
||
365 | * @return array<SplashAction> |
||
366 | */ |
||
367 | public function getSplashActionsList() |
||
379 | |||
380 | /** |
||
381 | * Generates the URLNodes from the list of URLS. |
||
382 | * URLNodes are a very efficient way to know whether we can access our page or not. |
||
383 | * |
||
384 | * @param array<SplashAction> $urlsList |
||
385 | * |
||
386 | * @return SplashUrlNode |
||
387 | */ |
||
388 | private function generateUrlNode($urlsList) |
||
397 | |||
398 | /** |
||
399 | * Purges the urls cache. |
||
400 | */ |
||
401 | public function purgeUrlsCache() |
||
405 | |||
406 | /** |
||
407 | * Process an incoming server request and return a response, optionally delegating |
||
408 | * to the next middleware component to create the response. |
||
409 | * |
||
410 | * @param ServerRequestInterface $request |
||
411 | * @param DelegateInterface $delegate |
||
412 | * |
||
413 | * @return ResponseInterface |
||
414 | */ |
||
415 | public function process(ServerRequestInterface $request, DelegateInterface $delegate) |
||
424 | } |
||
425 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..