diff --git a/src/ZfcUser/Authentication/Adapter/AdapterChain.php b/src/ZfcUser/Authentication/Adapter/AdapterChain.php index a7502386..b15857ed 100644 --- a/src/ZfcUser/Authentication/Adapter/AdapterChain.php +++ b/src/ZfcUser/Authentication/Adapter/AdapterChain.php @@ -5,6 +5,7 @@ use Zend\Authentication\Adapter\AdapterInterface; use Zend\Authentication\Result as AuthenticationResult; use Zend\EventManager\Event; +use Zend\EventManager\EventInterface; use Zend\EventManager\EventManagerAwareTrait; use Zend\Stdlib\RequestInterface as Request; use Zend\Stdlib\ResponseInterface as Response; @@ -51,11 +52,13 @@ public function prepareForAuthentication(Request $request) $e = $this->getEvent(); $e->setRequest($request); - $this->getEventManager()->trigger('authenticate.pre', $e); + $e->setName('authenticate.pre'); + $this->getEventManager()->triggerEvent($e); - $result = $this->getEventManager()->trigger('authenticate', $e, function ($test) { + $e->setName('authenticate'); + $result = $this->getEventManager()->triggerEventUntil(function ($test) { return ($test instanceof Response); - }); + }, $e); if ($result->stopped()) { if ($result->last() instanceof Response) { @@ -71,11 +74,13 @@ public function prepareForAuthentication(Request $request) } if ($e->getIdentity()) { - $this->getEventManager()->trigger('authenticate.success', $e); + $e->setName('authenticate.success'); + $this->getEventManager()->triggerEvent($e); return true; } - $this->getEventManager()->trigger('authenticate.fail', $e); + $e->setName('authenticate.fail'); + $this->getEventManager()->triggerEvent($e); return false; } @@ -109,7 +114,9 @@ public function resetAdapters() public function logoutAdapters() { //Adapters might need to perform additional cleanup after logout - $this->getEventManager()->trigger('logout', $this->getEvent()); + $e = $this->getEvent(); + $e->setName('logout'); + $this->getEventManager()->triggerEvent($e); } /** diff --git a/src/ZfcUser/Authentication/Adapter/AdapterChainServiceFactory.php b/src/ZfcUser/Authentication/Adapter/AdapterChainServiceFactory.php index 06c89e16..a5af75e7 100644 --- a/src/ZfcUser/Authentication/Adapter/AdapterChainServiceFactory.php +++ b/src/ZfcUser/Authentication/Adapter/AdapterChainServiceFactory.php @@ -16,6 +16,7 @@ class AdapterChainServiceFactory implements FactoryInterface public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null) { $chain = new AdapterChain(); + $chain->setEventManager($serviceLocator->get('EventManager')); $options = $this->getOptions($serviceLocator); diff --git a/src/ZfcUser/Authentication/Adapter/ChainableAdapter.php b/src/ZfcUser/Authentication/Adapter/ChainableAdapter.php index 748d7e1d..8f297f0f 100644 --- a/src/ZfcUser/Authentication/Adapter/ChainableAdapter.php +++ b/src/ZfcUser/Authentication/Adapter/ChainableAdapter.php @@ -8,10 +8,10 @@ interface ChainableAdapter { /** - * @param EventInterface $e + * @param AdapterChainEvent $e * @return bool */ - public function authenticate(EventInterface $e); + public function authenticate(AdapterChainEvent $e); /** * @return StorageInterface diff --git a/src/ZfcUser/Authentication/Adapter/Db.php b/src/ZfcUser/Authentication/Adapter/Db.php index 891e3e91..b6187464 100644 --- a/src/ZfcUser/Authentication/Adapter/Db.php +++ b/src/ZfcUser/Authentication/Adapter/Db.php @@ -36,20 +36,19 @@ class Db extends AbstractAdapter /** * Called when user id logged out - * @param EventInterface $e + * @param AdapterChainEvent $e */ - public function logout(EventInterface $e) + public function logout(AdapterChainEvent $e) { $this->getStorage()->clear(); } /** - * @param EventInterface $e + * @param AdapterChainEvent $e * @return bool */ - public function authenticate(EventInterface $e) + public function authenticate(AdapterChainEvent $e) { - $e = $e->getTarget(); if ($this->isSatisfied()) { $storage = $this->getStorage()->read(); $e->setIdentity($storage['identity']) diff --git a/src/ZfcUser/EventManager/EventProvider.php b/src/ZfcUser/EventManager/EventProvider.php index 46ef8599..cc6c277d 100644 --- a/src/ZfcUser/EventManager/EventProvider.php +++ b/src/ZfcUser/EventManager/EventProvider.php @@ -47,7 +47,7 @@ public function setEventManager(EventManagerInterface $events) public function getEventManager() { if (!$this->events instanceof EventManagerInterface) { - $this->setEventManager(new EventManager(new SharedEventManager())); + $this->setEventManager(new EventManager()); } return $this->events; } diff --git a/src/ZfcUser/Form/Base.php b/src/ZfcUser/Form/Base.php index 5972eae0..88d1b2ae 100644 --- a/src/ZfcUser/Form/Base.php +++ b/src/ZfcUser/Form/Base.php @@ -85,8 +85,6 @@ public function __construct($name = null) //$csrf = new Element\Csrf('csrf'); //$csrf->getValidator()->setTimeout($this->getRegistrationOptions()->getUserFormTimeout()); //$this->add($csrf); - - $this->getEventManager()->trigger('init', $this); } public function init() diff --git a/src/ZfcUser/Form/ChangeEmail.php b/src/ZfcUser/Form/ChangeEmail.php index 556432a0..98798a35 100644 --- a/src/ZfcUser/Form/ChangeEmail.php +++ b/src/ZfcUser/Form/ChangeEmail.php @@ -65,8 +65,6 @@ public function __construct($name, AuthenticationOptionsInterface $options) 'type' => 'submit' ), )); - - $this->getEventManager()->trigger('init', $this); } /** diff --git a/src/ZfcUser/Form/ChangePassword.php b/src/ZfcUser/Form/ChangePassword.php index 52dada45..0dabd0bc 100644 --- a/src/ZfcUser/Form/ChangePassword.php +++ b/src/ZfcUser/Form/ChangePassword.php @@ -66,8 +66,6 @@ public function __construct($name, AuthenticationOptionsInterface $options) 'type' => 'submit' ), )); - - $this->getEventManager()->trigger('init', $this); } /** diff --git a/src/ZfcUser/Form/Login.php b/src/ZfcUser/Form/Login.php index 46966778..740c314f 100644 --- a/src/ZfcUser/Form/Login.php +++ b/src/ZfcUser/Form/Login.php @@ -66,8 +66,6 @@ public function __construct($name, AuthenticationOptionsInterface $options) $this->add($submitElement, array( 'priority' => -100, )); - - $this->getEventManager()->trigger('init', $this); } /** diff --git a/src/ZfcUser/Form/LoginFilter.php b/src/ZfcUser/Form/LoginFilter.php index 3f98e3e6..37eae3f2 100644 --- a/src/ZfcUser/Form/LoginFilter.php +++ b/src/ZfcUser/Form/LoginFilter.php @@ -38,7 +38,5 @@ public function __construct(AuthenticationOptionsInterface $options) array('name' => 'StringTrim'), ), )); - - $this->getEventManager()->trigger('init', $this); } } diff --git a/src/ZfcUser/Form/RegisterFilter.php b/src/ZfcUser/Form/RegisterFilter.php index d9fe348d..1e1319bb 100644 --- a/src/ZfcUser/Form/RegisterFilter.php +++ b/src/ZfcUser/Form/RegisterFilter.php @@ -99,8 +99,6 @@ public function __construct($emailValidator, $usernameValidator, RegistrationOpt ), ), )); - - $this->getEventManager()->trigger('init', $this); } public function getEmailValidator()