Skip to content

Commit

Permalink
Added UserMapper to listener
Browse files Browse the repository at this point in the history
  • Loading branch information
xelax90 committed Nov 7, 2016
1 parent a2321ef commit b47815c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Listener/Factory/RouteListenerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 11 additions & 1 deletion src/Listener/RouteListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}


Expand Down Expand Up @@ -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);
}
}
}
}

0 comments on commit b47815c

Please sign in to comment.