In my bundle, I want to take advantage of the kernel.terminate
event to flush some statistics about webservice api call. Yet, I didn't find any resources to do it in the best way.
On a listener GuzzleExceptionListener
(his role is to intercept every fail webservice call) in which i've injected the EntityManger
service. :
if ($exception instanceof BadResponseException) {
$entityManager = $this->entityManager;
$dispatcher = new EventDispatcher;
$dispatcher->addListener('kernel.terminate', function (Event $event) use ($entityManager) {
$repository = $entityManager->getRepository("somerepository");
// do some treatment for stats
$entityManager->persist($apicall);
$entityManager->flush();
});
}
The declaration of the GuzzleExceptionListener
:
<service id="my_service" class="%my_class%">
<tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" />
<argument type="service" id="doctrine.orm.entity_manager" />
</service>
Anyhow, this closure is not called when the event kernel.terminate
is fired. Why ? Is it because it's inside a listener itself ?