@@ -40,7 +40,7 @@ abstract class Controller implements RequestHandlerInterface
4040 *
4141 * @var string
4242 */
43- public $ id = '' ;
43+ public string $ id = '' ;
4444
4545 /**
4646 * The name of the layout to be applied to this controller's views.
@@ -49,28 +49,28 @@ abstract class Controller implements RequestHandlerInterface
4949 * Defaults to null, meaning the actual layout value should inherit that from module's layout value.
5050 * If false, no layout will be applied.
5151 *
52- * @var null| string|false
52+ * @var string|false
5353 */
54- public $ layout ;
54+ public string | false $ layout = false ;
5555
5656 /**
5757 * The root directory that contains view files for this controller.
5858 *
5959 * @var string
6060 */
61- public $ viewPath ;
61+ public string $ viewPath ;
6262
6363 /**
6464 * The module that this controller belongs to.
6565 *
6666 * @var Module
6767 */
68- public $ module ;
68+ public Module $ module ;
6969
7070 /**
71- * @var ViewInterface
71+ * @var ViewInterface|null
7272 */
73- protected $ view ;
73+ protected ? ViewInterface $ view = null ;
7474
7575 /**
7676 * The dependency injection container, injected by Module::createController().
@@ -90,13 +90,13 @@ abstract class Controller implements RequestHandlerInterface
9090 *
9191 * @var ServerRequestInterface
9292 */
93- protected $ request ;
93+ protected ServerRequestInterface $ request ;
9494
9595 /**
9696 *
9797 * @var ResponseInterface
9898 */
99- protected $ response ;
99+ protected ResponseInterface $ response ;
100100
101101 public function handle (ServerRequestInterface $ request ): ResponseInterface
102102 {
@@ -140,15 +140,12 @@ private function runAction(string $id, array $params = []): ResponseInterface
140140
141141 $ view = $ this ->getView ();
142142
143- if ($ view instanceof View) {
143+ if ($ view instanceof View && $ this -> layout !== false ) {
144144 $ app = $ this ->module ->getApplication ();
145-
146- if ($ this ->layout !== false ) {
147- $ layout = $ this ->layout === null ? $ app ->defaultLayout : $ this ->layout ;
148- $ path = $ this ->module ->layoutPath ?? $ app ->defaultLayoutPath ;
149- $ view ->paths [] = $ path ;
150- $ response = $ view ->render ($ layout , ['content ' => $ response ]);
151- }
145+ $ layout = $ this ->layout == false ? $ app ->defaultLayout : $ this ->layout ;
146+ $ path = $ this ->module ->layoutPath ?? $ app ->defaultLayoutPath ;
147+ $ view ->paths [] = $ path ;
148+ $ response = $ view ->render ($ layout , ['content ' => $ response ]);
152149 }
153150
154151 $ response = $ this ->response ->withBody ((new StreamFactory ())->createStream ($ response ));
@@ -172,7 +169,7 @@ private function getMethodArguments(string $methodName, array $data = []): array
172169 $ actionParams = [];
173170
174171 foreach ($ method ->getParameters () as $ param ) {
175- /* @var $param \ReflectionParameter */
172+ /** @var \ReflectionParameter $param */
176173 $ name = (string ) $ param ->getName ();
177174
178175 if (isset ($ data [$ name ])) {
@@ -265,8 +262,10 @@ protected function getView(): ?ViewInterface
265262
266263 try {
267264 $ view = $ container ->get (View::class);
268- assert ($ view instanceof View);
269- $ view ->attachBehavior ('getUrl ' , [$ this , 'getUrl ' ]);
265+
266+ if ($ view instanceof View) {
267+ $ view ->attachBehavior ('getUrl ' , [$ this , 'getUrl ' ]);
268+ }
270269 } catch (NotFoundExceptionInterface $ e ) {
271270 try {
272271 $ view = $ container ->get (ViewInterface::class);
@@ -275,8 +274,9 @@ protected function getView(): ?ViewInterface
275274 }
276275 }
277276
278- assert ($ view instanceof ViewInterface);
279- $ this ->view = $ view ;
277+ if ($ view instanceof ViewInterface) {
278+ $ this ->view = $ view ;
279+ }
280280 }
281281
282282 return $ this ->view ;
0 commit comments