web/lib/Zend/Auth/Storage/Session.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Auth
       
    17  * @subpackage Storage
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Session.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 
       
    24 /**
       
    25  * @see Zend_Auth_Storage_Interface
       
    26  */
       
    27 require_once 'Zend/Auth/Storage/Interface.php';
       
    28 
       
    29 
       
    30 /**
       
    31  * @see Zend_Session
       
    32  */
       
    33 require_once 'Zend/Session.php';
       
    34 
       
    35 
       
    36 /**
       
    37  * @category   Zend
       
    38  * @package    Zend_Auth
       
    39  * @subpackage Storage
       
    40  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    41  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    42  */
       
    43 class Zend_Auth_Storage_Session implements Zend_Auth_Storage_Interface
       
    44 {
       
    45     /**
       
    46      * Default session namespace
       
    47      */
       
    48     const NAMESPACE_DEFAULT = 'Zend_Auth';
       
    49 
       
    50     /**
       
    51      * Default session object member name
       
    52      */
       
    53     const MEMBER_DEFAULT = 'storage';
       
    54 
       
    55     /**
       
    56      * Object to proxy $_SESSION storage
       
    57      *
       
    58      * @var Zend_Session_Namespace
       
    59      */
       
    60     protected $_session;
       
    61 
       
    62     /**
       
    63      * Session namespace
       
    64      *
       
    65      * @var mixed
       
    66      */
       
    67     protected $_namespace;
       
    68 
       
    69     /**
       
    70      * Session object member
       
    71      *
       
    72      * @var mixed
       
    73      */
       
    74     protected $_member;
       
    75 
       
    76     /**
       
    77      * Sets session storage options and initializes session namespace object
       
    78      *
       
    79      * @param  mixed $namespace
       
    80      * @param  mixed $member
       
    81      * @return void
       
    82      */
       
    83     public function __construct($namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT)
       
    84     {
       
    85         $this->_namespace = $namespace;
       
    86         $this->_member    = $member;
       
    87         $this->_session   = new Zend_Session_Namespace($this->_namespace);
       
    88     }
       
    89 
       
    90     /**
       
    91      * Returns the session namespace
       
    92      *
       
    93      * @return string
       
    94      */
       
    95     public function getNamespace()
       
    96     {
       
    97         return $this->_namespace;
       
    98     }
       
    99 
       
   100     /**
       
   101      * Returns the name of the session object member
       
   102      *
       
   103      * @return string
       
   104      */
       
   105     public function getMember()
       
   106     {
       
   107         return $this->_member;
       
   108     }
       
   109 
       
   110     /**
       
   111      * Defined by Zend_Auth_Storage_Interface
       
   112      *
       
   113      * @return boolean
       
   114      */
       
   115     public function isEmpty()
       
   116     {
       
   117         return !isset($this->_session->{$this->_member});
       
   118     }
       
   119 
       
   120     /**
       
   121      * Defined by Zend_Auth_Storage_Interface
       
   122      *
       
   123      * @return mixed
       
   124      */
       
   125     public function read()
       
   126     {
       
   127         return $this->_session->{$this->_member};
       
   128     }
       
   129 
       
   130     /**
       
   131      * Defined by Zend_Auth_Storage_Interface
       
   132      *
       
   133      * @param  mixed $contents
       
   134      * @return void
       
   135      */
       
   136     public function write($contents)
       
   137     {
       
   138         $this->_session->{$this->_member} = $contents;
       
   139     }
       
   140 
       
   141     /**
       
   142      * Defined by Zend_Auth_Storage_Interface
       
   143      *
       
   144      * @return void
       
   145      */
       
   146     public function clear()
       
   147     {
       
   148         unset($this->_session->{$this->_member});
       
   149     }
       
   150 }