Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Session Metadata and SessionArrayStorage requestaccesstime fixes. #3639

Closed
wants to merge 2 commits into from

3 participants

Mike Willbanks Maks3w Matthew Weier O'Phinney
Mike Willbanks
Collaborator

Overview

2.1 changed slightly in how the session manager retrieved results from the storage; unfortunately this caused the meta data to be blown away. Unfortunately in 2.0.x it was not clear that the type cast was working around the toArray method. Now toArray has a $metaData = false parameter to ensure that we can save the metadata when writing the session.

Additionally the Storage containers were never meant to directly modify $_SESSION; however, to fix issues with storage containers from ArrayObject this was made. Unfortunately when it is initialized it attempts to set the request access time; this has been changed to do it on session start by utilizing the fromArray method.

Mike Willbanks mwillbanks Added default variable to interface for metadata from toArray, fixed …
…issue with SessionArrayStorage to repopulate when session starts fixing request access time
2cfa6b3
library/Zend/Session/SessionManager.php
@@ -103,7 +103,10 @@ public function start($preserveStorage = false)
$storage->fromArray($_SESSION);
}
$_SESSION = $storage;
+ } else if ($storage instanceof Storage\SessionArrayStorage) {
Maks3w Collaborator
Maks3w added a note

According PSR-2 this must be elseif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Matthew Weier O'Phinney weierophinney was assigned
Matthew Weier O'Phinney weierophinney referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3639' into develop
Forward port #3639
f8af9b6
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3639'
Close #3639
879991d
Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney Merge branch 'hotfix/3639' into develop
Forward port #3639
8bd15eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 31, 2013
  1. Mike Willbanks

    Added default variable to interface for metadata from toArray, fixed …

    mwillbanks authored
    …issue with SessionArrayStorage to repopulate when session starts fixing request access time
Commits on Feb 1, 2013
  1. Mike Willbanks
This page is out of date. Refresh to see the latest.
5 library/Zend/Session/SessionManager.php
View
@@ -103,7 +103,10 @@ public function start($preserveStorage = false)
$storage->fromArray($_SESSION);
}
$_SESSION = $storage;
+ } elseif ($storage instanceof Storage\SessionArrayStorage) {
+ $storage->fromArray($_SESSION);
}
+
if (!$this->isValid()) {
throw new Exception\RuntimeException('Session validation failed');
}
@@ -159,7 +162,7 @@ public function writeClose()
// object isImmutable.
$storage = $this->getStorage();
if (!$storage->isImmutable()) {
- $_SESSION = $storage->toArray();
+ $_SESSION = $storage->toArray(true);
session_write_close();
$storage->fromArray($_SESSION);
$storage->markImmutable();
5 library/Zend/Session/Storage/ArrayStorage.php
View
@@ -337,9 +337,12 @@ public function fromArray(array $array)
*
* @return array
*/
- public function toArray()
+ public function toArray($metaData = false)
{
$values = $this->getArrayCopy();
+ if ($metaData) {
+ return $values;
+ }
if (isset($values['__ZF'])) {
unset($values['__ZF']);
}
15 library/Zend/Session/Storage/SessionArrayStorage.php
View
@@ -197,6 +197,9 @@ public function getIterator()
public function fromArray(array $array)
{
$ts = $this->getRequestAccessTime();
+ if (!$ts) {
+ $ts = microtime(true);
+ }
$_SESSION = $array;
$this->setRequestAccessTime($ts);
return $this;
@@ -346,10 +349,7 @@ public function setMetadata($key, $value, $overwriteArray = false)
}
} else {
if ((null === $value) && isset($_SESSION['__ZF'][$key])) {
- $array = $_SESSION['__ZF'];
- unset($array[$key]);
- $_SESSION['__ZF'] = $array;
- unset($array);
+ unset($_SESSION['__ZF'][$key]);
} elseif (null !== $value) {
$_SESSION['__ZF'][$key] = $value;
}
@@ -444,13 +444,18 @@ protected function setRequestAccessTime($time)
*
* @return array
*/
- public function toArray()
+ public function toArray($metaData = false)
{
if (isset($_SESSION)) {
$values = $_SESSION;
} else {
$values = array();
}
+
+ if ($metaData) {
+ return $values;
+ }
+
if (isset($values['__ZF'])) {
unset($values['__ZF']);
}
2  library/Zend/Session/Storage/StorageInterface.php
View
@@ -37,5 +37,5 @@ public function getMetadata($key = null);
public function clear($key = null);
public function fromArray(array $array);
- public function toArray();
+ public function toArray($metaData = false);
}
16 tests/ZendTest/Session/SessionArrayStorageTest.php
View
@@ -125,4 +125,20 @@ public function testSessionWorksWithContainer()
}
+ public function testToArrayWithMetaData()
+ {
+ $this->storage->foo = 'bar';
+ $this->storage->bar = 'baz';
+ $this->storage->setMetadata('foo', 'bar');
+ $expected = array(
+ '__ZF' => array(
+ '_REQUEST_ACCESS_TIME' => $this->storage->getRequestAccessTime(),
+ 'foo' => 'bar',
+ ),
+ 'foo' => 'bar',
+ 'bar' => 'baz',
+ );
+ $this->assertSame($expected, $this->storage->toArray(true));
+ }
+
}
14 tests/ZendTest/Session/SessionManagerTest.php
View
@@ -525,4 +525,18 @@ public function testResumeSessionThatFailsAValidatorShouldRaiseException()
$this->setExpectedException('Zend\Session\Exception\RuntimeException', 'failed');
$this->manager->start();
}
+
+ /**
+ * @runInSeparateProcess
+ */
+ public function testSessionWriteCloseStoresMetadata()
+ {
+ $this->manager->start();
+ $storage = $this->manager->getStorage();
+ $storage->setMetadata('foo', 'bar');
+ $metaData = $storage->getMetadata();
+ $this->manager->writeClose();
+ $this->assertSame($_SESSION['__ZF'], $metaData);
+ }
+
}
16 tests/ZendTest/Session/StorageTest.php
View
@@ -227,4 +227,20 @@ public function testRequestAccessTimeIsPreservedEvenInFactoryMethod()
$this->storage->fromArray(array());
$this->assertNotEmpty($this->storage->getRequestAccessTime());
}
+
+ public function testToArrayWithMetaData()
+ {
+ $this->storage->foo = 'bar';
+ $this->storage->bar = 'baz';
+ $this->storage->setMetadata('foo', 'bar');
+ $expected = array(
+ '__ZF' => array(
+ '_REQUEST_ACCESS_TIME' => $this->storage->getRequestAccessTime(),
+ 'foo' => 'bar',
+ ),
+ 'foo' => 'bar',
+ 'bar' => 'baz',
+ );
+ $this->assertSame($expected, $this->storage->toArray(true));
+ }
}
Something went wrong with that request. Please try again.