steffen: server/kolab-horde-framework/kolab-horde-framework/Notification Notification.php, NONE, 1.1 package.xml, NONE, 1.1
cvs at intevation.de
cvs at intevation.de
Fri Oct 14 16:33:11 CEST 2005
- Previous message: steffen: server/kolab-horde-framework/kolab-horde-framework/Net_SMS/SMS clickatell_http.php, NONE, 1.1 sms2email_http.php, NONE, 1.1 vodafoneitaly_smtp.php, NONE, 1.1
- Next message: steffen: server/kolab-horde-framework/kolab-horde-framework/Notification/Notification Event.php, NONE, 1.1 Listener.php, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Author: steffen
Update of /kolabrepository/server/kolab-horde-framework/kolab-horde-framework/Notification
In directory doto:/tmp/cvs-serv28903/kolab-horde-framework/kolab-horde-framework/Notification
Added Files:
Notification.php package.xml
Log Message:
Separated Horde Framework from kolab-resource-handlers
--- NEW FILE: Notification.php ---
<?php
/**
* The Notification:: class provides a subject-observer pattern for
* raising and showing messages of different types and to different
* listeners.
*
* $Horde: framework/Notification/Notification.php,v 1.41 2004/03/09 07:38:31 jon Exp $
*
* Copyright 2001-2004 Jan Schneider <jan at horde.org>
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Jan Schneider <jan at horde.org>
* @version $Revision: 1.1 $
* @since Horde 2.1
* @package Horde_Notification
*/
class Notification {
/**
* Hash containing all attached listener objects.
*
* @var array $_listeners
*/
var $_listeners = array();
/**
* Returns a reference to the global Notification object, only
* creating it if it doesn't already exist.
*
* This method must be invoked as:
* $notification = &Notification::singleton()
*
* @return object Notification The Horde Notification instance.
*/
function &singleton()
{
static $notification;
if (!isset($notification)) {
$notification = new Notification();
}
return $notification;
}
/**
* Initialize the notification system, set up any needed session
* variables, etc. Should never be called except by
* &Notification::singleton();
*
* @access private
*/
function Notification()
{
/* Make sure the message stack is registered in the session,
* and obtain a global-scope reference to it. */
if (!isset($_SESSION['hordeMessageStacks'])) {
$_SESSION['hordeMessageStacks'] = array();
}
}
/**
* Registers a listener with the notification object and includes
* the necessary library file dynamically.
*
* @param string $driver The name of the listener to attach.
* These names must be unique; further
* listeners with the same name will be
* ignored.
* @param optional array $params A hash containing any additional
* configuration or connection parameters
* a listener driver might need.
* @param optional 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.
*/
function &attach($listener, $params = array(), $class = null)
{
$listener = basename($listener);
if (!empty($this->_listeners[$listener])) {
return false;
}
if (is_null($class)) {
require_once dirname(__FILE__) . '/Notification/Listener/' . $listener . '.php';
$class = 'Notification_Listener_' . $listener;
}
if (class_exists($class)) {
$this->_listeners[$listener] = &new $class($params);
if (!isset($_SESSION['hordeMessageStacks'][$listener])) {
$_SESSION['hordeMessageStacks'][$listener] = array();
}
return $this->_listeners[$listener];
} else {
Horde::fatal(PEAR::raiseError(sprintf('Notification listener %s not found.', $listener)), __FILE__, __LINE__);
}
}
/**
* Remove a listener from the notification list.
*
* @access public
*
* @param string $listner The name of the listener to detach.
*/
function detach($listener)
{
$listener = basename($listener);
if (!isset($this->_listeners[$listener])) {
return PEAR::raiseError(sprintf('Notification listener %s not found.', $listener));
}
$list = $this->_listeners[$listener];
unset($this->_listeners[$listener]);
unset($_SESSION['hordeMessageStacks'][$list->getName()]);
return true;
}
/**
* Add an event to the Horde message stack.
*
* The event type parameter should begin with 'horde.' unless the
* application defines its own Notification_Listener subclass that
* handles additional codes.
*
* @access public
*
* @param mixed $event Notification_Event object or message string.
* @param optional integer $type The type of message: 'horde.error',
* 'horde.warning', 'horde.success', or
* 'horde.message'.
* @param optional array $flags Array of optional flags that will be
* passed to the registered listeners.
*/
function push($event, $type = 'horde.message', $flags = array())
{
if (!is_a($event, 'Notification_Event') &&
!is_a($event, 'PEAR_Error')) {
/* Transparently create a Notification_Event object and
* set the message attribute. */
require_once dirname(__FILE__) . '/Notification/Event.php';
$event = &new Notification_Event($event);
}
if (is_a($event, 'PEAR_Error')) {
Horde::logMessage($event, __FILE__, __LINE__, PEAR_LOG_DEBUG);
}
foreach ($this->_listeners as $listener) {
if ($listener->handles($type)) {
$_SESSION['hordeMessageStacks'][$listener->getName()][] =
array('type' => $type,
'class' => get_class($event),
'event' => serialize($event),
'flags' => serialize($flags));
}
}
}
/**
* Passes the message stack to all listeners and asks them to
* handle their messages.
*
* @access public
*
* @param optional array $options An array containing display options
* for the listeners.
*/
function notify($options = array())
{
if (!isset($options['listeners'])) {
$options['listeners'] = array_keys($this->_listeners);
} elseif (!is_array($options['listeners'])) {
$options['listeners'] = array($options['listeners']);
}
foreach ($options['listeners'] as $listener) {
$this->_listeners[$listener]->notify($_SESSION['hordeMessageStacks'][$this->_listeners[$listener]->getName()], $options);
}
}
/**
* Return the number of notification messages in the stack.
*
* @author David Ulevitch <davidu at everydns.net>
*
* @access public
*
* @param optional string $my_listener The name of the listener.
*
* @return integer The number of messages in the stack.
*
* @since Horde 2.2
*/
function count($my_listener = null)
{
if (is_null($my_listener)) {
$count = 0;
foreach ($this->_listeners as $listener) {
if (isset($_SESSION['hordeMessageStacks'][$listener->getName()])) {
$count += count($_SESSION['hordeMessageStacks'][$listener->getName()]);
}
}
return $count;
} else {
return @count($_SESSION['hordeMessageStacks'][$this->_listeners[$my_listener]->getName()]);
}
}
}
--- NEW FILE: package.xml ---
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- $Horde: framework/Notification/package.xml,v 1.8 2004/01/18 15:10:08 jan Exp $ -->
<!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.1">
<package version="1.0">
<name>Horde_Notification</name>
<summary>Horde Notification System</summary>
<description>
The Notification:: class provides a subject-observer pattern for raising and showing messages of different types and to different listeners.
</description>
<license>LGPL</license>
<maintainers>
<maintainer>
<user>yunosh</user>
<role>lead</role>
<name>Jan Schneider</name>
<email>jan at horde.org</email>
</maintainer>
</maintainers>
<release>
<version>0.0.1</version>
<state>alpha</state>
<date>2003-07-05</date>
<notes>Initial packaging.</notes>
<filelist>
<file role="php" baseinstalldir="/Horde" name="Notification.php" />
<dir role="php" baseinstalldir="/Horde" name="Notification">
<file name="Event.php" />
<file name="Listener.php" />
<dir role="php" baseinstalldir="/Horde" name="Listener">
<file name="javascript.php" />
<file name="mobile.php" />
<file name="status.php" />
</dir>
</dir>
</filelist>
<provides type="class" name="Notification" />
<provides type="class" name="Notification_Event" />
<provides type="class" name="Notification_Listener" />
<provides type="class" name="Notification_Listener_javascript" />
<provides type="class" name="Notification_Listener_mobile" />
<provides type="class" name="Notification_Listener_status" />
<deps>
<dep type="ext" rel="has">gettext</dep>
<dep type="pkg" rel="has">Horde_Framework</dep>
</deps>
</release>
<changelog>
<release>
<version>0.0.1</version>
<state>alpha</state>
<date>2003-07-05</date>
<notes>Initial release as a PEAR package</notes>
</release>
</changelog>
</package>
- Previous message: steffen: server/kolab-horde-framework/kolab-horde-framework/Net_SMS/SMS clickatell_http.php, NONE, 1.1 sms2email_http.php, NONE, 1.1 vodafoneitaly_smtp.php, NONE, 1.1
- Next message: steffen: server/kolab-horde-framework/kolab-horde-framework/Notification/Notification Event.php, NONE, 1.1 Listener.php, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the commits
mailing list