13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Http |
16 * @package Zend_Http |
17 * @subpackage UserAgent |
17 * @subpackage UserAgent |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 */ |
20 */ |
21 |
21 |
22 /** |
22 /** |
23 * @see Zend_Http_UserAgent_Storage |
23 * @see Zend_Http_UserAgent_Storage |
30 require_once 'Zend/Session/Namespace.php'; |
30 require_once 'Zend/Session/Namespace.php'; |
31 |
31 |
32 /** |
32 /** |
33 * @package Zend_Http |
33 * @package Zend_Http |
34 * @subpackage UserAgent |
34 * @subpackage UserAgent |
35 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
35 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
37 */ |
37 */ |
38 class Zend_Http_UserAgent_Storage_Session implements Zend_Http_UserAgent_Storage |
38 class Zend_Http_UserAgent_Storage_Session implements Zend_Http_UserAgent_Storage |
39 { |
39 { |
40 /** |
40 /** |
41 * Default session namespace |
41 * Default session namespace |
42 */ |
42 */ |
43 const NAMESPACE_DEFAULT = 'Zend_Http_UserAgent'; |
43 const NAMESPACE_DEFAULT = 'Zend_Http_UserAgent'; |
44 |
44 |
45 /** |
45 /** |
46 * Default session object member name |
46 * Default session object member name |
47 */ |
47 */ |
48 const MEMBER_DEFAULT = 'storage'; |
48 const MEMBER_DEFAULT = 'storage'; |
49 |
49 |
50 /** |
50 /** |
51 * Object to proxy $_SESSION storage |
51 * Object to proxy $_SESSION storage |
52 * |
52 * |
53 * @var Zend_Session_Namespace |
53 * @var Zend_Session_Namespace |
54 */ |
54 */ |
55 protected $_session; |
55 protected $_session; |
56 |
56 |
57 /** |
57 /** |
58 * Session namespace |
58 * Session namespace |
59 * |
59 * |
60 * @var mixed |
60 * @var mixed |
61 */ |
61 */ |
62 protected $_namespace; |
62 protected $_namespace; |
63 |
63 |
64 /** |
64 /** |
65 * Session object member |
65 * Session object member |
66 * |
66 * |
67 * @var mixed |
67 * @var mixed |
68 */ |
68 */ |
69 protected $_member; |
69 protected $_member; |
70 |
70 |
71 /** |
71 /** |
72 * Sets session storage options and initializes session namespace object |
72 * Sets session storage options and initializes session namespace object |
73 * |
73 * |
74 * Expects options to contain 0 or more of the following keys: |
74 * Expects options to contain 0 or more of the following keys: |
75 * - browser_type -- maps to "namespace" internally |
75 * - browser_type -- maps to "namespace" internally |
77 * |
77 * |
78 * @param null|array|object $options |
78 * @param null|array|object $options |
79 * @return void |
79 * @return void |
80 * @throws Zend_Http_UserAgent_Storage_Exception on invalid $options argument |
80 * @throws Zend_Http_UserAgent_Storage_Exception on invalid $options argument |
81 */ |
81 */ |
82 public function __construct($options = null) |
82 public function __construct($options = null) |
83 { |
83 { |
84 if (is_object($options) && method_exists($options, 'toArray')) { |
84 if (is_object($options) && method_exists($options, 'toArray')) { |
85 $options = $options->toArray(); |
85 $options = $options->toArray(); |
86 } elseif (is_object($options)) { |
86 } elseif (is_object($options)) { |
87 $options = (array) $options; |
87 $options = (array) $options; |
93 gettype($options) |
93 gettype($options) |
94 )); |
94 )); |
95 } |
95 } |
96 |
96 |
97 // add '.' to prevent the message ''Session namespace must not start with a number' |
97 // add '.' to prevent the message ''Session namespace must not start with a number' |
98 $this->_namespace = '.' |
98 $this->_namespace = '.' |
99 . (isset($options['browser_type']) |
99 . (isset($options['browser_type']) |
100 ? $options['browser_type'] |
100 ? $options['browser_type'] |
101 : self::NAMESPACE_DEFAULT); |
101 : self::NAMESPACE_DEFAULT); |
102 $this->_member = isset($options['member']) ? $options['member'] : self::MEMBER_DEFAULT; |
102 $this->_member = isset($options['member']) ? $options['member'] : self::MEMBER_DEFAULT; |
103 $this->_session = new Zend_Session_Namespace($this->_namespace); |
103 $this->_session = new Zend_Session_Namespace($this->_namespace); |
104 } |
104 } |
105 |
105 |
106 /** |
106 /** |
107 * Returns the session namespace name |
107 * Returns the session namespace name |
108 * |
108 * |
109 * @return string |
109 * @return string |
110 */ |
110 */ |
111 public function getNamespace() |
111 public function getNamespace() |
112 { |
112 { |
113 return $this->_namespace; |
113 return $this->_namespace; |
114 } |
114 } |
115 |
115 |
116 /** |
116 /** |
117 * Returns the name of the session object member |
117 * Returns the name of the session object member |
118 * |
118 * |
119 * @return string |
119 * @return string |
120 */ |
120 */ |
121 public function getMember() |
121 public function getMember() |
122 { |
122 { |
123 return $this->_member; |
123 return $this->_member; |
124 } |
124 } |
125 |
125 |
126 /** |
126 /** |
127 * Defined by Zend_Http_UserAgent_Storage |
127 * Defined by Zend_Http_UserAgent_Storage |
128 * |
128 * |
129 * @return boolean |
129 * @return boolean |
130 */ |
130 */ |
131 public function isEmpty() |
131 public function isEmpty() |
132 { |
132 { |
133 return empty($this->_session->{$this->_member}); |
133 return empty($this->_session->{$this->_member}); |
134 } |
134 } |
135 |
135 |
136 /** |
136 /** |
137 * Defined by Zend_Http_UserAgent_Storage |
137 * Defined by Zend_Http_UserAgent_Storage |
138 * |
138 * |
139 * @return mixed |
139 * @return mixed |
140 */ |
140 */ |
141 public function read() |
141 public function read() |
142 { |
142 { |
143 return $this->_session->{$this->_member}; |
143 return $this->_session->{$this->_member}; |
144 } |
144 } |
145 |
145 |
146 /** |
146 /** |
147 * Defined by Zend_Http_UserAgent_Storage |
147 * Defined by Zend_Http_UserAgent_Storage |
148 * |
148 * |
149 * @param mixed $contents |
149 * @param mixed $contents |
150 * @return void |
150 * @return void |
151 */ |
151 */ |
152 public function write($content) |
152 public function write($content) |
153 { |
153 { |
154 $this->_session->{$this->_member} = $content; |
154 $this->_session->{$this->_member} = $content; |
155 } |
155 } |
156 |
156 |
157 /** |
157 /** |
158 * Defined by Zend_Http_UserAgent_Storage |
158 * Defined by Zend_Http_UserAgent_Storage |
159 * |
159 * |
160 * @return void |
160 * @return void |
161 */ |
161 */ |
162 public function clear() |
162 public function clear() |
163 { |
163 { |
164 unset($this->_session->{$this->_member}); |
164 unset($this->_session->{$this->_member}); |
165 } |
165 } |
166 } |
166 } |