1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: class Horde_Core_Notification_Storage_Session
27: implements Horde_Notification_Storage_Interface
28: {
29: 30: 31: 32: 33:
34: protected $_cached = array();
35:
36: 37:
38: public function get($key)
39: {
40: $this->_processCached();
41: return $GLOBALS['session']->get('horde', 'notify/' . $key);
42: }
43:
44: 45:
46: public function set($key, $value)
47: {
48: if ($GLOBALS['session']->isActive()) {
49: $this->_processCached();
50: $GLOBALS['session']->set('horde', 'notify/' . $key, $value);
51: } else {
52: $this->_cached[] = array($key, $value);
53: }
54: }
55:
56: 57:
58: public function exists($key)
59: {
60: $this->_processCached();
61: return $GLOBALS['session']->exists('horde', 'notify/' . $key);
62: }
63:
64: 65:
66: public function clear($key)
67: {
68: $this->_cached = array();
69: $GLOBALS['session']->remove('horde', 'notify/' . $key);
70: }
71:
72: 73:
74: public function push($listener, Horde_Notification_Event $event)
75: {
76: global $session;
77:
78: if ($session->isActive()) {
79: $events = $session->get('horde', 'notify/' . $listener, Horde_Session::TYPE_ARRAY);
80: $events[] = $event;
81: $session->set('horde', 'notify/' . $listener, $events, Horde_Session::TYPE_OBJECT);
82: } else {
83: $this->_cached[] = array($listener, $event);
84: }
85: }
86:
87: 88:
89: protected function _processCached()
90: {
91: if (!empty($this->_cached) && $GLOBALS['session']->isActive()) {
92: $cached = $this->_cached;
93: $this->_cached = array();
94:
95: foreach ($cached as $val) {
96: if ($val[1] instanceof Horde_Notification_Event) {
97: $this->push($val[0], $val[1]);
98: } else {
99: $this->set($val[0], $val[1]);
100: }
101: }
102: }
103: }
104:
105: }
106: