Skip to content
Browse files

updated all HttpKernel event listeners to implement EventSubscriberIn…

…terface
  • Loading branch information...
1 parent 38fb43c commit beda03ba96b847fb6bcf2d7aed2893c978ec2565 @fabpot fabpot committed Oct 10, 2011
View
2 src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml
@@ -13,7 +13,7 @@
<service id="esi" class="%esi.class%" />
<service id="esi_listener" class="%esi_listener.class%">
- <tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse" />
+ <tag name="kernel.event_subscriber" />
<argument type="service" id="esi" on-invalid="ignore" />
</service>
</services>
View
3 src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml
@@ -24,8 +24,7 @@
</service>
<service id="profiler_listener" class="%profiler_listener.class%">
- <tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse" priority="-100" />
- <tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" />
+ <tag name="kernel.event_subscriber" />
<argument type="service" id="profiler" />
<argument type="service" id="profiler.request_matcher" on-invalid="null" />
<argument>%profiler_listener.only_exceptions%</argument>
View
3 src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml
@@ -84,8 +84,7 @@
</service>
<service id="router_listener" class="%router_listener.class%">
- <tag name="kernel.event_listener" event="kernel.request" method="onEarlyKernelRequest" priority="255" />
- <tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" />
+ <tag name="kernel.event_subscriber" />
<tag name="monolog.logger" channel="request" />
<argument type="service" id="router" />
<argument type="service" id="logger" on-invalid="ignore" />
View
5 src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml
@@ -25,13 +25,12 @@
</service>
<service id="response_listener" class="%response_listener.class%">
- <tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse" />
+ <tag name="kernel.event_subscriber" />
<argument>%kernel.charset%</argument>
</service>
<service id="locale_listener" class="%locale_listener.class%">
- <tag name="kernel.event_listener" event="kernel.request" method="onEarlyKernelRequest" priority="255" />
- <tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="-1" />
+ <tag name="kernel.event_subscriber" />
<argument>%kernel.default_locale%</argument>
<argument type="service" id="router" on-invalid="ignore" />
</service>
View
2 src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
@@ -83,7 +83,7 @@
</service>
<service id="twig.exception_listener" class="%twig.exception_listener.class%">
- <tag name="kernel.event_listener" event="kernel.exception" method="onKernelException" priority="-128" />
+ <tag name="kernel.event_subscriber" />
<tag name="monolog.logger" channel="request" />
<argument>%twig.exception_listener.controller%</argument>
<argument type="service" id="logger" on-invalid="null" />
View
11 src/Symfony/Component/HttpKernel/EventListener/EsiListener.php
@@ -14,14 +14,16 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
+use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\HttpCache\Esi;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* EsiListener adds a Surrogate-Control HTTP header when the Response needs to be parsed for ESI.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
-class EsiListener
+class EsiListener implements EventSubscriberInterface
{
private $i;
private $esi;
@@ -49,4 +51,11 @@ public function onKernelResponse(FilterResponseEvent $event)
$this->esi->addSurrogateControl($event->getResponse());
}
+
+ static public function getSubscribedEvents()
+ {
+ return array(
+ KernelEvents::RESPONSE => 'onKernelResponse',
+ );
+ }
}
View
11 src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php
@@ -14,17 +14,19 @@
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
+use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* ExceptionListener.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
-class ExceptionListener
+class ExceptionListener implements EventSubscriberInterface
{
private $controller;
private $logger;
@@ -101,4 +103,11 @@ public function onKernelException(GetResponseForExceptionEvent $event)
$handling = false;
}
+
+ static public function getSubscribedEvents()
+ {
+ return array(
+ KernelEvents::EXCEPTION => array('onKernelException', -128),
+ );
+ }
}
View
11 src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php
@@ -13,14 +13,16 @@
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
+use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\RouterInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Initializes the locale based on the current request.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
-class LocaleListener
+class LocaleListener implements EventSubscriberInterface
{
private $router;
private $defaultLocale;
@@ -60,4 +62,11 @@ public function onKernelRequest(GetResponseEvent $event)
$this->router->getContext()->setParameter('_locale', $request->getLocale());
}
}
+
+ static public function getSubscribedEvents()
+ {
+ return array(
+ KernelEvents::REQUEST => array(array('onEarlyKernelRequest', 255), array('onKernelRequest', -1)),
+ );
+ }
}
View
12 src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php
@@ -16,15 +16,17 @@
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
+use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* ProfilerListener collects data for the current request by listening to the onKernelResponse event.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
-class ProfilerListener
+class ProfilerListener implements EventSubscriberInterface
{
protected $profiler;
protected $matcher;
@@ -100,4 +102,12 @@ public function onKernelResponse(FilterResponseEvent $event)
}
}
}
+
+ static public function getSubscribedEvents()
+ {
+ return array(
+ KernelEvents::RESPONSE => array('onKernelResponse', -100),
+ KernelEvents::EXCEPTION => 'onKernelException',
+ );
+ }
}
View
11 src/Symfony/Component/HttpKernel/EventListener/ResponseListener.php
@@ -14,13 +14,15 @@
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
+use Symfony\Component\HttpKernel\KernelEvents;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* ResponseListener fixes the Response headers based on the Request.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
-class ResponseListener
+class ResponseListener implements EventSubscriberInterface
{
private $charset;
@@ -65,4 +67,11 @@ public function onKernelResponse(FilterResponseEvent $event)
$response->headers->set('Content-Type', $mimeType);
}
}
+
+ static public function getSubscribedEvents()
+ {
+ return array(
+ KernelEvents::RESPONSE => 'onKernelResponse',
+ );
+ }
}

3 comments on commit beda03b

@Koc
Koc commented on beda03b Dec 22, 2012

@fabpot what benefit of changing to subscribers (except using constants for events naming)? + your comment #2021 (comment)

@fabpot
Symfony member
fabpot commented on beda03b Dec 22, 2012

The big benefit of subscribers is that you don't need to repeat the priority and the method name in the configuration. As all event listeners in Symfony are also used in Silex, that's a big benefit. So, yes, I changed my mind ;)

@Koc
Koc commented on beda03b Dec 22, 2012

Does this subscribers registered in container can be dumped (for debug) later? For example dump all listeners and subscribers for event KernelEvents::RESPONSE

Please sign in to comment.
Something went wrong with that request. Please try again.