Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Update classes with dependencies on EventManager
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Feb 1, 2011
1 parent e22a167 commit bb8b8f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
namespace Zend\Session;

use Zend\EventManager\EventDispatcher;
use Zend\EventManager\EventCollection;

/**
* Session manager interface
Expand Down Expand Up @@ -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();
}
20 changes: 11 additions & 9 deletions src/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

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

/**
Expand Down
16 changes: 7 additions & 9 deletions src/ValidatorChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions test/TestAsset/TestManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -53,7 +53,7 @@ public function forgetMe()
{}


public function setValidatorChain(EventDispatcher $chain)
public function setValidatorChain(EventCollection $chain)
{}

public function getValidatorChain()
Expand Down

0 comments on commit bb8b8f6

Please sign in to comment.