Permalink
Browse files

Merge branch 'hotfix/3639'

Close #3639
  • Loading branch information...
2 parents 13e8c89 + 2d33cb7 commit 585a1ebea8fc49350ea3d4a4891b6f168ec71041 @weierophinney weierophinney committed Feb 5, 2013
@@ -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();
@@ -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']);
}
@@ -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']);
}
@@ -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);
}
@@ -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));
+ }
+
}
@@ -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);
+ }
+
}
@@ -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));
+ }
}

0 comments on commit 585a1eb

Please sign in to comment.