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));
 }
Exemple #2
0
 /**
  * Load session object from an existing array
  *
  * Ensures $_SESSION is set to an instance of the object when complete.
  *
  * @param  array          $array
  * @return SessionStorage
  */
 public function fromArray(array $array)
 {
     parent::fromArray($array);
     if ($_SESSION !== $this) {
         $_SESSION = $this;
     }
     return $this;
 }
Exemple #3
0
 public function testClearWhenStorageMarkedImmutableRaisesException()
 {
     $this->storage->foo = 'bar';
     $this->storage->bar = 'baz';
     $this->storage->markImmutable();
     $this->setExpectedException('Zend\\Session\\Exception\\RuntimeException', 'Cannot clear storage as it is marked immutable');
     $this->storage->clear();
 }
Exemple #4
0
 /**
  * Constructor
  *
  * Sets the $_SESSION superglobal to an ArrayObject, maintaining previous
  * values if any discovered.
  *
  * @param  array|null $input
  * @param  int $flags
  * @param  string $iteratorClass
  */
 public function __construct($input = null, $flags = ArrayObject::ARRAY_AS_PROPS, $iteratorClass = '\\ArrayIterator')
 {
     $resetSession = true;
     if (null === $input && isset($_SESSION)) {
         $input = $_SESSION;
         if (is_object($input) && $_SESSION instanceof \ArrayObject) {
             $resetSession = false;
         } elseif (is_object($input) && !$_SESSION instanceof \ArrayObject) {
             $input = (array) $input;
         }
     } elseif (null === $input) {
         $input = array();
     }
     parent::__construct($input, $flags, $iteratorClass);
     if ($resetSession) {
         $_SESSION = $this;
     }
 }
Exemple #5
0
 public function testRequestAccessTimeIsPreservedEvenInFactoryMethod()
 {
     $this->assertNotEmpty($this->storage->getRequestAccessTime());
     $this->storage->fromArray(array());
     $this->assertNotEmpty($this->storage->getRequestAccessTime());
 }