Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?PHP
2
/**
3
 * example that shows how to change the class used for notifications
4
 *
5
 * You may change the notification class per dispatcher or globally for all
6
 * newly created dispatchers.
7
 *
8
 * @package    Event_Dispatcher
9
 * @subpackage Examples
10
 * @author     Stephan Schmidt <schst@php.net>
11
 */
12
 
13
/**
14
 * load Event_Dispatcher package
15
 */
16
require_once 'Event/Dispatcher.php';
17
 
18
/**
19
 * example sender
20
 *
21
 * @package    Event_Dispatcher
22
 * @subpackage Examples
23
 * @author     Stephan Schmidt <schst@php.net>
24
 */
25
class sender
26
{
27
    var $_dispatcher = null;
28
 
29
    function sender(&$dispatcher)
30
    {
31
        $this->_dispatcher = &$dispatcher;
32
    }
33
 
34
    function foo()
35
    {
36
        $this->_dispatcher->post($this, 'onFoo', 'Some Info...');
37
    }
38
}
39
 
40
function receiver(&$notification)
41
{
42
    echo 'received notification: ';
43
    echo get_class($notification);
44
    echo '<br />';
45
}
46
 
47
/**
48
 * custom notification class
49
 *
50
 * @package    Event_Dispatcher
51
 * @subpackage Examples
52
 * @author     Stephan Schmidt <schst@php.net>
53
 */
54
class MyNotification extends Event_Notification
55
{
56
}
57
 
58
$dispatcher = &Event_Dispatcher::getInstance();
59
$dispatcher->setNotificationClass('MyNotification');
60
$sender = &new sender($dispatcher);
61
 
62
$dispatcher->addObserver('receiver');
63
 
64
echo 'sender->foo()<br />';
65
$sender->foo();
66
 
67
Event_Dispatcher::setNotificationClass('MyNotification');
68
 
69
$dispatcher2 = &Event_Dispatcher::getInstance();
70
$sender2 = &new sender($dispatcher2);
71
 
72
$dispatcher2->addObserver('receiver');
73
 
74
echo '<br />sender2->foo()<br />';
75
$sender2->foo();
76
?>