Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Session\Storage: always preserve _REQUEST_ACCESS_TIME #2766

Closed
wants to merge 2 commits into from

2 participants

@Slamdunk

SessionManager::start() is called by default with $preserveStorage = false (and that' ok), but doing so the special metadata _REQUEST_ACCESS_TIME is lost due to https://github.com/zendframework/zf2/blob/master/library/Zend/Session/SessionManager.php#L95-97 always-called overwriting method.

This is a bug that deny the Session\Container::expireByHops() functionality.

@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/2766'
Close #2766
83986ba
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/2766' into develop
Forward port #2766
5812a0d
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-session
@weierophinney weierophinney Merge branch 'hotfix/2766' 37eba61
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-session
@weierophinney weierophinney Merge branch 'hotfix/2766' into develop 65cd119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
20 library/Zend/Session/Storage/ArrayStorage.php
@@ -47,13 +47,25 @@ public function __construct(
$iteratorClass = '\\ArrayIterator'
) {
parent::__construct($input, $flags, $iteratorClass);
- $this->setMetadata('_REQUEST_ACCESS_TIME', microtime(true));
+ $this->setRequestAccessTime(microtime(true));
+ }
+
+ /**
+ * Set the request access time
+ *
+ * @param float $time
+ * @return ArrayStorage
+ */
+ protected function setRequestAccessTime($time)
+ {
+ $this->setMetadata('_REQUEST_ACCESS_TIME', $time);
+ return $this;
}
/**
* Retrieve the request access time
*
- * @return int
+ * @return float
*/
public function getRequestAccessTime()
{
@@ -289,7 +301,7 @@ public function clear($key = null)
throw new Exception\RuntimeException('Cannot clear storage as it is marked immutable');
}
if (null === $key) {
- $this->exchangeArray(array());
+ $this->fromArray(array());
return $this;
}
@@ -317,7 +329,9 @@ public function clear($key = null)
*/
public function fromArray(array $array)
{
+ $ts = $this->getRequestAccessTime();
$this->exchangeArray($array);
+ $this->setRequestAccessTime($ts);
return $this;
}
View
2  library/Zend/Session/Storage/SessionStorage.php
@@ -76,7 +76,7 @@ public function __destruct()
*/
public function fromArray(array $array)
{
- $this->exchangeArray($array);
+ parent::fromArray($array);
if ($_SESSION !== $this) {
$_SESSION = $this;
}
View
2  tests/ZendTest/Session/SessionManagerTest.php
@@ -311,7 +311,7 @@ public function testPassingClearStorageOptionWhenCallingDestroyClearsStorage()
$storage = $this->manager->getStorage();
$storage['foo'] = 'bar';
$this->manager->destroy(array('clear_storage' => true));
- $this->assertSame(array(), (array) $storage);
+ $this->assertFalse(isset($storage['foo']));
}
/**
View
7 tests/ZendTest/Session/StorageTest.php
@@ -220,4 +220,11 @@ public function testClearWhenStorageMarkedImmutableRaisesException()
'Cannot clear storage as it is marked immutable');
$this->storage->clear();
}
+
+ public function testRequestAccessTimeIsPreservedEvenInFactoryMethod()
+ {
+ $this->assertNotEmpty($this->storage->getRequestAccessTime());
+ $this->storage->fromArray(array());
+ $this->assertNotEmpty($this->storage->getRequestAccessTime());
+ }
}
Something went wrong with that request. Please try again.