/usr/share/php/Nette/Http/SessionSection.php is in php-nette 2.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | <?php
/**
* This file is part of the Nette Framework (http://nette.org)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/
namespace Nette\Http;
use Nette;
/**
* Session section.
*
* @author David Grudl
*/
class SessionSection extends Nette\Object implements \IteratorAggregate, \ArrayAccess
{
/** @var Session */
private $session;
/** @var string */
private $name;
/** @var array session data storage */
private $data;
/** @var array session metadata storage */
private $meta = FALSE;
/** @var bool */
public $warnOnUndefined = FALSE;
/**
* Do not call directly. Use Session::getSection().
*/
public function __construct(Session $session, $name)
{
if (!is_string($name)) {
throw new Nette\InvalidArgumentException("Session namespace must be a string, " . gettype($name) ." given.");
}
$this->session = $session;
$this->name = $name;
}
/**
* Do not call directly. Use Session::getNamespace().
*/
private function start()
{
if ($this->meta === FALSE) {
$this->session->start();
$this->data = & $_SESSION['__NF']['DATA'][$this->name];
$this->meta = & $_SESSION['__NF']['META'][$this->name];
}
}
/**
* Returns an iterator over all section variables.
* @return \ArrayIterator
*/
public function getIterator()
{
$this->start();
if (isset($this->data)) {
return new \ArrayIterator($this->data);
} else {
return new \ArrayIterator;
}
}
/**
* Sets a variable in this session section.
* @param string name
* @param mixed value
* @return void
*/
public function __set($name, $value)
{
$this->start();
$this->data[$name] = $value;
if (is_object($value)) {
$this->meta[$name]['V'] = Nette\Reflection\ClassType::from($value)->getAnnotation('serializationVersion');
}
}
/**
* Gets a variable from this session section.
* @param string name
* @return mixed
*/
public function &__get($name)
{
$this->start();
if ($this->warnOnUndefined && !array_key_exists($name, $this->data)) {
trigger_error("The variable '$name' does not exist in session section", E_USER_NOTICE);
}
return $this->data[$name];
}
/**
* Determines whether a variable in this session section is set.
* @param string name
* @return bool
*/
public function __isset($name)
{
if ($this->session->exists()) {
$this->start();
}
return isset($this->data[$name]);
}
/**
* Unsets a variable in this session section.
* @param string name
* @return void
*/
public function __unset($name)
{
$this->start();
unset($this->data[$name], $this->meta[$name]);
}
/**
* Sets a variable in this session section.
* @param string name
* @param mixed value
* @return void
*/
public function offsetSet($name, $value)
{
$this->__set($name, $value);
}
/**
* Gets a variable from this session section.
* @param string name
* @return mixed
*/
public function offsetGet($name)
{
return $this->__get($name);
}
/**
* Determines whether a variable in this session section is set.
* @param string name
* @return bool
*/
public function offsetExists($name)
{
return $this->__isset($name);
}
/**
* Unsets a variable in this session section.
* @param string name
* @return void
*/
public function offsetUnset($name)
{
$this->__unset($name);
}
/**
* Sets the expiration of the section or specific variables.
* @param string|int|DateTime time, value 0 means "until the browser is closed"
* @param mixed optional list of variables / single variable to expire
* @return self
*/
public function setExpiration($time, $variables = NULL)
{
$this->start();
if (empty($time)) {
$time = NULL;
$whenBrowserIsClosed = TRUE;
} else {
$time = Nette\DateTime::from($time)->format('U');
$max = ini_get('session.gc_maxlifetime');
if ($time - time() > $max + 3) { // bulgarian constant
trigger_error("The expiration time is greater than the session expiration $max seconds", E_USER_NOTICE);
}
$whenBrowserIsClosed = FALSE;
}
if ($variables === NULL) { // to entire section
$this->meta['']['T'] = $time;
$this->meta['']['B'] = $whenBrowserIsClosed;
} elseif (is_array($variables)) { // to variables
foreach ($variables as $variable) {
$this->meta[$variable]['T'] = $time;
$this->meta[$variable]['B'] = $whenBrowserIsClosed;
}
} else { // to variable
$this->meta[$variables]['T'] = $time;
$this->meta[$variables]['B'] = $whenBrowserIsClosed;
}
return $this;
}
/**
* Removes the expiration from the section or specific variables.
* @param mixed optional list of variables / single variable to expire
* @return void
*/
public function removeExpiration($variables = NULL)
{
$this->start();
if ($variables === NULL) {
// from entire section
unset($this->meta['']['T'], $this->meta['']['B']);
} elseif (is_array($variables)) {
// from variables
foreach ($variables as $variable) {
unset($this->meta[$variable]['T'], $this->meta[$variable]['B']);
}
} else {
unset($this->meta[$variables]['T'], $this->meta[$variables]['B']);
}
}
/**
* Cancels the current session section.
* @return void
*/
public function remove()
{
$this->start();
$this->data = NULL;
$this->meta = NULL;
}
}
|