|
12 | 12 | use Symfony\Component\ExpressionLanguage\SyntaxError;
|
13 | 13 | use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
14 | 14 | use Symfony\Component\HttpFoundation\Request;
|
15 |
| -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; |
16 | 15 | use Symfony\Component\HttpKernel\KernelEvents;
|
17 | 16 | use Symfony\Component\HttpKernel\Event\PostResponseEvent;
|
18 | 17 | use Symfony\Component\Routing\RouterInterface;
|
@@ -128,23 +127,35 @@ public function onKernelTerminate(PostResponseEvent $event)
|
128 | 127 | }
|
129 | 128 |
|
130 | 129 | /**
|
131 |
| - * Flush cache manager on console termination and exception |
| 130 | + * Flush cache manager when kernel exception occurs |
132 | 131 | */
|
133 |
| - public function onTerminate() |
| 132 | + public function onKernelException() |
134 | 133 | {
|
135 | 134 | $this->cacheManager->flush();
|
136 | 135 | }
|
137 | 136 |
|
| 137 | + /** |
| 138 | + * Flush cache manager when console terminates or errors |
| 139 | + */ |
| 140 | + public function onConsoleTerminate(ConsoleEvent $event) |
| 141 | + { |
| 142 | + $num = $this->cacheManager->flush(); |
| 143 | + |
| 144 | + if ($num > 0 && $event->getInput()->getOption('verbose')) { |
| 145 | + $event->getOutput()->writeln(sprintf('Sent %d invalidation requests', $num)); |
| 146 | + } |
| 147 | + } |
| 148 | + |
138 | 149 | /**
|
139 | 150 | * {@inheritdoc}
|
140 | 151 | */
|
141 | 152 | public static function getSubscribedEvents()
|
142 | 153 | {
|
143 | 154 | return array(
|
144 | 155 | KernelEvents::TERMINATE => 'onKernelTerminate',
|
145 |
| - KernelEvents::EXCEPTION => 'onTerminate', |
146 |
| - ConsoleEvents::TERMINATE => 'onTerminate', |
147 |
| - ConsoleEvents::EXCEPTION => 'onTerminate' |
| 156 | + KernelEvents::EXCEPTION => 'onKernelException', |
| 157 | + ConsoleEvents::TERMINATE => 'onConsoleTerminate', |
| 158 | + ConsoleEvents::EXCEPTION => 'onConsoleTerminate' |
148 | 159 | );
|
149 | 160 | }
|
150 | 161 |
|
|
0 commit comments