1 | <?php |
||
17 | class CacheSubscriber implements SubscriberInterface |
||
18 | { |
||
19 | /** @var CacheStorage $cache Object used to cache responses */ |
||
20 | protected $storage; |
||
21 | |||
22 | /** |
||
23 | * @param CacheStorage $cache Cache storage |
||
24 | */ |
||
25 | public function __construct(CacheStorage $cache) |
||
29 | |||
30 | /** |
||
31 | * @param HasEmitterInterface $subject |
||
32 | * @param CacheStorage|null $storage |
||
33 | * @return array |
||
34 | */ |
||
35 | public static function attach(HasEmitterInterface $subject, CacheStorage $storage) |
||
43 | |||
44 | /** |
||
45 | * @return array |
||
46 | */ |
||
47 | public function getEvents() |
||
54 | |||
55 | /** |
||
56 | * Checks if a request can be cached, and if so, intercepts with a cached |
||
57 | * response is available. |
||
58 | */ |
||
59 | public function onBefore(BeforeEvent $event) |
||
72 | |||
73 | /** |
||
74 | * Checks if the request and response can be cached, and if so, store it |
||
75 | */ |
||
76 | public function onComplete(CompleteEvent $event) |
||
88 | |||
89 | private function cacheMiss(RequestInterface $request) |
||
93 | |||
94 | private function addResponseHeaders(RequestInterface $request, ResponseInterface $response) |
||
106 | } |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: