From a06e46506f19765aed445e68cc63179f4f7a51f4 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 21 Oct 2009 13:37:37 -0600 Subject: [PATCH] Added Horde_Notification::replace() --- framework/Notification/lib/Horde/Notification.php | 50 ++++++++++++++++------- framework/Notification/package.xml | 3 +- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/framework/Notification/lib/Horde/Notification.php b/framework/Notification/lib/Horde/Notification.php index ae2efafe1..0ff9e2b4e 100644 --- a/framework/Notification/lib/Horde/Notification.php +++ b/framework/Notification/lib/Horde/Notification.php @@ -87,20 +87,20 @@ class Horde_Notification * Registers a listener with the notification object and includes * the necessary library file dynamically. * - * @param string $listener The name of the listener to attach. These names - * must be unique; further listeners with the same - * name will be ignored. - * @param array $params A hash containing any additional configuration or - * connection parameters a listener driver might - * need. - * @param string $class The class name from which the driver was - * instantiated if not the default one. If given - * you have to include the library file containing - * this class yourself. This is useful if you want - * the listener driver to be overriden by an - * application's implementation. - * - * @return TODO + * @param string $listener The name of the listener to attach. These + * names must be unique; further listeners with + * the same name will be ignored. + * @param array $params A hash containing any additional configuration + * or connection parameters a listener driver + * might need. + * @param string $class The class name from which the driver was + * instantiated if not the default one. If given + * you have to include the library file + * containing this class yourself. This is useful + * if you want the listener driver to be + * overriden by an application's implementation. + * + * @return Horde_Notification_Listener The listener object. * @throws Horde_Exception */ public function attach($listener, $params = array(), $class = null) @@ -126,7 +126,8 @@ class Horde_Notification } /** - * Remove a listener from the notification list. + * Remove a listener from the notification list. This will discard any + * notifications in this listeners stack. * * @param string $listner The name of the listener to detach. * @@ -144,6 +145,25 @@ class Horde_Notification } /** + * Replaces a listener in the notification list. This preserves all + * notifications in this listeners stack. If the listener does not exist, + * the new listener will be added automatically. + * + * @param string $listener See attach(). + * @param array $params See attach(). + * @param string $class See attach(). + * + * @return Horde_Notification_Listener See attach() + * @throws Horde_Exception + */ + public function replace($listener, $params = array(), $class = null) + { + $listener = strtolower(basename($listener)); + unset($this->_listeners[$listener]); + return $this->attach($listener, $params, $class); + } + + /** * Add an event to the Horde message stack. * * The event type parameter should begin with 'horde.' unless the diff --git a/framework/Notification/package.xml b/framework/Notification/package.xml index 7e9edf512..6ed82799a 100644 --- a/framework/Notification/package.xml +++ b/framework/Notification/package.xml @@ -24,7 +24,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Initial Horde 4 package. + * Added Horde_Notification::replace(). + * Initial Horde 4 package. -- 2.11.0