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 cancel an event
4
 *
5
 * @package    Event_Dispatcher
6
 * @subpackage Examples
7
 * @author     Stephan Schmidt <schst@php.net>
8
 */
9
 
10
/**
11
 * load Event_Dispatcher package
12
 */
13
require_once 'Event/Dispatcher.php';
14
 
15
/**
16
 * example sender
17
 */
18
class sender
19
{
20
    var $_dispatcher = null;
21
 
22
    function sender(&$dispatcher)
23
    {
24
        $this->_dispatcher = &$dispatcher;
25
    }
26
 
27
    function foo()
28
    {
29
        $this->_dispatcher->post($this, 'onFoo', 'Some Info...');
30
    }
31
}
32
 
33
/**
34
 * example observer
35
 */
36
function receiver1(&$notification)
37
{
38
    echo "receiver 1 received notification<br />\n";
39
    // the notification will be cancelled and no other observers
40
    // will be notified
41
    $notification->cancelNotification();
42
}
43
 
44
/**
45
 * example observer
46
 */
47
function receiver2(&$notification)
48
{
49
    echo "receiver 2 received notification<br />\n";
50
}
51
 
52
 
53
$dispatcher = &Event_Dispatcher::getInstance();
54
$sender = &new sender($dispatcher);
55
 
56
$dispatcher->addObserver('receiver1', 'onFoo');
57
$dispatcher->addObserver('receiver2', 'onFoo');
58
 
59
$sender->foo();
60
?>