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

Session\Storage: always preserve _REQUEST_ACCESS_TIME #2766

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions library/Zend/Session/Storage/ArrayStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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;
}

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

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Session/Storage/SessionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __destruct()
*/
public function fromArray(array $array)
{
$this->exchangeArray($array);
parent::fromArray($array);
if ($_SESSION !== $this) {
$_SESSION = $this;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/Session/SessionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/ZendTest/Session/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}