Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions EventListener/TimezoneListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,6 +42,7 @@ class TimezoneListener implements EventSubscriberInterface
protected $logger;
protected $timezone;
protected $sessionTimezoneString;
protected $dispatcher;

/**
* Construct the TimezoneListener
Expand All @@ -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.');
Expand All @@ -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;
}

/**
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<argument type="service" id="validator"/>
<argument type="service" id="lunetics_timezone.provider" />
<argument type="service" id="logger" on-invalid="null"/>
<argument type="service" id="event_dispatcher"/>
<tag name="monolog.logger" channel="lunetics_timezone" />
<tag name="kernel.event_subscriber"/>
</service>
Expand Down