Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Protected Attributes | Static Protected Attributes
Zend_Session_Namespace Class Reference
Inheritance diagram for Zend_Session_Namespace:
Zend_Session_Abstract

Public Member Functions

 __construct ($namespace='Default', $singleInstance=false)
 
 getIterator ()
 
 lock ()
 
 unlock ()
 
 isLocked ()
 
 unsetAll ()
 
__get ($name)
 
 __set ($name, $value)
 
 apply ($callback)
 
 applySet ($callback)
 
 __isset ($name)
 
 __unset ($name)
 
 setExpirationSeconds ($seconds, $variables=null)
 
 setExpirationHops ($hops, $variables=null, $hopCountOnUsageOnly=false)
 
 getNamespace ()
 

Static Public Member Functions

static resetSingleInstance ($namespaceName=null)
 
static unlockAll ()
 

Data Fields

const SINGLE_INSTANCE = true
 
- Data Fields inherited from Zend_Session_Abstract
const _THROW_NOT_WRITABLE_MSG = 'Zend_Session is currently marked as read-only.'
 
const _THROW_NOT_READABLE_MSG = 'Zend_Session is not marked as readable.'
 

Protected Attributes

 $_namespace = "Default"
 

Static Protected Attributes

static $_namespaceLocks = array()
 
static $_singleInstances = array()
 
- Static Protected Attributes inherited from Zend_Session_Abstract
static $_writable = false
 
static $_readable = false
 
static $_expiringData = array()
 

Additional Inherited Members

- Static Protected Member Functions inherited from Zend_Session_Abstract
static _namespaceIsset ($namespace, $name=null)
 
static _namespaceUnset ($namespace, $name=null)
 
static & _namespaceGet ($namespace, $name=null)
 
static _namespaceGetAll ($namespace)
 

Detailed Description

Definition at line 44 of file Namespace.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $namespace = 'Default',
  $singleInstance = false 
)

__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.

Parameters
string$namespace- programmatic name of the requested namespace
bool$singleInstance- prevent creation of additional accessor instance objects for this namespace
Returns
void
See also
Zend_Session_Exception
Zend_Session_Exception
Zend_Session_Exception
Zend_Session_Exception
Zend_Session_Exception

Definition at line 102 of file Namespace.php.

103  {
104  if ($namespace === '') {
108  #require_once 'Zend/Session/Exception.php';
109  throw new Zend_Session_Exception('Session namespace must be a non-empty string.');
110  }
111 
112  if ($namespace[0] == "_") {
116  #require_once 'Zend/Session/Exception.php';
117  throw new Zend_Session_Exception('Session namespace must not start with an underscore.');
118  }
119 
120  if (preg_match('#(^[0-9])#i', $namespace[0])) {
124  #require_once 'Zend/Session/Exception.php';
125  throw new Zend_Session_Exception('Session namespace must not start with a number.');
126  }
127 
128  if (isset(self::$_singleInstances[$namespace])) {
132  #require_once 'Zend/Session/Exception.php';
133  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.");
134  }
135 
136  if ($singleInstance === true) {
137  self::$_singleInstances[$namespace] = true;
138  }
139 
140  $this->_namespace = $namespace;
141 
142  // Process metadata specific only to this namespace.
143  Zend_Session::start(true); // attempt auto-start (throws exception if strict option set)
144 
145  if (self::$_readable === false) {
149  #require_once 'Zend/Session/Exception.php';
150  throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG);
151  }
152 
153  if (!isset($_SESSION['__ZF'])) {
154  return; // no further processing needed
155  }
156 
157  // do not allow write access to namespaces, after stop() or writeClose()
158  if (parent::$_writable === true) {
159  if (isset($_SESSION['__ZF'][$namespace])) {
160 
161  // Expire Namespace by Namespace Hop (ENNH)
162  if (isset($_SESSION['__ZF'][$namespace]['ENNH'])) {
163  $_SESSION['__ZF'][$namespace]['ENNH']--;
164 
165  if ($_SESSION['__ZF'][$namespace]['ENNH'] === 0) {
166  if (isset($_SESSION[$namespace])) {
167  self::$_expiringData[$namespace] = $_SESSION[$namespace];
168  unset($_SESSION[$namespace]);
169  }
170  unset($_SESSION['__ZF'][$namespace]);
171  }
172  }
173 
174  // Expire Namespace Variables by Namespace Hop (ENVNH)
175  if (isset($_SESSION['__ZF'][$namespace]['ENVNH'])) {
176  foreach ($_SESSION['__ZF'][$namespace]['ENVNH'] as $variable => $hops) {
177  $_SESSION['__ZF'][$namespace]['ENVNH'][$variable]--;
178 
179  if ($_SESSION['__ZF'][$namespace]['ENVNH'][$variable] === 0) {
180  if (isset($_SESSION[$namespace][$variable])) {
181  self::$_expiringData[$namespace][$variable] = $_SESSION[$namespace][$variable];
182  unset($_SESSION[$namespace][$variable]);
183  }
184  unset($_SESSION['__ZF'][$namespace]['ENVNH'][$variable]);
185  }
186  }
187  if(empty($_SESSION['__ZF'][$namespace]['ENVNH'])) {
188  unset($_SESSION['__ZF'][$namespace]['ENVNH']);
189  }
190  }
191  }
192 
193  if (empty($_SESSION['__ZF'][$namespace])) {
194  unset($_SESSION['__ZF'][$namespace]);
195  }
196 
197  if (empty($_SESSION['__ZF'])) {
198  unset($_SESSION['__ZF']);
199  }
200  }
201  }
$variable
Definition: variable.php:7
static start($options=false)
Definition: Session.php:421

Member Function Documentation

◆ __get()

& __get (   $name)

__get() - method to get a variable in this object's current namespace

Parameters
string$name- programmatic name of a key, in a <key,value> pair in the current namespace
Returns
mixed
See also
Zend_Session_Exception

Definition at line 277 of file Namespace.php.

278  {
279  if ($name === '') {
283  #require_once 'Zend/Session/Exception.php';
284  throw new Zend_Session_Exception("The '$name' key must be a non-empty string");
285  }
286 
287  return parent::_namespaceGet($this->_namespace, $name);
288  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ __isset()

__isset (   $name)

__isset() - determine if a variable in this object's namespace is set

Parameters
string$name- programmatic name of a key, in a <key,value> pair in the current namespace
Returns
bool
See also
Zend_Session_Exception

Definition at line 384 of file Namespace.php.

385  {
386  if ($name === '') {
390  #require_once 'Zend/Session/Exception.php';
391  throw new Zend_Session_Exception("The '$name' key must be a non-empty string");
392  }
393 
394  return parent::_namespaceIsset($this->_namespace, $name);
395  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ __set()

__set (   $name,
  $value 
)

__set() - method to set a variable/value in this object's namespace

Parameters
string$name- programmatic name of a key, in a <key,value> pair in the current namespace
mixed$value- value in the <key,value> pair to assign to the $name key
Exceptions
Zend_Session_Exception
Returns
true
See also
Zend_Session_Exception
Zend_Session_Exception
Zend_Session_Exception

Definition at line 299 of file Namespace.php.

300  {
301  if (isset(self::$_namespaceLocks[$this->_namespace])) {
305  #require_once 'Zend/Session/Exception.php';
306  throw new Zend_Session_Exception('This session/namespace has been marked as read-only.');
307  }
308 
309  if ($name === '') {
313  #require_once 'Zend/Session/Exception.php';
314  throw new Zend_Session_Exception("The '$name' key must be a non-empty string");
315  }
316 
317  if (parent::$_writable === false) {
321  #require_once 'Zend/Session/Exception.php';
322  throw new Zend_Session_Exception(parent::_THROW_NOT_WRITABLE_MSG);
323  }
324 
325  $name = (string) $name;
326 
327  $_SESSION[$this->_namespace][$name] = $value;
328  }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ __unset()

__unset (   $name)

__unset() - unset a variable in this object's namespace.

Parameters
string$name- programmatic name of a key, in a <key,value> pair in the current namespace
Returns
true
See also
Zend_Session_Exception

Definition at line 404 of file Namespace.php.

405  {
406  if ($name === '') {
410  #require_once 'Zend/Session/Exception.php';
411  throw new Zend_Session_Exception("The '$name' key must be a non-empty string");
412  }
413 
414  return parent::_namespaceUnset($this->_namespace, $name);
415  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ apply()

apply (   $callback)

apply() - enables applying user-selected function, such as array_merge() to the namespace Parameters following the $callback argument are passed to the callback function. Caveat: ignores members expiring now.

Example: $namespace->apply('array_merge', array('tree' => 'apple', 'fruit' => 'peach'), array('flower' => 'rose')); $namespace->apply('count');

Parameters
string | array$callback- callback function

Definition at line 342 of file Namespace.php.

343  {
344  $arg_list = func_get_args();
345  $arg_list[0] = $_SESSION[$this->_namespace];
346  return call_user_func_array($callback, $arg_list);
347  }

◆ applySet()

applySet (   $callback)

applySet() - enables applying user-selected function, and sets entire namespace to the result Result of $callback must be an array. Parameters following the $callback argument are passed to the callback function. Caveat: ignores members expiring now.

Example: $namespace->applySet('array_merge', array('tree' => 'apple', 'fruit' => 'peach'), array('flower' => 'rose'));

Parameters
string | array$callback- callback function
See also
Zend_Session_Exception

Definition at line 361 of file Namespace.php.

362  {
363  $arg_list = func_get_args();
364  $arg_list[0] = $_SESSION[$this->_namespace];
365  $result = call_user_func_array($callback, $arg_list);
366  if (!is_array($result)) {
370  #require_once 'Zend/Session/Exception.php';
371  throw new Zend_Session_Exception('Result must be an array. Got: ' . gettype($result));
372  }
373  $_SESSION[$this->_namespace] = $result;
374  return $result;
375  }

◆ getIterator()

getIterator ( )

getIterator() - return an iteratable object for use in foreach and the like, this completes the IteratorAggregate interface

Returns
ArrayObject - iteratable container of the namespace contents

Definition at line 210 of file Namespace.php.

211  {
212  return new ArrayObject(parent::_namespaceGetAll($this->_namespace));
213  }

◆ getNamespace()

getNamespace ( )

Returns the namespace name

Returns
string

Definition at line 525 of file Namespace.php.

526  {
527  return $this->_namespace;
528  }

◆ isLocked()

isLocked ( )

isLocked() - return lock status, true if, and only if, read-only

Returns
bool

Definition at line 254 of file Namespace.php.

255  {
256  return isset(self::$_namespaceLocks[$this->_namespace]);
257  }

◆ lock()

lock ( )

lock() - mark a session/namespace as readonly

Returns
void

Definition at line 221 of file Namespace.php.

222  {
223  self::$_namespaceLocks[$this->_namespace] = true;
224  }

◆ resetSingleInstance()

static resetSingleInstance (   $namespaceName = null)
static

resetSingleInstance()

Parameters
string$namespaceName
Returns
null

Definition at line 79 of file Namespace.php.

80  {
81  if ($namespaceName != null) {
82  if (array_key_exists($namespaceName, self::$_singleInstances)) {
83  unset(self::$_singleInstances[$namespaceName]);
84  }
85  return;
86  }
87 
88  self::$_singleInstances = array();
89  return;
90  }

◆ setExpirationHops()

setExpirationHops (   $hops,
  $variables = null,
  $hopCountOnUsageOnly = false 
)

setExpirationHops() - expire the namespace, or specific variables after a specified number of page hops

Parameters
int$hops- how many "hops" (number of subsequent requests) before expiring
mixed$variables- OPTIONAL list of variables to expire (defaults to all)
boolean$hopCountOnUsageOnly- OPTIONAL if set, only count a hop/request if this namespace is used
Exceptions
Zend_Session_Exception
Returns
void
See also
Zend_Session_Exception
Zend_Session_Exception

Definition at line 475 of file Namespace.php.

476  {
477  if (parent::$_writable === false) {
481  #require_once 'Zend/Session/Exception.php';
482  throw new Zend_Session_Exception(parent::_THROW_NOT_WRITABLE_MSG);
483  }
484 
485  if ($hops <= 0) {
489  #require_once 'Zend/Session/Exception.php';
490  throw new Zend_Session_Exception('Hops must be positive number.');
491  }
492 
493  if ($variables === null) {
494 
495  // apply expiration to entire namespace
496  if ($hopCountOnUsageOnly === false) {
497  $_SESSION['__ZF'][$this->_namespace]['ENGH'] = $hops;
498  } else {
499  $_SESSION['__ZF'][$this->_namespace]['ENNH'] = $hops;
500  }
501 
502  } else {
503 
504  if (is_string($variables)) {
505  $variables = array($variables);
506  }
507 
508  foreach ($variables as $variable) {
509  if (!empty($variable)) {
510  if ($hopCountOnUsageOnly === false) {
511  $_SESSION['__ZF'][$this->_namespace]['ENVGH'][$variable] = $hops;
512  } else {
513  $_SESSION['__ZF'][$this->_namespace]['ENVNH'][$variable] = $hops;
514  }
515  }
516  }
517  }
518  }
$variable
Definition: variable.php:7

◆ setExpirationSeconds()

setExpirationSeconds (   $seconds,
  $variables = null 
)

setExpirationSeconds() - expire the namespace, or specific variables after a specified number of seconds

Parameters
int$seconds- expires in this many seconds
mixed$variables- OPTIONAL list of variables to expire (defaults to all)
Exceptions
Zend_Session_Exception
Returns
void
See also
Zend_Session_Exception
Zend_Session_Exception

Definition at line 427 of file Namespace.php.

428  {
429  if (parent::$_writable === false) {
433  #require_once 'Zend/Session/Exception.php';
434  throw new Zend_Session_Exception(parent::_THROW_NOT_WRITABLE_MSG);
435  }
436 
437  if ($seconds <= 0) {
441  #require_once 'Zend/Session/Exception.php';
442  throw new Zend_Session_Exception('Seconds must be positive.');
443  }
444 
445  if ($variables === null) {
446 
447  // apply expiration to entire namespace
448  $_SESSION['__ZF'][$this->_namespace]['ENT'] = time() + $seconds;
449 
450  } else {
451 
452  if (is_string($variables)) {
453  $variables = array($variables);
454  }
455 
456  foreach ($variables as $variable) {
457  if (!empty($variable)) {
458  $_SESSION['__ZF'][$this->_namespace]['ENVT'][$variable] = time() + $seconds;
459  }
460  }
461  }
462  }
$variable
Definition: variable.php:7

◆ unlock()

unlock ( )

unlock() - unmark a session/namespace to enable read & write

Returns
void

Definition at line 232 of file Namespace.php.

233  {
234  unset(self::$_namespaceLocks[$this->_namespace]);
235  }

◆ unlockAll()

static unlockAll ( )
static

unlockAll() - unmark all session/namespaces to enable read & write

Returns
void

Definition at line 243 of file Namespace.php.

244  {
245  self::$_namespaceLocks = array();
246  }

◆ unsetAll()

unsetAll ( )

unsetAll() - unset all variables in this namespace

Returns
true

Definition at line 265 of file Namespace.php.

266  {
267  return parent::_namespaceUnset($this->_namespace);
268  }

Field Documentation

◆ $_namespace

$_namespace = "Default"
protected

Definition at line 57 of file Namespace.php.

◆ $_namespaceLocks

$_namespaceLocks = array()
staticprotected

Definition at line 64 of file Namespace.php.

◆ $_singleInstances

$_singleInstances = array()
staticprotected

Definition at line 71 of file Namespace.php.

◆ SINGLE_INSTANCE

const SINGLE_INSTANCE = true

used as option to constructor to prevent additional instances to the same namespace

Definition at line 50 of file Namespace.php.


The documentation for this class was generated from the following file: