From 51c4ced3f502ebc5ade458b2dd5b3342716d0bfd Mon Sep 17 00:00:00 2001 From: Thinkscape Date: Mon, 22 Aug 2011 12:29:50 +0200 Subject: [PATCH 1/3] Last commit should go to a branch. This reverts commit b98b8151d39d71db5d6b591df76acbabbc237579. --- src/SessionManager.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index f6b3bfab..28f58c80 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -84,16 +84,14 @@ 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($preserveStorage = false) + public function start() { if ($this->sessionExists()) { return; @@ -109,9 +107,7 @@ public function start($preserveStorage = false) if ($storage instanceof Storage\SessionStorage && $_SESSION !== $storage ) { - if(!$preserveStorage){ - $storage->fromArray($_SESSION); - } + $storage->fromArray($_SESSION); $_SESSION = $storage; } } @@ -261,7 +257,9 @@ public function regenerateId() session_regenerate_id(); return $this; } + $this->destroy(); session_regenerate_id(); + $this->start(); return $this; } @@ -386,12 +384,19 @@ protected function _setSessionCookieLifetime($ttl) return; } - // Set new cookie TTL - $config->setCookieLifetime($ttl); - if ($this->sessionExists()) { - // There is a running session so we'll regenerate id to send a new cookie + $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 + $config->setCookieLifetime($ttl); + + if (!$this->sessionExists()) { + // Restart session if necessary + $this->start(); + } } } From b11b34eca58efe7ea11b020ca161fa6242c3a4c8 Mon Sep 17 00:00:00 2001 From: Thinkscape Date: Mon, 22 Aug 2011 12:33:35 +0200 Subject: [PATCH 2/3] ZF2-52: ::regenerateId() fails and ::rememberMe() clears session storage (http://framework.zend.com/issues/browse/ZF2-52) --- src/SessionManager.php | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index 28f58c80..f6b3bfab 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -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; @@ -107,7 +109,9 @@ public function start() if ($storage instanceof Storage\SessionStorage && $_SESSION !== $storage ) { - $storage->fromArray($_SESSION); + if(!$preserveStorage){ + $storage->fromArray($_SESSION); + } $_SESSION = $storage; } } @@ -257,9 +261,7 @@ public function regenerateId() session_regenerate_id(); return $this; } - $this->destroy(); session_regenerate_id(); - $this->start(); return $this; } @@ -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(); } } } From beadb3c28eecfe8bf29bbfb5e787d8c5d345e6c5 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 25 Aug 2011 13:16:56 -0500 Subject: [PATCH 3/3] ZF2-52: CS fixing, as well as API cleanup - s/connect/attach/ in ValidatorChain and tests - whitespace CS fixes --- src/SessionManager.php | 2 +- src/ValidatorChain.php | 4 ++-- test/SessionManagerTest.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SessionManager.php b/src/SessionManager.php index f6b3bfab..4bcd325e 100644 --- a/src/SessionManager.php +++ b/src/SessionManager.php @@ -109,7 +109,7 @@ public function start($preserveStorage = false) if ($storage instanceof Storage\SessionStorage && $_SESSION !== $storage ) { - if(!$preserveStorage){ + if (!$preserveStorage){ $storage->fromArray($_SESSION); } $_SESSION = $storage; diff --git a/src/ValidatorChain.php b/src/ValidatorChain.php index 8539d9f5..d04f632b 100644 --- a/src/ValidatorChain.php +++ b/src/ValidatorChain.php @@ -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'); } } } @@ -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; } diff --git a/test/SessionManagerTest.php b/test/SessionManagerTest.php index b1fb3a67..92f025e3 100644 --- a/test/SessionManagerTest.php +++ b/test/SessionManagerTest.php @@ -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');