1: <?php
2: /**
3: * The Horde_Notification_Listener:: class provides functionality for
4: * displaying messages from the message stack as a status line.
5: *
6: * Copyright 2001-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10: *
11: * @author Chuck Hagenbuch <chuck@horde.org>
12: * @category Horde
13: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
14: * @package Notification
15: */
16: abstract class Horde_Notification_Listener
17: {
18: /**
19: * The base type of this listener.
20: *
21: * @var string
22: */
23: protected $_name;
24:
25: /**
26: * Array of message types that this listener handles.
27: * Key is the type, value is the default class name of the Event type to
28: * use.
29: *
30: * @var array
31: */
32: protected $_handles = array();
33:
34: /**
35: * Does this listener handle a certain type of message?
36: *
37: * @param string $type The message type in question.
38: *
39: * @return mixed False if this listener does not handle, the default
40: * event class if it does handle the type.
41: */
42: public function handles($type)
43: {
44: if (isset($this->_handles[$type])) {
45: return $this->_handles[$type];
46: }
47:
48: /* Search for '*' entries. */
49: foreach (array_keys($this->_handles) as $key) {
50: if ((substr($key, -1) == '*') &&
51: (strpos($type, substr($key, 0, -1)) === 0)) {
52: return $this->_handles[$key];
53: }
54: }
55:
56: return false;
57: }
58:
59: /**
60: * Adds message type handler.
61: *
62: * @param string $type The type identifier.
63: * @param string $class A classname.
64: */
65: public function addType($type, $class)
66: {
67: $this->_handles[$type] = $class;
68: }
69:
70: /**
71: * Return a unique identifier for this listener.
72: *
73: * @return string Unique id.
74: */
75: public function getName()
76: {
77: return $this->_name;
78: }
79:
80: /**
81: * Outputs the status line, sends emails, pages, etc., if there
82: * are any messages on this listener's message stack.
83: *
84: * @param array $events The list of events to handle.
85: * @param array $options An array of options.
86: */
87: abstract public function notify($events, $options = array());
88:
89: }
90: