diff --git a/src/Listener/Factory/RouteListenerFactory.php b/src/Listener/Factory/RouteListenerFactory.php index a5a1472..229212d 100644 --- a/src/Listener/Factory/RouteListenerFactory.php +++ b/src/Listener/Factory/RouteListenerFactory.php @@ -36,10 +36,14 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o $request = $container->get('request'); $translator = $container->get('MvcTranslator'); $authService = null; + $userMapper = null; if($container->has('zfcuser_auth_service')){ $authService = $container->get('zfcuser_auth_service'); } + if($container->has('zfcuser_user_mapper')){ + $userMapper = $container->get('zfcuser_user_mapper'); + } - return new $requestedName($languageOptions, $router, $request, $translator, $authService); + return new $requestedName($languageOptions, $router, $request, $translator, $authService, $userMapper); } } diff --git a/src/Listener/RouteListener.php b/src/Listener/RouteListener.php index 903b169..8fb46a8 100644 --- a/src/Listener/RouteListener.php +++ b/src/Listener/RouteListener.php @@ -30,6 +30,7 @@ use Zend\I18n\Translator\TranslatorInterface; use Zend\Authentication\AuthenticationServiceInterface; use ZF2LanguageRoute\Entity\LocaleUserInterface; +use ZfcUser\Mapper\User as ZfcUserMapper; /** * Injects language into translator and updates user locale @@ -49,15 +50,20 @@ class RouteListener extends AbstractListenerAggregate{ /** @var AuthenticationServiceInterface */ protected $authService; + + /** @var ZfcUserMapper */ + protected $userMapper; + /** @var TranslatorInterface */ protected $translator; - function __construct(LanguageRouteOptions $options, RouteStackInterface $router, RequestInterface $request, TranslatorInterface $translator, AuthenticationServiceInterface $authService = null) { + function __construct(LanguageRouteOptions $options, RouteStackInterface $router, RequestInterface $request, TranslatorInterface $translator, AuthenticationServiceInterface $authService = null, ZfcUserMapper $userMapper = null) { $this->options = $options; $this->router = $router; $this->request = $request; $this->authService = $authService; $this->translator = $translator; + $this->userMapper = $userMapper; } @@ -85,6 +91,10 @@ public function onRoute($e){ if($user instanceof LocaleUserInterface){ $user->setLocale($locale); } + // use the zfc user mapper to update if available + if($this->userMapper){ + $this->userMapper->update($user); + } } } }