2626 * Class to dispatch the request to the middleware dispatcher
2727 */
2828class Dispatcher {
29- /** @var MiddlewareDispatcher */
30- private $ middlewareDispatcher ;
31-
32- /** @var Http */
33- private $ protocol ;
34-
35- /** @var ControllerMethodReflector */
36- private $ reflector ;
37-
38- /** @var IRequest */
39- private $ request ;
40-
41- /** @var IConfig */
42- private $ config ;
43-
44- /** @var ConnectionAdapter */
45- private $ connection ;
46-
47- /** @var LoggerInterface */
48- private $ logger ;
49-
50- /** @var IEventLogger */
51- private $ eventLogger ;
52-
53- private ContainerInterface $ appContainer ;
54-
5529 /**
5630 * @param Http $protocol the http protocol with contains all status headers
5731 * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which
5832 * runs the middleware
59- * @param ControllerMethodReflector $reflector the reflector that is used to inject
60- * the arguments for the controller
61- * @param IRequest $request the incoming request
62- * @param IConfig $config
63- * @param ConnectionAdapter $connection
64- * @param LoggerInterface $logger
65- * @param IEventLogger $eventLogger
6633 */
6734 public function __construct (
68- Http $ protocol ,
69- MiddlewareDispatcher $ middlewareDispatcher ,
70- ControllerMethodReflector $ reflector ,
71- IRequest $ request ,
72- IConfig $ config ,
73- ConnectionAdapter $ connection ,
74- LoggerInterface $ logger ,
75- IEventLogger $ eventLogger ,
76- ContainerInterface $ appContainer ,
35+ private readonly Http $ protocol ,
36+ private readonly MiddlewareDispatcher $ middlewareDispatcher ,
37+ private readonly ControllerMethodReflector $ reflector ,
38+ private readonly IRequest $ request ,
39+ private readonly IConfig $ config ,
40+ private readonly ConnectionAdapter $ connection ,
41+ private readonly LoggerInterface $ logger ,
42+ private readonly IEventLogger $ eventLogger ,
43+ private readonly ContainerInterface $ appContainer ,
7744 ) {
78- $ this ->protocol = $ protocol ;
79- $ this ->middlewareDispatcher = $ middlewareDispatcher ;
80- $ this ->reflector = $ reflector ;
81- $ this ->request = $ request ;
82- $ this ->config = $ config ;
83- $ this ->connection = $ connection ;
84- $ this ->logger = $ logger ;
85- $ this ->eventLogger = $ eventLogger ;
86- $ this ->appContainer = $ appContainer ;
8745 }
8846
8947
@@ -92,16 +50,15 @@ public function __construct(
9250 * @param Controller $controller the controller which will be called
9351 * @param string $methodName the method name which will be called on
9452 * the controller
95- * @return array $array[0] contains the http status header as a string,
96- * $array[1] contains response headers as an array,
97- * $array[2] contains response cookies as an array,
98- * $array[3] contains the response output as a string,
99- * $array[4] contains the response object
53+ * @return array{0: string, 1: array, 2: array, 3: string, 4: Response}
54+ * $array[0] contains the http status header as a string,
55+ * $array[1] contains response headers as an array,
56+ * $array[2] contains response cookies as an array,
57+ * $array[3] contains the response output as a string,
58+ * $array[4] contains the response object
10059 * @throws \Exception
10160 */
10261 public function dispatch (Controller $ controller , string $ methodName ): array {
103- $ out = [null , [], null ];
104-
10562 try {
10663 // prefill reflector with everything that's needed for the
10764 // middlewares
@@ -156,15 +113,15 @@ public function dispatch(Controller $controller, string $methodName): array {
156113 $ controller , $ methodName , $ response );
157114
158115 // depending on the cache object the headers need to be changed
159- $ out [ 0 ] = $ this -> protocol -> getStatusHeader ( $ response -> getStatus ());
160- $ out [ 1 ] = array_merge ($ response ->getHeaders ());
161- $ out [ 2 ] = $ response ->getCookies ();
162- $ out [ 3 ] = $ this -> middlewareDispatcher -> beforeOutput (
163- $ controller , $ methodName , $ response -> render ()
164- );
165- $ out [ 4 ] = $ response ;
166-
167- return $ out ;
116+ return [
117+ $ this -> protocol -> getStatusHeader ($ response ->getStatus ()),
118+ array_merge ( $ response ->getHeaders ()),
119+ $ response -> getCookies (),
120+ $ this -> middlewareDispatcher -> beforeOutput (
121+ $ controller , $ methodName , $ response -> render ()
122+ ),
123+ $ response ,
124+ ] ;
168125 }
169126
170127
0 commit comments