*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Session / Abstract.php
blob448afbf5c544c7f2b0f269f00bf2d587e9fb1ef7
1 <?php
3 /**
4 * Zend Framework
6 * LICENSE
8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
16 * @category Zend
17 * @package Zend_Session
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Abstract.php 16210 2009-06-21 19:22:17Z thomas $
21 * @since Preview Release 0.2
25 /**
26 * Zend_Session_Abstract
28 * @category Zend
29 * @package Zend_Session
30 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
33 abstract class Zend_Session_Abstract
35 /**
36 * Whether or not session permits writing (modification of $_SESSION[])
38 * @var bool
40 protected static $_writable = false;
42 /**
43 * Whether or not session permits reading (reading data in $_SESSION[])
45 * @var bool
47 protected static $_readable = false;
49 /**
50 * Since expiring data is handled at startup to avoid __destruct difficulties,
51 * the data that will be expiring at end of this request is held here
53 * @var array
55 protected static $_expiringData = array();
58 /**
59 * Error message thrown when an action requires modification,
60 * but current Zend_Session has been marked as read-only.
62 const _THROW_NOT_WRITABLE_MSG = 'Zend_Session is currently marked as read-only.';
65 /**
66 * Error message thrown when an action requires reading session data,
67 * but current Zend_Session is not marked as readable.
69 const _THROW_NOT_READABLE_MSG = 'Zend_Session is not marked as readable.';
72 /**
73 * namespaceIsset() - check to see if a namespace or a variable within a namespace is set
75 * @param string $namespace
76 * @param string $name
77 * @return bool
79 protected static function _namespaceIsset($namespace, $name = null)
81 if (self::$_readable === false) {
82 /**
83 * @see Zend_Session_Exception
85 require_once 'Zend/Session/Exception.php';
86 throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG);
89 if ($name === null) {
90 return ( isset($_SESSION[$namespace]) || isset(self::$_expiringData[$namespace]) );
91 } else {
92 return ( isset($_SESSION[$namespace][$name]) || isset(self::$_expiringData[$namespace][$name]) );
97 /**
98 * namespaceUnset() - unset a namespace or a variable within a namespace
100 * @param string $namespace
101 * @param string $name
102 * @throws Zend_Session_Exception
103 * @return void
105 protected static function _namespaceUnset($namespace, $name = null)
107 if (self::$_writable === false) {
109 * @see Zend_Session_Exception
111 require_once 'Zend/Session/Exception.php';
112 throw new Zend_Session_Exception(self::_THROW_NOT_WRITABLE_MSG);
115 $name = (string) $name;
117 // check to see if the api wanted to remove a var from a namespace or a namespace
118 if ($name === '') {
119 unset($_SESSION[$namespace]);
120 unset(self::$_expiringData[$namespace]);
121 } else {
122 unset($_SESSION[$namespace][$name]);
123 unset(self::$_expiringData[$namespace]);
126 // if we remove the last value, remove namespace.
127 if (empty($_SESSION[$namespace])) {
128 unset($_SESSION[$namespace]);
134 * namespaceGet() - Get $name variable from $namespace, returning by reference.
136 * @param string $namespace
137 * @param string $name
138 * @return mixed
140 protected static function & _namespaceGet($namespace, $name = null)
142 if (self::$_readable === false) {
144 * @see Zend_Session_Exception
146 require_once 'Zend/Session/Exception.php';
147 throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG);
150 if ($name === null) {
151 if (isset($_SESSION[$namespace])) { // check session first for data requested
152 return $_SESSION[$namespace];
153 } elseif (isset(self::$_expiringData[$namespace])) { // check expiring data for data reqeusted
154 return self::$_expiringData[$namespace];
155 } else {
156 return $_SESSION[$namespace]; // satisfy return by reference
158 } else {
159 if (isset($_SESSION[$namespace][$name])) { // check session first
160 return $_SESSION[$namespace][$name];
161 } elseif (isset(self::$_expiringData[$namespace][$name])) { // check expiring data
162 return self::$_expiringData[$namespace][$name];
163 } else {
164 return $_SESSION[$namespace][$name]; // satisfy return by reference
171 * namespaceGetAll() - Get an array containing $namespace, including expiring data.
173 * @param string $namespace
174 * @param string $name
175 * @return mixed
177 protected static function _namespaceGetAll($namespace)
179 $currentData = (isset($_SESSION[$namespace]) && is_array($_SESSION[$namespace])) ?
180 $_SESSION[$namespace] : array();
181 $expiringData = (isset(self::$_expiringData[$namespace]) && is_array(self::$_expiringData[$namespace])) ?
182 self::$_expiringData[$namespace] : array();
183 return array_merge($currentData, $expiringData);