static protected $_instances = array();
/**
- * Returns a reference to the global Notification handler, only
+ * Returns a reference to the global notification handler, only
* creating it if it doesn't already exist.
*
* This method must be invoked as:
- * $notification = Horde_Notification::singleton()
+ * $notification = Horde_Notification::singleton([$stack]);
*
* @param string $stack The name of the message stack to use.
*
- * return Horde_Notification_Handler The Horde Notification handler.
+ * return Horde_Notification_Handler The Horde Notification handler.
*/
static public function singleton($stack = 'horde_notification_stacks')
{
return self::$_instances[$stack];
}
+
}
<?php
/**
- * The Horde_Notification_Event:: class provides a container for passing
- * messages to Horde_Notification_Listener classes.
+ * The Horde_Notification_Event:: class defines a single notification event.
*
* Copyright 2002-2010 The Horde Project (http://www.horde.org/)
*
protected $_alarm;
/**
- * Initialize the notification system, set up any needed session
- * variables, etc.
+ * Initialize the notification system.
*
- * @param Horde_Notification_Storage $storage The storage location to use.
+ * @param Horde_Notification_Storage $storage The storage location to
+ * use.
*/
- public function __construct(
- Horde_Notification_Storage_Interface $storage
- ) {
+ public function __construct(Horde_Notification_Storage_Interface $storage)
+ {
$this->_storage = $storage;
}
throw new Horde_Exception(sprintf('Notification listener %s not found.', $listener));
}
- $listener_instance = $this->_listeners[$listener];
+ $instance = $this->_listeners[$listener];
unset($this->_listeners[$listener]);
- $this->_storage->clear($listener_instance->getName());
+ $this->_storage->clear($instance->getName());
}
/**
*
* @param array $options An array containing display options for the
* listeners.
+ * <pre>
+ * 'listeners' - The list of listeners to notify.
+ * </pre>
*/
public function notify(array $options = array())
{
*
* @param array $options An array containing display options for the
* listeners.
+ *
+ * @return array The list of listeners to notify.
*/
public function setNotificationListeners(array $options)
{
if (!isset($options['listeners'])) {
- $options['listeners'] = $this->getListeners();
+ $options['listeners'] = array_keys($this->_listeners);
} elseif (!is_array($options['listeners'])) {
$options['listeners'] = array($options['listeners']);
}
$options['listeners'] = array_map(array('Horde_String', 'lower'), $options['listeners']);
+
return $options;
}
/**
- * Passes the message stack to all listeners and asks them to
- * handle their messages.
+ * Passes the message stack to all listeners and asks them to handle
+ * their messages.
*
* @param array $options An array containing display options for the
* listeners. This array is required to contain the
{
foreach ($options['listeners'] as $listener) {
if (isset($this->_listeners[$listener])) {
- $this->_listeners[$listener]->notify(
- $this->_storage->get(
- $this->_listeners[$listener]->getName()
- ),
- $options
- );
+ $this->_listeners[$listener]->notify($this->_storage->get($this->_listeners[$listener]->getName()), $options);
}
}
}
}
}
return $count;
- } else {
- return @count($this->_storage->get($this->_listeners[Horde_String::lower($my_listener)]->getName()));
}
- }
- protected function getListeners()
- {
- return array_keys($this->_listeners);
+ return @count($this->_storage->get($this->_listeners[Horde_String::lower($my_listener)]->getName()));
}
+
}
* Initialize the notification system, set up any needed session
* variables, etc.
*
- * @param Horde_Notification_Handler $handler The handler this instance
- * provides with logging.
- * @param Horde_Alarm $alarm The alarm system to notify.
+ * @param Horde_Notification_Handler $handler The handler this instance
+ * provides with logging.
+ * @param Horde_Alarm $alarm The alarm system to notify.
*/
- public function __construct(
- Horde_Notification_Handler_Interface $handler,
- Horde_Alarm $alarm
- ) {
+ public function __construct(Horde_Notification_Handler_Interface $handler,
+ Horde_Alarm $alarm)
+ {
$this->_handler = $handler;
$this->_alarm = $alarm;
}
* @param Horde_Notification_Handler $handler The handler this instance
* provides with logging.
*/
- public function __construct(
- Horde_Notification_Handler_Interface $handler
- ) {
+ public function __construct(Horde_Notification_Handler_Interface $handler)
+ {
$this->_handler = $handler;
}
* Initialize the notification system, set up any needed session
* variables, etc.
*
- * @param Horde_Notification_Handler $handler The handler this instance
- * provides with logging.
- *
- * @param mixed $logger The log handler. The provided
- * instance is required to
- * implement the debug() function.
- * You should be able to use a
- * common Logger here (PEAR Log,
- * Horde_Log_Logger, or Zend_Log).
+ * @param Horde_Notification_Handler $handler The handler this instance
+ * provides with logging.
+ *
+ * @param mixed $logger The log handler. The
+ * provided instance is
+ * required to implement the
+ * debug() function. You
+ * should be able to use a
+ * common Logger here (PEAR
+ * Log, Horde_Log_Logger, or
+ * Zend_Log).
*/
- public function __construct(
- Horde_Notification_Handler_Interface $handler,
- $logger
- ) {
+ public function __construct(Horde_Notification_Handler_Interface $handler,
+ $logger)
+ {
$this->_handler = $handler;
$this->_logger = $logger;
}
public function push($event, $type = null, array $flags = array())
{
if ($event instanceof PEAR_Error || $event instanceof Exception) {
- /**
- * Some loggers only accept string messages. As both PEAR_Error and
- * Exception accept being casted into a string we can ensure that
- * the logger receives a string here.
- */
+ /* Some loggers only accept string messages. As both PEAR_Error
+ * and Exception accept being casted into a string we can ensure
+ * that the logger receives a string here. */
$this->_logger->debug((string) $event);
}
$this->_handler->push($event, $type, $flags);
{
return $this->_handler->count($my_listener);
}
+
}
* @return integer The number of messages in the stack.
*/
public function count($my_listener = null);
+
}
*/
public function __construct()
{
- $this->_handles = array('audio' => '');
+ $this->_handles = array(
+ 'audio' => ''
+ );
$this->_name = 'audio';
}
* 'audio' message stack.
*
* @param array &$messageStack The stack of messages.
- * @param array $options An array of options.
+ * @param array $options An array of options (not used).
*/
public function notify(&$messageStack, $options = array())
{
*
* @param Horde_Mobile The Horde_Mobile:: object to send status lines to.
*/
- public function setMobileObject(&$mobile)
+ public function setMobileObject($mobile)
{
- $this->_mobile = &$mobile;
+ $this->_mobile = $mobile;
}
/**
* message stack.
*
* @param array &$messageStack The stack of messages.
- * @param array $options An array of options. Options: 'nospace'
+ * @param array $options An array of options.
*/
public function notify(&$messageStack, $options = array())
{
/**
* An interface describing a storage location for notification messages.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
/**
* Return the given stack by reference from the notification store.
*
- * @param string $key The key for the data.
+ * @param string $key The key for the data.
*
- * @return mixed The notification data stored for the given key.
+ * @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
+ * @param mixed $value The data.
*/
public function set($key, $value);
/**
* Is the given stack present in the notification store?
*
- * @param string $key The key of the data.
+ * @param string $key The key of the data.
*
- * @return boolean True if the element is set, false otherwise.
+ * @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
+ * @param string $key The key of the data.
*/
public function clear($key);
/**
* A class that stores notifications in the session.
*
- * PHP version 5
- *
* @category Horde
* @package Horde_Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
/**
* Constructor.
*
- * @param string $stack The name of the notification stack.
+ * @param string $stack The name of the notification stack.
*/
public function __construct($stack)
{
/**
* Return the given stack by reference from the notification store.
*
- * @param string $key The key for the data.
+ * @param string $key The key for the data.
*
- * @return mixed The notification data stored for the given key.
+ * @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
+ * @param mixed $value The data.
*/
public function set($key, $value)
{
/**
* Is the given stack present in the notification store?
*
- * @param string $key The key of the data.
+ * @param string $key The key of the data.
*
- * @return boolean True if the element is set, false otherwise.
+ * @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
+ * @param string $key The key of the data.
*/
public function clear($key)
{
/**
* All tests for the Horde_Notification package.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
/**
* Setup autoloading for the tests.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
if (!spl_autoload_functions()) {
spl_autoload_register(
create_function(
- '$class',
+ '$class',
'$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);'
. '$err_mask = E_ALL ^ E_WARNING;'
. '$oldErrorReporting = error_reporting($err_mask);'
/**
* Test the basic event class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
/**
* Test the basic notification handler class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
public function getMessage($message, $options = array())
{
}
-}
\ No newline at end of file
+}
/**
* Test the alarm notification handler class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
$this->assertEquals(1, $this->alarm_handler->count('listener'));
}
-}
\ No newline at end of file
+}
/**
* Test the notification handler class that logs to the horde log.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
$this->assertEquals(1, $this->logged_handler->count('listener'));
}
-}
\ No newline at end of file
+}
/**
* Test the logging notification handler class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
$this->assertEquals(1, $this->logged_handler->count('listener'));
}
-}
\ No newline at end of file
+}
/**
* Test the audio listener class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
/**
* Test the javascript listener class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
/**
* Test the mobile listener class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
/**
* Test the status listener class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
/**
* Test the basic listener class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
/**
* Test the notification class.
*
- * PHP version 5
- *
* @category Horde
* @package Notification
* @author Gunnar Wrobel <wrobel@pardus.de>
$this->markTestSkipped('The Horde_Alarm package is not installed!');
}
- global $conf;
- $conf['alarms']['driver'] = 'Mock';
+ $GLOBALS['conf']['alarms']['driver'] = 'Mock';
$this->assertType(
'Horde_Notification_Handler_Decorator_Alarm',
static public function newInstance($stack)
{
$storage = new Horde_Notification_Storage_Session($stack);
- $instance = new Horde_Notification_Handler_Base($storage);
- return $instance;
+ return new Horde_Notification_Handler_Base($storage);
}
}