File indexing completed on 2024-12-29 05:27:45
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_Http 0017 * @subpackage UserAgent 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 */ 0021 0022 /** 0023 * @see Zend_Http_UserAgent_Storage 0024 */ 0025 // require_once 'Zend/Http/UserAgent/Storage.php'; 0026 0027 /** 0028 * @see Zend_Session_Namespace 0029 */ 0030 // require_once 'Zend/Session/Namespace.php'; 0031 0032 /** 0033 * @package Zend_Http 0034 * @subpackage UserAgent 0035 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0036 * @license http://framework.zend.com/license/new-bsd New BSD License 0037 */ 0038 class Zend_Http_UserAgent_Storage_Session implements Zend_Http_UserAgent_Storage 0039 { 0040 /** 0041 * Default session namespace 0042 */ 0043 const NAMESPACE_DEFAULT = 'Zend_Http_UserAgent'; 0044 0045 /** 0046 * Default session object member name 0047 */ 0048 const MEMBER_DEFAULT = 'storage'; 0049 0050 /** 0051 * Object to proxy $_SESSION storage 0052 * 0053 * @var Zend_Session_Namespace 0054 */ 0055 protected $_session; 0056 0057 /** 0058 * Session namespace 0059 * 0060 * @var mixed 0061 */ 0062 protected $_namespace; 0063 0064 /** 0065 * Session object member 0066 * 0067 * @var mixed 0068 */ 0069 protected $_member; 0070 0071 /** 0072 * Sets session storage options and initializes session namespace object 0073 * 0074 * Expects options to contain 0 or more of the following keys: 0075 * - browser_type -- maps to "namespace" internally 0076 * - member 0077 * 0078 * @param null|array|object $options 0079 * @return void 0080 * @throws Zend_Http_UserAgent_Storage_Exception on invalid $options argument 0081 */ 0082 public function __construct($options = null) 0083 { 0084 if (is_object($options) && method_exists($options, 'toArray')) { 0085 $options = $options->toArray(); 0086 } elseif (is_object($options)) { 0087 $options = (array) $options; 0088 } 0089 if (null !== $options && !is_array($options)) { 0090 // require_once 'Zend/Http/UserAgent/Storage/Exception.php'; 0091 throw new Zend_Http_UserAgent_Storage_Exception(sprintf( 0092 'Expected array or object options; "%s" provided', 0093 gettype($options) 0094 )); 0095 } 0096 0097 // add '.' to prevent the message ''Session namespace must not start with a number' 0098 $this->_namespace = '.' 0099 . (isset($options['browser_type']) 0100 ? $options['browser_type'] 0101 : self::NAMESPACE_DEFAULT); 0102 $this->_member = isset($options['member']) ? $options['member'] : self::MEMBER_DEFAULT; 0103 $this->_session = new Zend_Session_Namespace($this->_namespace); 0104 } 0105 0106 /** 0107 * Returns the session namespace name 0108 * 0109 * @return string 0110 */ 0111 public function getNamespace() 0112 { 0113 return $this->_namespace; 0114 } 0115 0116 /** 0117 * Returns the name of the session object member 0118 * 0119 * @return string 0120 */ 0121 public function getMember() 0122 { 0123 return $this->_member; 0124 } 0125 0126 /** 0127 * Defined by Zend_Http_UserAgent_Storage 0128 * 0129 * @return boolean 0130 */ 0131 public function isEmpty() 0132 { 0133 return empty($this->_session->{$this->_member}); 0134 } 0135 0136 /** 0137 * Defined by Zend_Http_UserAgent_Storage 0138 * 0139 * @return mixed 0140 */ 0141 public function read() 0142 { 0143 return $this->_session->{$this->_member}; 0144 } 0145 0146 /** 0147 * Defined by Zend_Http_UserAgent_Storage 0148 * 0149 * @param mixed $contents 0150 * @return void 0151 */ 0152 public function write($content) 0153 { 0154 $this->_session->{$this->_member} = $content; 0155 } 0156 0157 /** 0158 * Defined by Zend_Http_UserAgent_Storage 0159 * 0160 * @return void 0161 */ 0162 public function clear() 0163 { 0164 unset($this->_session->{$this->_member}); 0165 } 0166 }