From d000d80252fb52aa5fcac0c718cbbcec08f5762f Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Tue, 27 Oct 2009 18:51:09 +0100
Subject: [PATCH] Splitted off the Horde_Notification_Storage interface and
added the Horde_Notification_Storage_Session class implementing this
interface.
---
framework/Notification/lib/Horde/Notification.php | 49 +++++----
.../lib/Horde/Notification/Storage.php | 39 +++++++
.../lib/Horde/Notification/Storage/Session.php | 113 +++++++++++++++++++++
framework/Notification/package.xml | 6 ++
.../Horde/Notification/Class/NotificationTest.php | 3 +-
5 files changed, 184 insertions(+), 26 deletions(-)
create mode 100644 framework/Notification/lib/Horde/Notification/Storage.php
create mode 100644 framework/Notification/lib/Horde/Notification/Storage/Session.php
diff --git a/framework/Notification/lib/Horde/Notification.php b/framework/Notification/lib/Horde/Notification.php
index 0ff9e2b4e..2ab002d00 100644
--- a/framework/Notification/lib/Horde/Notification.php
+++ b/framework/Notification/lib/Horde/Notification.php
@@ -29,11 +29,11 @@ class Horde_Notification
protected $_listeners = array();
/**
- * The name of the session variable where we store the messages.
+ * The storage location where we store the messages.
*
- * @var string
+ * @var Horde_Notification_Storage
*/
- protected $_stack;
+ protected $_storage;
/**
* A Horde_Alarm instance.
@@ -56,7 +56,8 @@ class Horde_Notification
static public function singleton($stack = 'horde_notification_stacks')
{
if (!isset(self::$_instances[$stack])) {
- self::$_instances[$stack] = new Horde_Notification($stack);
+ $storage = new Horde_Notification_Storage_Session($stack);
+ self::$_instances[$stack] = new Horde_Notification($storage);
}
return self::$_instances[$stack];
@@ -66,17 +67,11 @@ class Horde_Notification
* Initialize the notification system, set up any needed session
* variables, etc.
*
- * @param string $stack The name of the message stack to use.
+ * @param Horde_Notification_Storage $storage The storage location to use.
*/
- protected function __construct($stack)
+ protected function __construct(Horde_Notification_Storage $storage)
{
- $this->_stack = $stack;
-
- /* Make sure the message stack is registered in the session,
- * and obtain a global-scope reference to it. */
- if (!isset($_SESSION[$this->_stack])) {
- $_SESSION[$this->_stack] = array();
- }
+ $this->_storage = $storage;
if (!empty($GLOBALS['conf']['alarms']['driver'])) {
$this->_alarm = Horde_Alarm::factory();
@@ -116,8 +111,8 @@ class Horde_Notification
if (class_exists($class)) {
$this->_listeners[$listener] = new $class($params);
- if (!isset($_SESSION[$this->_stack][$listener])) {
- $_SESSION[$this->_stack][$listener] = array();
+ if (!isset($this->_storage[$listener])) {
+ $this->_storage[$listener] = array();
}
return $this->_listeners[$listener];
}
@@ -141,7 +136,7 @@ class Horde_Notification
}
$list = $this->_listeners[$listener];
- unset($this->_listeners[$listener], $_SESSION[$this->_stack][$list->getName()]);
+ unset($this->_listeners[$listener], $this->_storage[$list->getName()]);
}
/**
@@ -198,11 +193,14 @@ class Horde_Notification
foreach ($this->_listeners as $listener) {
if ($listener->handles($type)) {
- $_SESSION[$this->_stack][$listener->getName()][] = array(
- 'class' => get_class($event),
- 'event' => serialize($event),
- 'flags' => serialize($flags),
- 'type' => $type
+ $this->_storage->push(
+ $listener->getName(),
+ array(
+ 'class' => get_class($event),
+ 'event' => serialize($event),
+ 'flags' => serialize($flags),
+ 'type' => $type
+ )
);
}
}
@@ -231,7 +229,8 @@ class Horde_Notification
foreach ($options['listeners'] as $listener) {
if (isset($this->_listeners[$listener])) {
- $this->_listeners[$listener]->notify($_SESSION[$this->_stack][$this->_listeners[$listener]->getName()], $options);
+ $instance = $this->_storage[$this->_listeners[$listener]->getName()];
+ $this->_listeners[$listener]->notify($instance, $options);
}
}
}
@@ -250,13 +249,13 @@ class Horde_Notification
if (is_null($my_listener)) {
$count = 0;
foreach ($this->_listeners as $listener) {
- if (isset($_SESSION[$this->_stack][$listener->getName()])) {
- $count += count($_SESSION[$this->_stack][$listener->getName()]);
+ if (isset($this->_storage[$listener->getName()])) {
+ $count += count($this->_storage[$listener->getName()]);
}
}
return $count;
} else {
- return @count($_SESSION[$this->_stack][$this->_listeners[strtolower($my_listener)]->getName()]);
+ return @count($this->_storage[$this->_listeners[strtolower($my_listener)]->getName()]);
}
}
diff --git a/framework/Notification/lib/Horde/Notification/Storage.php b/framework/Notification/lib/Horde/Notification/Storage.php
new file mode 100644
index 000000000..ca35e7a9b
--- /dev/null
+++ b/framework/Notification/lib/Horde/Notification/Storage.php
@@ -0,0 +1,39 @@
+
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link http://pear.horde.org/index.php?package=Notification
+ */
+
+/**
+ * An interface describing a storage location for notification messages.
+ *
+ * Copyright 2009 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.
+ *
+ * @category Horde
+ * @package Notification
+ * @author Gunnar Wrobel