From: Gunnar Wrobel
Date: Thu, 5 Nov 2009 05:53:46 +0000 (+0100) Subject: Do not use ArrayAccess so that we can fetch message stacks by reference. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7b16317d3ad5dcb91833481a7a025513b7e35254;p=horde.git Do not use ArrayAccess so that we can fetch message stacks by reference. --- diff --git a/framework/Notification/lib/Horde/Notification/Handler/Base.php b/framework/Notification/lib/Horde/Notification/Handler/Base.php index 0753e898f..83e7ed686 100644 --- a/framework/Notification/lib/Horde/Notification/Handler/Base.php +++ b/framework/Notification/lib/Horde/Notification/Handler/Base.php @@ -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())); } } diff --git a/framework/Notification/lib/Horde/Notification/Storage/Interface.php b/framework/Notification/lib/Horde/Notification/Storage/Interface.php index f6382d633..5c5893947 100644 --- a/framework/Notification/lib/Horde/Notification/Storage/Interface.php +++ b/framework/Notification/lib/Horde/Notification/Storage/Interface.php @@ -25,9 +25,46 @@ * @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. diff --git a/framework/Notification/lib/Horde/Notification/Storage/Session.php b/framework/Notification/lib/Horde/Notification/Storage/Session.php index 45c52b738..0959437c6 100644 --- a/framework/Notification/lib/Horde/Notification/Storage/Session.php +++ b/framework/Notification/lib/Horde/Notification/Storage/Session.php @@ -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.