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];
}
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());
}
/**
{
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;
}
}
}
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()));
}
}
* @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.
}
/**
- * 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.