Loading src/UnicaenAuth/Event/Listener/UserRoleSelectedEventAbstractListener.php 0 → 100644 +70 −0 Original line number Diff line number Diff line <?php namespace UnicaenAuth\Event\Listener; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\ListenerAggregateInterface; use UnicaenApp\Service\EntityManagerAwareInterface; use UnicaenApp\Service\EntityManagerAwareTrait; use UnicaenAuth\Event\UserRoleSelectedEvent; /** * Classe abstraites pour les classes désirant scruter un événement déclenché lors de la sélection d'un * rôle utilisateur. * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> * @see UserAuthenticatedEvent */ abstract class UserRoleSelectedEventAbstractListener implements ListenerAggregateInterface, EntityManagerAwareInterface { use EntityManagerAwareTrait; /** * @var \Zend\Stdlib\CallbackHandler[] */ protected $listeners = []; /** * Renseigne les relations 'intervenant' et 'personnel' avant que l'objet soit persisté. * * @param UserRoleSelectedEvent $e * @return */ abstract public function postSelection(UserRoleSelectedEvent $e); /** * Attach one or more listeners * * Implementors may add an optional $priority argument; the EventManager * implementation will pass this to the aggregate. * * @param EventManagerInterface $events * * @return void */ public function attach(EventManagerInterface $events) { $sharedEvents = $events->getSharedManager(); $this->listeners[] = $sharedEvents->attach( 'UnicaenAuth\Service\UserContext', UserRoleSelectedEvent::POST_SELECTION, [$this, 'postSelection'], 100); } /** * Detach all previously attached listeners * * @param EventManagerInterface $events * * @return void */ public function detach(EventManagerInterface $events) { foreach ($this->listeners as $index => $listener) { if ($events->detach($listener)) { unset($this->listeners[$index]); } } } } No newline at end of file src/UnicaenAuth/Event/UserRoleSelectedEvent.php 0 → 100644 +45 −0 Original line number Diff line number Diff line <?php namespace UnicaenAuth\Event; use Zend\EventManager\Event; use Zend\Permissions\Acl\Role\RoleInterface; /** * Classe des événements déclenchés lors l'utilisateur a sélectionné rôle. * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ class UserRoleSelectedEvent extends Event { const POST_SELECTION = 'postSelection'; private $role; /** * @return RoleInterface|string */ public function getRole() { return $this->role; } /** * @param RoleInterface|string $role * @return self */ public function setRole($role) { $this->role = $role; return $this; } /** * @return static */ static public function postSelection() { return new static(static::POST_SELECTION); } } No newline at end of file src/UnicaenAuth/Service/UserContext.php +23 −2 Original line number Diff line number Diff line Loading @@ -5,20 +5,24 @@ namespace UnicaenAuth\Service; use BjyAuthorize\Acl\Role; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Traits\SessionContainerTrait; use UnicaenAuth\Event\UserRoleSelectedEvent; use UnicaenAuth\Provider\Identity\Chain; use Zend\EventManager\EventManagerAwareInterface; use Zend\Session\Container as SessionContainer; use Zend\Permissions\Acl\Role\RoleInterface; use ZfcUser\Entity\UserInterface; use UnicaenAuth\Entity\Ldap\People; use UnicaenAuth\Acl\NamedRole; use Zend\EventManager\EventManagerAwareTrait; /** * Service centralisant des méthodes utiles concernant l'utilisateur authentifié. * * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr> */ class UserContext extends AbstractService class UserContext extends AbstractService implements EventManagerAwareInterface { use EventManagerAwareTrait; use SessionContainerTrait; /** Loading Loading @@ -222,6 +226,8 @@ class UserContext extends AbstractService unset($this->getSessionContainer()->selectedIdentityRole); } $this->triggerUserRoleSelectedEvent(UserRoleSelectedEvent::POST_SELECTION, $role); return $this; } Loading Loading @@ -261,10 +267,25 @@ class UserContext extends AbstractService unset($this->getSessionContainer()->nextSelectedIdentityRole); } $this->triggerUserRoleSelectedEvent(UserRoleSelectedEvent::POST_SELECTION, $role); return $this; } /** * Déclenche l'événement donnant à l'application l'opportunité de réagir à la sélection d'un rôle. * * @param string $name Ex: UserRoleSelectedEvent::POST_SELECTION * @param RoleInterface|string|null $role Rôle sélectionné */ private function triggerUserRoleSelectedEvent($name, $role) { $event = new UserRoleSelectedEvent($name); $event ->setRole($role) ->setTarget($this); $this->getEventManager()->trigger($event); } /** * Teste si le rôle spécifié fait partie des rôles disponibles. Loading Loading
src/UnicaenAuth/Event/Listener/UserRoleSelectedEventAbstractListener.php 0 → 100644 +70 −0 Original line number Diff line number Diff line <?php namespace UnicaenAuth\Event\Listener; use Zend\EventManager\EventManagerInterface; use Zend\EventManager\ListenerAggregateInterface; use UnicaenApp\Service\EntityManagerAwareInterface; use UnicaenApp\Service\EntityManagerAwareTrait; use UnicaenAuth\Event\UserRoleSelectedEvent; /** * Classe abstraites pour les classes désirant scruter un événement déclenché lors de la sélection d'un * rôle utilisateur. * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> * @see UserAuthenticatedEvent */ abstract class UserRoleSelectedEventAbstractListener implements ListenerAggregateInterface, EntityManagerAwareInterface { use EntityManagerAwareTrait; /** * @var \Zend\Stdlib\CallbackHandler[] */ protected $listeners = []; /** * Renseigne les relations 'intervenant' et 'personnel' avant que l'objet soit persisté. * * @param UserRoleSelectedEvent $e * @return */ abstract public function postSelection(UserRoleSelectedEvent $e); /** * Attach one or more listeners * * Implementors may add an optional $priority argument; the EventManager * implementation will pass this to the aggregate. * * @param EventManagerInterface $events * * @return void */ public function attach(EventManagerInterface $events) { $sharedEvents = $events->getSharedManager(); $this->listeners[] = $sharedEvents->attach( 'UnicaenAuth\Service\UserContext', UserRoleSelectedEvent::POST_SELECTION, [$this, 'postSelection'], 100); } /** * Detach all previously attached listeners * * @param EventManagerInterface $events * * @return void */ public function detach(EventManagerInterface $events) { foreach ($this->listeners as $index => $listener) { if ($events->detach($listener)) { unset($this->listeners[$index]); } } } } No newline at end of file
src/UnicaenAuth/Event/UserRoleSelectedEvent.php 0 → 100644 +45 −0 Original line number Diff line number Diff line <?php namespace UnicaenAuth\Event; use Zend\EventManager\Event; use Zend\Permissions\Acl\Role\RoleInterface; /** * Classe des événements déclenchés lors l'utilisateur a sélectionné rôle. * * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> */ class UserRoleSelectedEvent extends Event { const POST_SELECTION = 'postSelection'; private $role; /** * @return RoleInterface|string */ public function getRole() { return $this->role; } /** * @param RoleInterface|string $role * @return self */ public function setRole($role) { $this->role = $role; return $this; } /** * @return static */ static public function postSelection() { return new static(static::POST_SELECTION); } } No newline at end of file
src/UnicaenAuth/Service/UserContext.php +23 −2 Original line number Diff line number Diff line Loading @@ -5,20 +5,24 @@ namespace UnicaenAuth\Service; use BjyAuthorize\Acl\Role; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Traits\SessionContainerTrait; use UnicaenAuth\Event\UserRoleSelectedEvent; use UnicaenAuth\Provider\Identity\Chain; use Zend\EventManager\EventManagerAwareInterface; use Zend\Session\Container as SessionContainer; use Zend\Permissions\Acl\Role\RoleInterface; use ZfcUser\Entity\UserInterface; use UnicaenAuth\Entity\Ldap\People; use UnicaenAuth\Acl\NamedRole; use Zend\EventManager\EventManagerAwareTrait; /** * Service centralisant des méthodes utiles concernant l'utilisateur authentifié. * * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr> */ class UserContext extends AbstractService class UserContext extends AbstractService implements EventManagerAwareInterface { use EventManagerAwareTrait; use SessionContainerTrait; /** Loading Loading @@ -222,6 +226,8 @@ class UserContext extends AbstractService unset($this->getSessionContainer()->selectedIdentityRole); } $this->triggerUserRoleSelectedEvent(UserRoleSelectedEvent::POST_SELECTION, $role); return $this; } Loading Loading @@ -261,10 +267,25 @@ class UserContext extends AbstractService unset($this->getSessionContainer()->nextSelectedIdentityRole); } $this->triggerUserRoleSelectedEvent(UserRoleSelectedEvent::POST_SELECTION, $role); return $this; } /** * Déclenche l'événement donnant à l'application l'opportunité de réagir à la sélection d'un rôle. * * @param string $name Ex: UserRoleSelectedEvent::POST_SELECTION * @param RoleInterface|string|null $role Rôle sélectionné */ private function triggerUserRoleSelectedEvent($name, $role) { $event = new UserRoleSelectedEvent($name); $event ->setRole($role) ->setTarget($this); $this->getEventManager()->trigger($event); } /** * Teste si le rôle spécifié fait partie des rôles disponibles. Loading