1 | <?php |
||
9 | class Session extends Container |
||
10 | { |
||
11 | /** |
||
12 | * Session handler |
||
13 | * |
||
14 | * @var SessionHandlerInterface |
||
15 | */ |
||
16 | protected $handler; |
||
17 | |||
18 | /** |
||
19 | * Session array |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $session = array(); |
||
24 | |||
25 | /** |
||
26 | * Array of settings |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $settings = array(); |
||
31 | |||
32 | /** |
||
33 | * Session key |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $key; |
||
38 | |||
39 | /** |
||
40 | * @param SessionHandlerInterface $handler |
||
41 | * @param array $settings |
||
42 | * @param string $key |
||
43 | */ |
||
44 | public function __construct( |
||
72 | |||
73 | /** |
||
74 | * Returns the current domain for the Session to be saved to, if the installation |
||
75 | * is on localhost, this returns null and just allows PHP to take care of setting |
||
76 | * the valid domain for the Session, otherwise it will return the non-www version |
||
77 | * of the domain host. |
||
78 | * |
||
79 | * @return string|null |
||
80 | * Null if on localhost, or HTTP_HOST is not set, a string of the domain name sans |
||
81 | * www otherwise |
||
82 | */ |
||
83 | public function getDomain() |
||
97 | |||
98 | /** |
||
99 | * Get the current session save key |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | public function key() |
||
107 | |||
108 | /** |
||
109 | * Start the session if it is not already started. |
||
110 | * |
||
111 | * @throws Exception when headers have already been sent |
||
112 | * @return string |
||
113 | */ |
||
114 | public function start() |
||
159 | |||
160 | /** |
||
161 | * Is the session started |
||
162 | * |
||
163 | * @return boolean |
||
164 | */ |
||
165 | protected function isStarted() |
||
177 | |||
178 | /** |
||
179 | * Expires the current session by unsetting the Symphony |
||
180 | * namespace (`$this->key`). If `$this->store` |
||
181 | * is empty, the function will destroy the entire `$this->store` |
||
182 | * |
||
183 | * @link http://au2.php.net/manual/en/function.session-destroy.php |
||
184 | */ |
||
185 | public function expire() |
||
198 | |||
199 | /** |
||
200 | * Set a service or value in this container |
||
201 | * |
||
202 | * @param string $key |
||
203 | * @param mixed $value |
||
204 | */ |
||
205 | public function offsetSet($key, $value) |
||
209 | |||
210 | /** |
||
211 | * Get a service or value from this container |
||
212 | * |
||
213 | * @param string $key |
||
214 | * @return mixed |
||
215 | */ |
||
216 | public function offsetGet($key) |
||
220 | |||
221 | /** |
||
222 | * Check if the container contains the given key |
||
223 | * |
||
224 | * @param string $key |
||
225 | * String key to check |
||
226 | * @return boolean |
||
227 | * Whether the key is in the container |
||
228 | */ |
||
229 | public function offsetExists($key) |
||
233 | |||
234 | /** |
||
235 | * Unset a value from the container |
||
236 | * |
||
237 | * @param string $key |
||
238 | */ |
||
239 | public function offsetUnset($key) |
||
243 | } |
||
244 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: