forked from PHPFluent/EventManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample-2.php
36 lines (27 loc) · 1.09 KB
/
sample-2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use PHPFluent\EventManager\Event;
use PHPFluent\EventManager\Manager;
$eventManager = new Manager();
// Use no argument
$eventManager->addEventListener('foo', function () {
echo 'Listener 1' . PHP_EOL;
});
// Use `Event` as first argument
$eventManager->addEventListener('foo', function (Event $event) {
echo 'Listener 2: ' . $event->getName() . PHP_EOL;
});
// Use `Event` as first argument and an array as seccond
$eventManager->addEventListener('foo', function (Event $event, array $params) {
echo 'Listener 3: ' . $event->getName() . ', ' . json_encode($params) . PHP_EOL;
});
// Use an array as first argument
$eventManager->addEventListener('foo', function (array $params) {
echo 'Listener 4: ' . json_encode($params) . PHP_EOL;
});
// Use an array as first argument and `Event` as seccond
$eventManager->addEventListener('foo', function (array $params, Event $event) {
echo 'Listener 3: ' . json_encode($params) . ', ' . $event->getName() . PHP_EOL;
});
// Dispatch event
$eventManager->dispatchEvent('foo', range(1, 10));