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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasweidner committed Aug 26, 2011
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
31 changes: 13 additions & 18 deletions src/SessionManager.php
Expand Up @@ -84,14 +84,16 @@ public function sessionExists()
/**
* Start session
*
* if No sesion currently exists, attempt to start it. Calls
* {@link isValid()} once session_start() is called, and raises an
* if No sesion currently exists, attempt to start it. Calls
* {@link isValid()} once session_start() is called, and raises an
* exception if validation fails.
*
*
* @param bool $preserveStorage If set to true, current session storage will not be overwritten by the
* contents of $_SESSION.
* @return void
* @throws Exception
*/
public function start()
public function start($preserveStorage = false)
{
if ($this->sessionExists()) {
return;
Expand All @@ -107,7 +109,9 @@ public function start()
if ($storage instanceof Storage\SessionStorage
&& $_SESSION !== $storage
) {
$storage->fromArray($_SESSION);
if (!$preserveStorage){
$storage->fromArray($_SESSION);
}
$_SESSION = $storage;
}
}
Expand Down Expand Up @@ -257,9 +261,7 @@ public function regenerateId()
session_regenerate_id();
return $this;
}
$this->destroy();
session_regenerate_id();
$this->start();
return $this;
}

Expand Down Expand Up @@ -384,19 +386,12 @@ protected function _setSessionCookieLifetime($ttl)
return;
}

if ($this->sessionExists()) {
$this->destroy(array('send_expire_cookie' => false));

// Since a cookie was destroyed, we should regenerate the ID
$this->regenerateId();
}

// Now simply set the cookie TTL
// Set new cookie TTL
$config->setCookieLifetime($ttl);

if (!$this->sessionExists()) {
// Restart session if necessary
$this->start();
if ($this->sessionExists()) {
// There is a running session so we'll regenerate id to send a new cookie
$this->regenerateId();
}
}
}
4 changes: 2 additions & 2 deletions src/ValidatorChain.php
Expand Up @@ -55,7 +55,7 @@ public function __construct(Storage $storage)
$validators = $storage->getMetadata('_VALID');
if ($validators) {
foreach ($validators as $validator => $data) {
$this->connect('session.validate', new $validator($data), 'isValid');
$this->attach('session.validate', new $validator($data), 'isValid');
}
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ public function attach($event, $callback, $priority = 1)
$this->getStorage()->setMetadata('_VALID', array($name => $data));
}

$handle = parent::connect($event, $callback, $priority);
$handle = parent::attach($event, $callback, $priority);
return $handle;
}

Expand Down
2 changes: 1 addition & 1 deletion test/SessionManagerTest.php
Expand Up @@ -622,7 +622,7 @@ public function testForgetMeShouldSendCookieWithZeroTimestamp()
public function testStartingSessionThatFailsAValidatorShouldRaiseException()
{
$chain = $this->manager->getValidatorChain();
$chain->connect('session.validate', function() {
$chain->attach('session.validate', function() {
return false;
});
$this->setExpectedException('Zend\Session\Exception\InvalidArgumentException', 'xxx');
Expand Down

0 comments on commit 90b7795

Please sign in to comment.