Skip to content
This repository
Browse code

Merge branch 'hotfix/3639' into develop

Forward port #3639
  • Loading branch information...
commit f8af9b6cdd7ea2e9d37532263790fd5f42f9432e 2 parents b91f6c3 + 2d33cb7
Matthew Weier O'Phinney weierophinney authored
5 library/Zend/Session/SessionManager.php
@@ -103,7 +103,10 @@ public function start($preserveStorage = false)
103 103 $storage->fromArray($_SESSION);
104 104 }
105 105 $_SESSION = $storage;
  106 + } elseif ($storage instanceof Storage\SessionArrayStorage) {
  107 + $storage->fromArray($_SESSION);
106 108 }
  109 +
107 110 if (!$this->isValid()) {
108 111 throw new Exception\RuntimeException('Session validation failed');
109 112 }
@@ -159,7 +162,7 @@ public function writeClose()
159 162 // object isImmutable.
160 163 $storage = $this->getStorage();
161 164 if (!$storage->isImmutable()) {
162   - $_SESSION = $storage->toArray();
  165 + $_SESSION = $storage->toArray(true);
163 166 session_write_close();
164 167 $storage->fromArray($_SESSION);
165 168 $storage->markImmutable();
5 library/Zend/Session/Storage/ArrayStorage.php
@@ -337,9 +337,12 @@ public function fromArray(array $array)
337 337 *
338 338 * @return array
339 339 */
340   - public function toArray()
  340 + public function toArray($metaData = false)
341 341 {
342 342 $values = $this->getArrayCopy();
  343 + if ($metaData) {
  344 + return $values;
  345 + }
343 346 if (isset($values['__ZF'])) {
344 347 unset($values['__ZF']);
345 348 }
15 library/Zend/Session/Storage/SessionArrayStorage.php
@@ -197,6 +197,9 @@ public function getIterator()
197 197 public function fromArray(array $array)
198 198 {
199 199 $ts = $this->getRequestAccessTime();
  200 + if (!$ts) {
  201 + $ts = microtime(true);
  202 + }
200 203 $_SESSION = $array;
201 204 $this->setRequestAccessTime($ts);
202 205 return $this;
@@ -346,10 +349,7 @@ public function setMetadata($key, $value, $overwriteArray = false)
346 349 }
347 350 } else {
348 351 if ((null === $value) && isset($_SESSION['__ZF'][$key])) {
349   - $array = $_SESSION['__ZF'];
350   - unset($array[$key]);
351   - $_SESSION['__ZF'] = $array;
352   - unset($array);
  352 + unset($_SESSION['__ZF'][$key]);
353 353 } elseif (null !== $value) {
354 354 $_SESSION['__ZF'][$key] = $value;
355 355 }
@@ -444,13 +444,18 @@ protected function setRequestAccessTime($time)
444 444 *
445 445 * @return array
446 446 */
447   - public function toArray()
  447 + public function toArray($metaData = false)
448 448 {
449 449 if (isset($_SESSION)) {
450 450 $values = $_SESSION;
451 451 } else {
452 452 $values = array();
453 453 }
  454 +
  455 + if ($metaData) {
  456 + return $values;
  457 + }
  458 +
454 459 if (isset($values['__ZF'])) {
455 460 unset($values['__ZF']);
456 461 }
2  library/Zend/Session/Storage/StorageInterface.php
@@ -37,5 +37,5 @@ public function getMetadata($key = null);
37 37 public function clear($key = null);
38 38
39 39 public function fromArray(array $array);
40   - public function toArray();
  40 + public function toArray($metaData = false);
41 41 }
16 tests/ZendTest/Session/SessionArrayStorageTest.php
@@ -125,4 +125,20 @@ public function testSessionWorksWithContainer()
125 125
126 126 }
127 127
  128 + public function testToArrayWithMetaData()
  129 + {
  130 + $this->storage->foo = 'bar';
  131 + $this->storage->bar = 'baz';
  132 + $this->storage->setMetadata('foo', 'bar');
  133 + $expected = array(
  134 + '__ZF' => array(
  135 + '_REQUEST_ACCESS_TIME' => $this->storage->getRequestAccessTime(),
  136 + 'foo' => 'bar',
  137 + ),
  138 + 'foo' => 'bar',
  139 + 'bar' => 'baz',
  140 + );
  141 + $this->assertSame($expected, $this->storage->toArray(true));
  142 + }
  143 +
128 144 }
14 tests/ZendTest/Session/SessionManagerTest.php
@@ -525,4 +525,18 @@ public function testResumeSessionThatFailsAValidatorShouldRaiseException()
525 525 $this->setExpectedException('Zend\Session\Exception\RuntimeException', 'failed');
526 526 $this->manager->start();
527 527 }
  528 +
  529 + /**
  530 + * @runInSeparateProcess
  531 + */
  532 + public function testSessionWriteCloseStoresMetadata()
  533 + {
  534 + $this->manager->start();
  535 + $storage = $this->manager->getStorage();
  536 + $storage->setMetadata('foo', 'bar');
  537 + $metaData = $storage->getMetadata();
  538 + $this->manager->writeClose();
  539 + $this->assertSame($_SESSION['__ZF'], $metaData);
  540 + }
  541 +
528 542 }
16 tests/ZendTest/Session/StorageTest.php
@@ -227,4 +227,20 @@ public function testRequestAccessTimeIsPreservedEvenInFactoryMethod()
227 227 $this->storage->fromArray(array());
228 228 $this->assertNotEmpty($this->storage->getRequestAccessTime());
229 229 }
  230 +
  231 + public function testToArrayWithMetaData()
  232 + {
  233 + $this->storage->foo = 'bar';
  234 + $this->storage->bar = 'baz';
  235 + $this->storage->setMetadata('foo', 'bar');
  236 + $expected = array(
  237 + '__ZF' => array(
  238 + '_REQUEST_ACCESS_TIME' => $this->storage->getRequestAccessTime(),
  239 + 'foo' => 'bar',
  240 + ),
  241 + 'foo' => 'bar',
  242 + 'bar' => 'baz',
  243 + );
  244 + $this->assertSame($expected, $this->storage->toArray(true));
  245 + }
230 246 }

0 comments on commit f8af9b6

Please sign in to comment.
Something went wrong with that request. Please try again.