1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14:
15: 16: 17: 18: 19:
20: final class SessionNamespace extends Object implements IteratorAggregate, ArrayAccess
21: {
22:
23: private $data;
24:
25:
26: private $meta;
27:
28:
29: public $warnOnUndefined = FALSE;
30:
31:
32:
33: 34: 35:
36: public function __construct(& $data, & $meta)
37: {
38: $this->data = & $data;
39: $this->meta = & $meta;
40: }
41:
42:
43:
44: 45: 46: 47:
48: public function getIterator()
49: {
50: if (isset($this->data)) {
51: return new ArrayIterator($this->data);
52: } else {
53: return new ArrayIterator;
54: }
55: }
56:
57:
58:
59: 60: 61: 62: 63: 64:
65: public function __set($name, $value)
66: {
67: $this->data[$name] = $value;
68: if (is_object($value)) {
69: $this->meta[$name]['V'] = ClassReflection::from($value)->getAnnotation('serializationVersion');
70: }
71: }
72:
73:
74:
75: 76: 77: 78: 79:
80: public function &__get($name)
81: {
82: if ($this->warnOnUndefined && !array_key_exists($name, $this->data)) {
83: trigger_error("The variable '$name' does not exist in session namespace", E_USER_NOTICE);
84: }
85:
86: return $this->data[$name];
87: }
88:
89:
90:
91: 92: 93: 94: 95:
96: public function __isset($name)
97: {
98: return isset($this->data[$name]);
99: }
100:
101:
102:
103: 104: 105: 106: 107:
108: public function __unset($name)
109: {
110: unset($this->data[$name], $this->meta[$name]);
111: }
112:
113:
114:
115: 116: 117: 118: 119: 120:
121: public function offsetSet($name, $value)
122: {
123: $this->__set($name, $value);
124: }
125:
126:
127:
128: 129: 130: 131: 132:
133: public function offsetGet($name)
134: {
135: return $this->__get($name);
136: }
137:
138:
139:
140: 141: 142: 143: 144:
145: public function offsetExists($name)
146: {
147: return $this->__isset($name);
148: }
149:
150:
151:
152: 153: 154: 155: 156:
157: public function offsetUnset($name)
158: {
159: $this->__unset($name);
160: }
161:
162:
163:
164: 165: 166: 167: 168: 169:
170: public function setExpiration($time, $variables = NULL)
171: {
172: if (empty($time)) {
173: $time = NULL;
174: $whenBrowserIsClosed = TRUE;
175: } else {
176: $time = Tools::createDateTime($time)->format('U');
177: $whenBrowserIsClosed = FALSE;
178: }
179:
180: if ($variables === NULL) { 181: $this->meta['']['T'] = $time;
182: $this->meta['']['B'] = $whenBrowserIsClosed;
183:
184: } elseif (is_array($variables)) { 185: foreach ($variables as $variable) {
186: $this->meta[$variable]['T'] = $time;
187: $this->meta[$variable]['B'] = $whenBrowserIsClosed;
188: }
189:
190: } else { 191: $this->meta[$variables]['T'] = $time;
192: $this->meta[$variables]['B'] = $whenBrowserIsClosed;
193: }
194: return $this;
195: }
196:
197:
198:
199: 200: 201: 202: 203:
204: public function removeExpiration($variables = NULL)
205: {
206: if ($variables === NULL) {
207: 208: unset($this->meta['']['T'], $this->meta['']['B']);
209:
210: } elseif (is_array($variables)) {
211: 212: foreach ($variables as $variable) {
213: unset($this->meta[$variable]['T'], $this->meta[$variable]['B']);
214: }
215: } else {
216: unset($this->meta[$variables]['T'], $this->meta[$variable]['B']);
217: }
218: }
219:
220:
221:
222: 223: 224: 225:
226: public function remove()
227: {
228: $this->data = NULL;
229: $this->meta = NULL;
230: }
231:
232: }
233: