📄 namespace.php
字号:
<?php/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category Zend * @package Zend_Session * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id: Namespace.php 163 2008-01-14 04:40:16Z matt $ * @since Preview Release 0.2 *//** * @see Zend_Session */require_once 'Zend/Session.php';/** * @see Zend_Session_Abstract */require_once 'Zend/Session/Abstract.php';/** * Zend_Session_Namespace * * @category Zend * @package Zend_Session * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */class Zend_Session_Namespace extends Zend_Session_Abstract implements IteratorAggregate{ /** * used as option to constructor to prevent additional instances to the same namespace */ const SINGLE_INSTANCE = true; /** * Namespace - which namespace this instance of zend-session is saving-to/getting-from * * @var string */ protected $_namespace = "Default"; /** * Namespace locking mechanism * * @var array */ protected static $_namespaceLocks = array(); /** * Single instance namespace array to ensure data security. * * @var array */ protected static $_singleInstances = array(); /** * __construct() - Returns an instance object bound to a particular, isolated section * of the session, identified by $namespace name (defaulting to 'Default'). * The optional argument $singleInstance will prevent construction of additional * instance objects acting as accessors to this $namespace. * * @param string $namespace - programmatic name of the requested namespace * @param bool $singleInstance - prevent creation of additional accessor instance objects for this namespace * @return void */ public function __construct($namespace = 'Default', $singleInstance = false) { if ($namespace === '') { /** * @see Zend_Session_Exception */ require_once 'Zend/Session/Exception.php'; throw new Zend_Session_Exception('Session namespace must be a non-empty string.'); } if ($namespace[0] == "_") { /** * @see Zend_Session_Exception */ require_once 'Zend/Session/Exception.php'; throw new Zend_Session_Exception('Session namespace must not start with an underscore.'); } if (isset(self::$_singleInstances[$namespace])) { /** * @see Zend_Session_Exception */ require_once 'Zend/Session/Exception.php'; throw new Zend_Session_Exception("A session namespace object already exists for this namespace ('$namespace'), and no additional accessors (session namespace objects) for this namespace are permitted."); } if ($singleInstance === true) { self::$_singleInstances[$namespace] = true; } $this->_namespace = $namespace; // Process metadata specific only to this namespace. Zend_Session::start(true); // attempt auto-start (throws exception if strict option set) if (self::$_readable === false) { /** * @see Zend_Session_Exception */ require_once 'Zend/Session/Exception.php'; throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG); } if (!isset($_SESSION['__ZF'])) { return; // no further processing needed } // do not allow write access to namespaces, after stop() or writeClose() if (parent::$_writable === true) { if (isset($_SESSION['__ZF'][$namespace])) { // Expire Namespace by Namespace Hop (ENNH) if (isset($_SESSION['__ZF'][$namespace]['ENNH'])) { $_SESSION['__ZF'][$namespace]['ENNH']--; if ($_SESSION['__ZF'][$namespace]['ENNH'] === 0) { if (isset($_SESSION[$namespace])) { self::$_expiringData[$namespace] = $_SESSION[$namespace]; unset($_SESSION[$namespace]); } unset($_SESSION['__ZF'][$namespace]['ENNH']); } } // Expire Namespace Variables by Namespace Hop (ENVNH) if (isset($_SESSION['__ZF'][$namespace]['ENVNH'])) { foreach ($_SESSION['__ZF'][$namespace]['ENVNH'] as $variable => $hops) { $_SESSION['__ZF'][$namespace]['ENVNH'][$variable]--; if ($_SESSION['__ZF'][$namespace]['ENVNH'][$variable] === 0) { if (isset($_SESSION[$namespace][$variable])) { self::$_expiringData[$namespace][$variable] = $_SESSION[$namespace][$variable]; unset($_SESSION[$namespace][$variable]); } unset($_SESSION['__ZF'][$namespace]['ENVNH'][$variable]); } } } } if (empty($_SESSION['__ZF'][$namespace])) { unset($_SESSION['__ZF'][$namespace]); } if (empty($_SESSION['__ZF'])) { unset($_SESSION['__ZF']); } } } /** * getIterator() - return an iteratable object for use in foreach and the like, * this completes the IteratorAggregate interface * * @return ArrayObject - iteratable container of the namespace contents */ public function getIterator() { return new ArrayObject(parent::_namespaceGetAll($this->_namespace)); } /** * lock() - mark a session/namespace as readonly * * @return void */ public function lock() { self::$_namespaceLocks[$this->_namespace] = true; } /** * unlock() - unmark a session/namespace to enable read & write * * @return void */ public function unlock() { unset(self::$_namespaceLocks[$this->_namespace]); } /** * unlockAll() - unmark all session/namespaces to enable read & write * * @return void */ public static function unlockAll() { self::$_namespaceLocks = array(); } /** * isLocked() - return lock status, true if, and only if, read-only * * @return bool */ public function isLocked() { return isset(self::$_namespaceLocks[$this->_namespace]); } /** * unsetAll() - unset all variables in this namespace * * @return true */ public function unsetAll() { return parent::_namespaceUnset($this->_namespace); } /** * __get() - method to get a variable in this object's current namespace * * @param string $name - programmatic name of a key, in a <key,value> pair in the current namespace * @return mixed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -