diff --git a/src/Manager.php b/src/Manager.php index e65e39d7..12a63e2c 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -23,7 +23,7 @@ */ namespace Zend\Session; -use Zend\EventManager\EventDispatcher; +use Zend\EventManager\EventCollection; /** * Session manager interface @@ -55,7 +55,7 @@ public function rememberMe($ttl = null); public function forgetMe(); public function expireSessionCookie(); - public function setValidatorChain(EventDispatcher $chain); + public function setValidatorChain(EventCollection $chain); public function getValidatorChain(); public function isValid(); } diff --git a/src/SessionManager.php b/src/SessionManager.php index f1b61986..7a9263f6 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -24,7 +24,7 @@ namespace Zend\Session; use Zend\Validator\Alnum as AlnumValidator, - Zend\EventManager\EventDispatcher; + Zend\EventManager\EventCollection; /** * Session Manager implementation utilizing ext/session @@ -63,7 +63,7 @@ class SessionManager extends AbstractManager protected $_name; /** - * @var EventDispatcher Validation chain to determine if session is valid + * @var EventCollection Validation chain to determine if session is valid */ protected $_validatorChain; @@ -298,10 +298,10 @@ public function forgetMe() * * In most cases, you should use an instance of {@link ValidatorChain}. * - * @param EventDispatcher $chain + * @param EventCollection $chain * @return SessionManager */ - public function setValidatorChain(EventDispatcher $chain) + public function setValidatorChain(EventCollection $chain) { $this->_validatorChain = $chain; return $this; @@ -333,13 +333,15 @@ public function getValidatorChain() public function isValid() { $validator = $this->getValidatorChain(); - $responses = $validator->emitUntil(function($test) { + $responses = $validator->triggerUntil('session.validate', $this, array($this), function($test) { return !$test; - }, 'session.validate', $this); - if (null === $responses->last()) { - return true; + }); + if ($responses->stopped()) { + // If execution was halted, validation failed + return false; } - return (bool) $responses->last(); + // Otherwise, we're good to go + return true; } /** diff --git a/src/ValidatorChain.php b/src/ValidatorChain.php index 274996c6..36348184 100644 --- a/src/ValidatorChain.php +++ b/src/ValidatorChain.php @@ -63,17 +63,15 @@ public function __construct(Storage $storage) /** * Attach a handler to the session validator chain * - * @param string|\Zend\EventManager\HandlerAggregate $eventOrAggregate - * @param string|object|Closure $context - * @param null|string $handler - * @return Zend\Stdlib\SignalHandler + * @param string $event + * @param callback $context + * @param int $priority + * @return Zend\Stdlib\CallbackHandler */ - public function connect($eventOrAggregate, $callback = null, $priority = 1000) + public function attach($event, $callback, $priority = 1) { $context = null; - if (null === $callback) { - $context = $eventOrAggregate; - } elseif ($callback instanceof Validator) { + if ($callback instanceof Validator) { $context = $callback; } elseif (is_array($callback)) { $test = array_shift($callback); @@ -88,7 +86,7 @@ public function connect($eventOrAggregate, $callback = null, $priority = 1000) $this->getStorage()->setMetadata('_VALID', array($name => $data)); } - $handle = parent::connect($eventOrAggregate, $callback, $priority); + $handle = parent::connect($event, $callback, $priority); return $handle; } diff --git a/test/TestAsset/TestManager.php b/test/TestAsset/TestManager.php index 08477f6a..df17e927 100644 --- a/test/TestAsset/TestManager.php +++ b/test/TestAsset/TestManager.php @@ -4,7 +4,7 @@ use Zend\Session\AbstractManager, Zend\Session\Configuration as SessionConfiguration, Zend\Session\Storage as SessionStorage, - Zend\EventManager\EventDispatcher; + Zend\EventManager\EventCollection; class TestManager extends AbstractManager { @@ -53,7 +53,7 @@ public function forgetMe() {} - public function setValidatorChain(EventDispatcher $chain) + public function setValidatorChain(EventCollection $chain) {} public function getValidatorChain()