1 | <?php |
||
35 | class InvalidationListener extends AbstractRuleListener implements EventSubscriberInterface |
||
36 | { |
||
37 | /** |
||
38 | * Cache manager. |
||
39 | * |
||
40 | * @var CacheManager |
||
41 | */ |
||
42 | private $cacheManager; |
||
43 | |||
44 | /** |
||
45 | * Router. |
||
46 | * |
||
47 | * @var UrlGeneratorInterface |
||
48 | */ |
||
49 | private $urlGenerator; |
||
50 | |||
51 | /** |
||
52 | * Router. |
||
53 | * |
||
54 | * @var ExpressionLanguage|null |
||
55 | */ |
||
56 | private $expressionLanguage; |
||
57 | |||
58 | /** |
||
59 | * Constructor. |
||
60 | * |
||
61 | * @param CacheManager $cacheManager |
||
62 | * @param UrlGeneratorInterface $urlGenerator |
||
63 | * @param ExpressionLanguage|null $expressionLanguage |
||
64 | */ |
||
65 | 29 | public function __construct( |
|
74 | |||
75 | /** |
||
76 | * Apply invalidators and flush cache manager. |
||
77 | * |
||
78 | * On kernel.terminate: |
||
79 | * - see if any invalidators apply to the current request and, if so, add |
||
80 | * their routes to the cache manager; |
||
81 | * - flush the cache manager in order to send invalidation requests to the |
||
82 | * HTTP cache. |
||
83 | * |
||
84 | * @param PostResponseEvent $event |
||
85 | */ |
||
86 | 19 | public function onKernelTerminate(PostResponseEvent $event) |
|
105 | |||
106 | /** |
||
107 | * Flush cache manager when kernel exception occurs. |
||
108 | */ |
||
109 | 2 | public function onKernelException() |
|
118 | |||
119 | /** |
||
120 | * Flush cache manager when console terminates or errors. |
||
121 | * |
||
122 | * @throws ExceptionCollection If an exception occurs during flush |
||
123 | */ |
||
124 | 9 | public function onConsoleTerminate(ConsoleEvent $event) |
|
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | 23 | public static function getSubscribedEvents() |
|
145 | |||
146 | /** |
||
147 | * Handle the invalidation annotations and configured invalidators. |
||
148 | * |
||
149 | * @param Request $request |
||
150 | * @param Response $response |
||
151 | */ |
||
152 | 15 | private function handleInvalidation(Request $request, Response $response) |
|
183 | |||
184 | /** |
||
185 | * Invalidate paths from annotations. |
||
186 | * |
||
187 | * @param array|InvalidatePath[] $pathConfigurations |
||
188 | */ |
||
189 | 4 | private function invalidatePaths(array $pathConfigurations) |
|
197 | |||
198 | /** |
||
199 | * Invalidate routes from annotations. |
||
200 | * |
||
201 | * @param array|InvalidateRoute[] $routes |
||
202 | * @param Request $request |
||
203 | */ |
||
204 | 2 | private function invalidateRoutes(array $routes, Request $request) |
|
227 | |||
228 | /** |
||
229 | * Delay instantiating the expression language instance until we need it, |
||
230 | * to support a setup with only symfony 2.3. |
||
231 | * |
||
232 | * @return ExpressionLanguage |
||
233 | */ |
||
234 | 2 | private function getExpressionLanguage() |
|
242 | } |
||
243 |