Skip to content

Commit 188c0d2

Browse files
committed
Output number of invalidation requests to console
Improve PHPDocs
1 parent cf8524e commit 188c0d2

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

EventListener/InvalidationListener.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Symfony\Component\ExpressionLanguage\SyntaxError;
1313
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1414
use Symfony\Component\HttpFoundation\Request;
15-
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
1615
use Symfony\Component\HttpKernel\KernelEvents;
1716
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
1817
use Symfony\Component\Routing\RouterInterface;
@@ -128,23 +127,35 @@ public function onKernelTerminate(PostResponseEvent $event)
128127
}
129128

130129
/**
131-
* Flush cache manager on console termination and exception
130+
* Flush cache manager when kernel exception occurs
132131
*/
133-
public function onTerminate()
132+
public function onKernelException()
134133
{
135134
$this->cacheManager->flush();
136135
}
137136

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+
138149
/**
139150
* {@inheritdoc}
140151
*/
141152
public static function getSubscribedEvents()
142153
{
143154
return array(
144155
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'
148159
);
149160
}
150161

Tests/EventListener/InvalidationListenerTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,15 @@ public function testInvalidateRoute()
125125
$this->getListener()->onKernelTerminate($event);
126126
}
127127

128-
public function testOnTerminate()
128+
public function testOnConsoleTerminate()
129129
{
130-
$this->cacheManager->shouldReceive('flush')->once();
130+
$this->cacheManager->shouldReceive('flush')->once()->andReturn(2);
131131

132-
$this->getListener()->onTerminate();
132+
$event = \Mockery::mock('\Symfony\Component\Console\Event\ConsoleEvent');
133+
$event->shouldReceive('getInput->getOption')->with('verbose')->andReturn(true);
134+
$event->shouldReceive('getOutput->writeln')->with('Sent 2 invalidation requests')->once();
135+
136+
$this->getListener()->onConsoleTerminate($event);
133137
}
134138

135139
protected function getEvent(Request $request, Response $response = null)

0 commit comments

Comments
 (0)