File indexing completed on 2024-06-16 05:25:46

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Auth
0017  * @subpackage Storage
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 
0024 /**
0025  * @see Zend_Auth_Storage_Interface
0026  */
0027 // require_once 'Zend/Auth/Storage/Interface.php';
0028 
0029 
0030 /**
0031  * @see Zend_Session
0032  */
0033 // require_once 'Zend/Session.php';
0034 
0035 
0036 /**
0037  * @category   Zend
0038  * @package    Zend_Auth
0039  * @subpackage Storage
0040  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0041  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0042  */
0043 class Zend_Auth_Storage_Session implements Zend_Auth_Storage_Interface
0044 {
0045     /**
0046      * Default session namespace
0047      */
0048     const NAMESPACE_DEFAULT = 'Zend_Auth';
0049 
0050     /**
0051      * Default session object member name
0052      */
0053     const MEMBER_DEFAULT = 'storage';
0054 
0055     /**
0056      * Object to proxy $_SESSION storage
0057      *
0058      * @var Zend_Session_Namespace
0059      */
0060     protected $_session;
0061 
0062     /**
0063      * Session namespace
0064      *
0065      * @var mixed
0066      */
0067     protected $_namespace;
0068 
0069     /**
0070      * Session object member
0071      *
0072      * @var mixed
0073      */
0074     protected $_member;
0075 
0076     /**
0077      * Sets session storage options and initializes session namespace object
0078      *
0079      * @param mixed $namespace
0080      * @param mixed $member
0081      */
0082     public function __construct($namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT)
0083     {
0084         $this->_namespace = $namespace;
0085         $this->_member    = $member;
0086         $this->_session   = new Zend_Session_Namespace($this->_namespace);
0087     }
0088 
0089     /**
0090      * Returns the session namespace
0091      *
0092      * @return string
0093      */
0094     public function getNamespace()
0095     {
0096         return $this->_namespace;
0097     }
0098 
0099     /**
0100      * Returns the name of the session object member
0101      *
0102      * @return string
0103      */
0104     public function getMember()
0105     {
0106         return $this->_member;
0107     }
0108 
0109     /**
0110      * Defined by Zend_Auth_Storage_Interface
0111      *
0112      * @return boolean
0113      */
0114     public function isEmpty()
0115     {
0116         return !isset($this->_session->{$this->_member});
0117     }
0118 
0119     /**
0120      * Defined by Zend_Auth_Storage_Interface
0121      *
0122      * @return mixed
0123      */
0124     public function read()
0125     {
0126         return $this->_session->{$this->_member};
0127     }
0128 
0129     /**
0130      * Defined by Zend_Auth_Storage_Interface
0131      *
0132      * @param  mixed $contents
0133      * @return void
0134      */
0135     public function write($contents)
0136     {
0137         $this->_session->{$this->_member} = $contents;
0138     }
0139 
0140     /**
0141      * Defined by Zend_Auth_Storage_Interface
0142      *
0143      * @return void
0144      */
0145     public function clear()
0146     {
0147         unset($this->_session->{$this->_member});
0148     }
0149 }