2424 */
2525final class EventListener
2626{
27- /** @var ContainerInterface */
28- private $ container ;
29-
3027 /**
3128 * Maps (master and sub) requests to their corresponding last modified date. This date is determined by the
3229 * ReplaceWithNotModifiedResponse annotation of the corresponding controller's action.
33- *
34- * @var SplObjectStorage
3530 */
36- private $ lastModified ;
31+ private SplObjectStorage $ lastModified ;
3732
38- /**
39- * @var bool Symfony kernel.debug mode
40- */
41- private $ debug ;
42-
43- public function __construct (ContainerInterface $ container , bool $ debug = false )
44- {
45- $ this ->container = $ container ;
33+ public function __construct (
34+ private readonly ContainerInterface $ container ,
35+ // Symfony kernel.debug mode
36+ private readonly bool $ debug = false ,
37+ ) {
4638 $ this ->lastModified = new SplObjectStorage ();
47- $ this ->debug = $ debug ;
4839 }
4940
5041 /**
@@ -53,7 +44,7 @@ public function __construct(ContainerInterface $container, bool $debug = false)
5344 * header in the request, replace the determined controller action with a minimal action that just returns an
5445 * "empty" response with a 304 Not Modified HTTP status code.
5546 */
56- public function onKernelController (ControllerEvent $ event )
47+ public function onKernelController (ControllerEvent $ event ): void
5748 {
5849 $ annotation = $ this ->findAnnotation ($ event ->getController ());
5950 if (!$ annotation ) {
@@ -89,7 +80,7 @@ public function onKernelController(ControllerEvent $event)
8980 * If a last modified date was determined for the current (master or sub) request, set it to the response so the
9081 * client can use it for the "If-Modified-Since" header in subsequent requests.
9182 */
92- public function onKernelResponse (ResponseEvent $ event )
83+ public function onKernelResponse (ResponseEvent $ event ): void
9384 {
9485 $ request = $ event ->getRequest ();
9586 $ response = $ event ->getResponse ();
@@ -101,10 +92,8 @@ public function onKernelResponse(ResponseEvent $event)
10192
10293 /**
10394 * @param $controllerCallable callable PHP callback pointing to the method to reflect on.
104- *
105- * @return ?ReplaceWithNotModifiedResponse The annotation, if found. Null otherwise.
10695 */
107- private function findAnnotation (callable $ controllerCallable )
96+ private function findAnnotation (callable $ controllerCallable ): ? ReplaceWithNotModifiedResponse
10897 {
10998 if (!is_array ($ controllerCallable )) {
11099 return null ;
0 commit comments