1 | <?php |
||
29 | class Dispatcher extends AbstractMiddleware implements MiddlewareInterface |
||
30 | { |
||
31 | |||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $namespace; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $action; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $controller; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $args = []; |
||
51 | |||
52 | /** |
||
53 | * Handles a Request and updated the response |
||
54 | * |
||
55 | * @param ServerRequestInterface $request |
||
56 | * @param ResponseInterface $response |
||
57 | * |
||
58 | * @return ResponseInterface |
||
59 | */ |
||
60 | 10 | public function handle( |
|
84 | |||
85 | |||
86 | 2 | protected function checkView( |
|
87 | ServerRequestInterface $request, |
||
88 | ControllerNotFoundException $caught |
||
89 | ) { |
||
90 | /** @var Route $route */ |
||
91 | 2 | $route = $request->getAttribute('route'); |
|
92 | 2 | $def = $route->attributes; |
|
93 | 2 | $viewName = "{$def['controller']}/{$def['action']}.twig"; |
|
94 | 2 | $paths = Template::getPaths(); |
|
95 | 2 | foreach ($paths as $path) { |
|
96 | 2 | $filename = str_replace('//', '/', "{$path}/{$viewName}"); |
|
97 | 2 | if (is_file($filename)) { |
|
98 | return; |
||
99 | } |
||
100 | 2 | } |
|
101 | 2 | throw $caught; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * Sets the data values into request |
||
106 | * |
||
107 | * @param ControllerInterface $controller |
||
108 | * @param ServerRequestInterface $request |
||
109 | * |
||
110 | * @return ServerRequestInterface|static |
||
111 | */ |
||
112 | 4 | protected function setViewVars( |
|
123 | |||
124 | /** |
||
125 | * Creates the controller with provided class name |
||
126 | * |
||
127 | * @param string $controller |
||
128 | * |
||
129 | * @return ControllerInterface |
||
130 | */ |
||
131 | 10 | protected function createController($controller) |
|
142 | |||
143 | /** |
||
144 | * Check if class exists |
||
145 | * |
||
146 | * @param string $className |
||
147 | * @return $this|self|Dispatcher |
||
148 | */ |
||
149 | 10 | protected function checkClass($className) |
|
158 | |||
159 | /** |
||
160 | * @param Route $route |
||
161 | * |
||
162 | * @return $this|self|Dispatcher |
||
163 | */ |
||
164 | 10 | protected function setAttributes(Route $route) |
|
180 | |||
181 | /** |
||
182 | * Normalize controller/action names |
||
183 | * |
||
184 | * @param string $name |
||
185 | * @return string |
||
186 | */ |
||
187 | 10 | protected function normalize($name) |
|
194 | |||
195 | /** |
||
196 | * Check if action is defined in the controller |
||
197 | * |
||
198 | * @param string $className |
||
199 | * |
||
200 | * @return Dispatcher |
||
201 | */ |
||
202 | 6 | protected function checkAction($className) |
|
212 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.