diff --git a/EventListener/TimezoneListener.php b/EventListener/TimezoneListener.php index c31868c..1b7e962 100644 --- a/EventListener/TimezoneListener.php +++ b/EventListener/TimezoneListener.php @@ -13,6 +13,7 @@ use Lunetics\TimezoneBundle\TimezoneProvider\TimezoneProvider; use Psr\Log\NullLogger; use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Session\Session; @@ -41,6 +42,7 @@ class TimezoneListener implements EventSubscriberInterface protected $logger; protected $timezone; protected $sessionTimezoneString; + protected $dispatcher; /** * Construct the TimezoneListener @@ -52,7 +54,7 @@ class TimezoneListener implements EventSubscriberInterface * @param ValidatorInterace $validator Timzone Validator * @param LoggerInterface $logger Logger */ - public function __construct(Session $session, $sessionVar, $defaultTimezone = 'UTC', TimezoneGuesserManager $manager, $validator, TimezoneProvider $provider, LoggerInterface $logger = null) + public function __construct(Session $session, $sessionVar, $defaultTimezone = 'UTC', TimezoneGuesserManager $manager, $validator, TimezoneProvider $provider, LoggerInterface $logger = null, EventDispatcherInterface $dispatcher) { if (!$validator instanceof ValidatorInterface && !$validator instanceof LegacyValidatorInterface) { throw new \InvalidArgumentException('MetadataValidator accepts either the new or the old ValidatorInterface, '.get_class($validator).' was injected instead.'); @@ -64,6 +66,7 @@ public function __construct(Session $session, $sessionVar, $defaultTimezone = 'U $this->logger = $logger ? : new NullLogger(); $this->sessionTimezoneString = $sessionVar; $this->defaultTimezone = $defaultTimezone; + $this->dispatcher = $dispatcher; } /** @@ -72,6 +75,7 @@ public function __construct(Session $session, $sessionVar, $defaultTimezone = 'U * Call the TimezoneGuesserManager to guess the Timezone by the activated guessers * * @param GetResponseEvent $event + * @param EventDispatcherInterface $dispatcher */ public function onKernelRequest(GetResponseEvent $event) { @@ -102,10 +106,10 @@ public function onKernelRequest(GetResponseEvent $event) } else { $this->timezone = $this->session->get($this->sessionTimezoneString); - $event->getDispatcher()->removeListener(TimezoneBundleEvents::TIMEZONE_CHANGE, array($this,'setSessionAttribute')); + $this->dispatcher->removeListener(TimezoneBundleEvents::TIMEZONE_CHANGE, array($this,'setSessionAttribute')); } $localeSwitchEvent = new FilterTimezoneEvent($this->timezone); - $event->getDispatcher()->dispatch(TimezoneBundleEvents::TIMEZONE_CHANGE, $localeSwitchEvent); + $this->dispatcher->dispatch(TimezoneBundleEvents::TIMEZONE_CHANGE, $localeSwitchEvent); } /** diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 33c3f00..5aba3c5 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -46,6 +46,7 @@ +