1 | <?php |
||
13 | class Session implements \IteratorAggregate |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * The session data |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | private $sessionData = array(); |
||
22 | |||
23 | /** |
||
24 | * The session namespace |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | private $namespace = null; |
||
29 | |||
30 | /** |
||
31 | * The session identifier |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | private $sessionId; |
||
36 | |||
37 | /** |
||
38 | * Create a new session instance |
||
39 | * |
||
40 | * @param string $namespace |
||
41 | * Optional name of session namespace |
||
42 | */ |
||
43 | public function __construct($namespace = null) |
||
57 | |||
58 | /** |
||
59 | * Set a specific session key to arbitrary data |
||
60 | * |
||
61 | * @param string $key |
||
62 | * The session data key |
||
63 | * @param mixed $value |
||
64 | * The value |
||
65 | */ |
||
66 | public function set($key, $value) |
||
71 | |||
72 | /** |
||
73 | * Destroy the session |
||
74 | */ |
||
75 | public function destroy() |
||
80 | |||
81 | /** |
||
82 | * Update internal session data |
||
83 | */ |
||
84 | private function update() |
||
92 | |||
93 | /** |
||
94 | * Get specific session data |
||
95 | * |
||
96 | * @param string $key |
||
97 | * @return NULL|mixed |
||
98 | */ |
||
99 | public function get($key) |
||
103 | |||
104 | /** |
||
105 | * Checks whether a specific key exists in session data |
||
106 | * |
||
107 | * @param string $key |
||
108 | */ |
||
109 | public function has($key) |
||
113 | |||
114 | /** |
||
115 | * (non-PHPdoc) |
||
116 | * |
||
117 | * @see IteratorAggregate::getIterator() |
||
118 | */ |
||
119 | public function getIterator() |
||
123 | } |
||
124 |
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: