From 40185a35da57545a47e75f981f7df614a4420591 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 14 Oct 2010 11:43:02 -0600 Subject: [PATCH] Add Notification Storage handler that uses Horde_Session --- .../Core/lib/Horde/Core/Factory/Notification.php | 4 +- .../Horde/Core/Notification/Storage/Session.php | 68 ++++++++++++++++++++++ framework/Core/lib/Horde/Session.php | 4 +- framework/Core/package.xml | 4 ++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Notification/Storage/Session.php diff --git a/framework/Core/lib/Horde/Core/Factory/Notification.php b/framework/Core/lib/Horde/Core/Factory/Notification.php index 1295f6cbd..6c46b5025 100644 --- a/framework/Core/lib/Horde/Core/Factory/Notification.php +++ b/framework/Core/lib/Horde/Core/Factory/Notification.php @@ -7,7 +7,9 @@ class Horde_Core_Factory_Notification { public function create(Horde_Injector $injector) { - $notify = Horde_Notification::singleton(); + $notify = new Horde_Notification_Handler( + new Horde_Core_Notification_Storage_Session() + ); $notify->addType('default', '*', 'Horde_Core_Notification_Status'); $notify->addType('status', 'horde.*', 'Horde_Core_Notification_Status'); diff --git a/framework/Core/lib/Horde/Core/Notification/Storage/Session.php b/framework/Core/lib/Horde/Core/Notification/Storage/Session.php new file mode 100644 index 000000000..1af241f6c --- /dev/null +++ b/framework/Core/lib/Horde/Core/Notification/Storage/Session.php @@ -0,0 +1,68 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + * @package Core + */ + +/** + * A class that stores notifications in the session, using Horde_Session. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @author Michael Slusarz + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + * @package Core + */ +class Horde_Core_Notification_Storage_Session +implements Horde_Notification_Storage_Interface +{ + /** + */ + public function get($key) + { + return $GLOBALS['session']['horde:notify/' . $key]; + } + + /** + */ + public function set($key, $value) + { + $GLOBALS['session']['horde:notify/' . $key] = $value; + } + + /** + */ + public function exists($key) + { + return isset($GLOBALS['session']['horde:notify/' . $key]); + } + + /** + */ + public function clear($key) + { + unset($GLOBALS['session']['horde:notify/' . $key]); + } + + /** + */ + public function push($listener, Horde_Notification_Event $event) + { + global $session; + + $events = $session['horde:notify/' . $listener . ';array']; + $events[] = $event; + $session['horde:notify/' . $listener . ';object'] = $events; + } + +} diff --git a/framework/Core/lib/Horde/Session.php b/framework/Core/lib/Horde/Session.php index 0983bc2dd..4995c75f7 100644 --- a/framework/Core/lib/Horde/Session.php +++ b/framework/Core/lib/Horde/Session.php @@ -333,13 +333,13 @@ class Horde_Session implements ArrayAccess * given page load. Thus, for arrays ans objects, it is beneficial to * always convert to string representations so that the object/array * does not need to be rebuilt every time the session is reloaded. */ - if (is_object($value)) { + if (is_object($value) || ($ob->type == 'object')) { $value = serialize($value); if ($this->_lzf) { $value = lzf_compress($value); } $_SESSION[self::SERIALIZED][$ob->key] = 's'; - } elseif (is_array($value)) { + } elseif (is_array($value) || ($ob->type == 'array')) { $value = json_encode($value); if ($this->_lzf) { $value = lzf_compress($value); diff --git a/framework/Core/package.xml b/framework/Core/package.xml index b896d9515..e25bafb63 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -174,6 +174,9 @@ Application Framework. + + + @@ -471,6 +474,7 @@ Application Framework. + -- 2.11.0