Source of file SessionStorage.php
Size: 2,644 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Session/Storage/SessionStorage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Session\Storage; use Zend\Stdlib\ArrayObject; /** * Session storage in $_SESSION * * Replaces the $_SESSION superglobal with an ArrayObject that allows for * property access, metadata storage, locking, and immutability. */ class SessionStorage extends ArrayStorage { /** * 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; } } /** * Destructor * * Resets $_SESSION superglobal to an array, by casting object using * getArrayCopy(). * * @return void */ public function __destruct() { $_SESSION = (array) $this->getArrayCopy(); } /** * 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; } /** * Mark object as isImmutable * * @return SessionStorage */ public function markImmutable() { $this['_IMMUTABLE'] = true; return $this; } /** * Determine if this object is isImmutable * * @return bool */ public function isImmutable() { return (isset($this['_IMMUTABLE']) && $this['_IMMUTABLE']); } } |