Do not use ArrayAccess so that we can fetch message stacks by reference.
authorGunnar Wrobel <p@rdus.de>
Thu, 5 Nov 2009 05:53:46 +0000 (06:53 +0100)
committerGunnar Wrobel <p@rdus.de>
Thu, 5 Nov 2009 05:53:46 +0000 (06:53 +0100)
framework/Notification/lib/Horde/Notification/Handler/Base.php
framework/Notification/lib/Horde/Notification/Storage/Interface.php
framework/Notification/lib/Horde/Notification/Storage/Session.php

index 0753e89..83e7ed6 100644 (file)
@@ -81,8 +81,8 @@ implements Horde_Notification_Handler_Interface
 
         if (class_exists($class)) {
             $this->_listeners[$listener] = new $class($params);
-            if (!isset($this->_storage[$listener])) {
-                $this->_storage[$listener] = array();
+            if (!$this->_storage->exists($listener)) {
+                $this->_storage->set($listener, array());
             }
             return $this->_listeners[$listener];
         }
@@ -105,8 +105,9 @@ implements Horde_Notification_Handler_Interface
             throw new Horde_Exception(sprintf('Notification listener %s not found.', $listener));
         }
 
-        $list = $this->_listeners[$listener];
-        unset($this->_listeners[$listener], $this->_storage[$list->getName()]);
+        $listener_instance = $this->_listeners[$listener];
+        unset($this->_listeners[$listener]);
+        $this->_storage->clear($listener_instance->getName());
     }
 
     /**
@@ -218,9 +219,8 @@ implements Horde_Notification_Handler_Interface
     {
         foreach ($options['listeners'] as $listener) {
             if (isset($this->_listeners[$listener])) {
-                $stack = $this->_storage[$this->_listeners[$listener]->getName()];
+                $stack = $this->_storage->get($this->_listeners[$listener]->getName());
                 $this->_listeners[$listener]->notify($stack, $options);
-                $this->_storage[$this->_listeners[$listener]->getName()] = $stack;
             }
         }
     }
@@ -239,13 +239,13 @@ implements Horde_Notification_Handler_Interface
         if (is_null($my_listener)) {
             $count = 0;
             foreach ($this->_listeners as $listener) {
-                if (isset($this->_storage[$listener->getName()])) {
-                    $count += count($this->_storage[$listener->getName()]);
+                if ($this->_storage->exists($listener->getName())) {
+                    $count += count($this->_storage->get($listener->getName()));
                 }
             }
             return $count;
         } else {
-            return @count($this->_storage[$this->_listeners[Horde_String::lower($my_listener)]->getName()]);
+            return @count($this->_storage->get($this->_listeners[Horde_String::lower($my_listener)]->getName()));
         }
     }
 
index f6382d6..5c58939 100644 (file)
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Notification
  */
-interface Horde_Notification_Storage_Interface extends ArrayAccess
+interface Horde_Notification_Storage_Interface
 {
     /**
+     * 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);
+
+    /**
+     * Set the given stack in the notification store.
+     *
+     * @param string $key   The key for the data.
+     * @param mixed  $value The data.
+     *
+     * @return NULL
+     */
+    public function set($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);
+
+    /**
+     * Unset the given stack in the notification store.
+     *
+     * @param string $key The key of the data.
+     *
+     * @return NULL
+     */
+    public function clear($key);
+
+    /**
      * Store a new event.
      *
      * @param string $listener The event will be stored for this listener.
index 45c52b7..0959437 100644 (file)
@@ -51,56 +51,56 @@ implements Horde_Notification_Storage_Interface
     }
 
     /**
-     * Return the given value from the notification store.
+     * 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 offsetGet($key)
+    public function &get($key)
     {
         return $_SESSION[$this->_stack][$key];
     }
 
     /**
-     * Set the given value in the notification store.
+     * Set the given stack in the notification store.
      *
      * @param string $key   The key for the data.
      * @param mixed  $value The data.
      *
      * @return NULL
      */
-    public function offsetSet($key, $value)
+    public function set($key, $value)
     {
         $_SESSION[$this->_stack][$key] = $value;
     }
 
     /**
-     * Is the given key set in the notification store?
+     * 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 offsetExists($key)
+    public function exists($key)
     {
         return isset($_SESSION[$this->_stack][$key]);
     }
 
     /**
-     * Unset the given key set in the notification store.
+     * Unset the given stack in the notification store.
      *
      * @param string $key The key of the data.
      *
      * @return NULL
      */
-    public function offsetUnset($key)
+    public function clear($key)
     {
         unset($_SESSION[$this->_stack][$key]);
     }
 
     /**
-     * Store a new event for the given listener name.
+     * Store a new event for the given listener stack.
      *
      * @param string $listener The event will be stored for this listener.
      * @param array  $event    The event to store.