Add objects storage for notifications, that simply keeps the notifications in
authorJan Schneider <jan@horde.org>
Thu, 6 May 2010 10:21:18 +0000 (12:21 +0200)
committerJan Schneider <jan@horde.org>
Thu, 6 May 2010 15:51:09 +0000 (17:51 +0200)
the current storage instance.
Helpful for testing and any cases where we are sure that the notifications
will be returned in the same request, so that we can close the session to
allow more concurrent requests (keyword ajax).

framework/Notification/lib/Horde/Notification/Storage/Object.php [new file with mode: 0644]
framework/Notification/lib/Horde/Notification/Storage/Session.php
framework/Notification/package.xml

diff --git a/framework/Notification/lib/Horde/Notification/Storage/Object.php b/framework/Notification/lib/Horde/Notification/Storage/Object.php
new file mode 100644 (file)
index 0000000..3ac6d41
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/**
+ * A class that stores notifications in an object.
+ *
+ * @category Horde
+ * @package  Horde_Notification
+ * @author   Jan Schneider <jan@horde.org>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Notification
+ */
+
+/**
+ * A class that stores notifications in an object.
+ *
+ * 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.
+ *
+ * @category Horde
+ * @package  Notification
+ * @author   Jan Schneider <jan@horde.org>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Notification
+ */
+class Horde_Notification_Storage_Session
+implements Horde_Notification_Storage_Interface
+{
+    /**
+     * Holds the notifications pushed into this storage object.
+     *
+     * @var array
+     */
+    protected $_notifications = array();
+
+    /**
+     * Return the given stack by reference from the notification store.
+     *
+     * @param string $key  The key for the data.
+     *
+     * @return mixed  The notification data stored for the given key.
+     */
+    public function &get($key)
+    {
+        return $this->_notifications[$key];
+    }
+
+    /**
+     * Set the given stack in the notification store.
+     *
+     * @param string $key   The key for the data.
+     * @param mixed $value  The data.
+     */
+    public function set($key, $value)
+    {
+        $this->_notifications[$key] = $value;
+    }
+
+    /**
+     * Is the given stack present in the notification store?
+     *
+     * @param string $key  The key of the data.
+     *
+     * @return boolean  True if the element is set, false otherwise.
+     */
+    public function exists($key)
+    {
+        return isset($this->_notifications[$key]);
+    }
+
+    /**
+     * Unset the given stack in the notification store.
+     *
+     * @param string $key  The key of the data.
+     */
+    public function clear($key)
+    {
+        unset($this->_notifications[$key]);
+    }
+
+    /**
+     * Store a new event for the given listener stack.
+     *
+     * @param string $listener                    The event will be stored for
+     *                                            this listener.
+     * @param Notification_Event_Listener $event  The event to store.
+     */
+    public function push($listener, Notification_Event_Listener $event)
+    {
+        $this->_notifications[$listener][] = $event;
+    }
+
+}
index 4dcdadc..54c7341 100644 (file)
@@ -31,7 +31,7 @@ implements Horde_Notification_Storage_Interface
      *
      * @var string
      */
-    private $_stack;
+    protected $_stack;
 
     /**
      * Constructor.
@@ -100,7 +100,7 @@ implements Horde_Notification_Storage_Interface
      *                                            this listener.
      * @param Notification_Event_Listener $event  The event to store.
      */
-    public function push($listener, $event)
+    public function push($listener, Notification_Event_Listener $event)
     {
         /* No need to serialize() ourselves - PHP's session handling does
          * this automatically. */
index cf81867..e70dba1 100644 (file)
@@ -50,6 +50,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
       </dir> <!-- /lib/Horde/Notification/Listener -->
       <dir name="Storage">
        <file name="Interface.php" role="php" />
+       <file name="Object.php" role="php" />
        <file name="Session.php" role="php" />
       </dir> <!-- /lib/Horde/Notification/Storage -->
       <file name="Event.php" role="php" />
@@ -126,6 +127,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Notification/Listener/Javascript.php" as="Horde/Notification/Listener/Javascript.php" />
    <install name="lib/Horde/Notification/Listener/Status.php" as="Horde/Notification/Listener/Status.php" />
    <install name="lib/Horde/Notification/Storage/Interface.php" as="Horde/Notification/Storage/Interface.php" />
+   <install name="lib/Horde/Notification/Storage/Object.php" as="Horde/Notification/Storage/Object.php" />
    <install name="lib/Horde/Notification/Storage/Session.php" as="Horde/Notification/Storage/Session.php" />
    <install name="lib/Horde/Notification/Event.php" as="Horde/Notification/Event.php" />
    <install name="lib/Horde/Notification/Handler.php" as="Horde/Notification/Handler.php" />