Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'hotfix/3639' into develop

Forward port #3639
  • Loading branch information...
commit 8bd15eb842b5214b6d4278323bb27b7dfa83407b 2 parents fc0c82e + 29510cf
@weierophinney weierophinney authored
View
5 library/Zend/Session/SessionManager.php
@@ -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();
View
5 library/Zend/Session/Storage/ArrayStorage.php
@@ -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']);
}
View
15 library/Zend/Session/Storage/SessionArrayStorage.php
@@ -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']);
}
View
2  library/Zend/Session/Storage/StorageInterface.php
@@ -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);
}
View
16 tests/ZendTest/Session/SessionArrayStorageTest.php
@@ -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));
+ }
+
}
View
14 tests/ZendTest/Session/SessionManagerTest.php
@@ -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);
+ }
+
}
View
16 tests/ZendTest/Session/StorageTest.php
@@ -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));
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.