This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
TopicEventExample.php
76 lines (67 loc) · 2.14 KB
/
TopicEventExample.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
include __DIR__ . '/../vendor/autoload.php';
$adapter = new \Superbalist\PubSub\Adapters\LocalPubSubAdapter();
$translator = new \Superbalist\EventPubSub\Translators\TopicEventMessageTranslator();
$manager = new \Superbalist\EventPubSub\EventManager($adapter, $translator);
// listen for "*" event
$manager->listen('events', '*', function (\Superbalist\EventPubSub\EventInterface $event) {
echo "Listener '*' received new event on channel 'events':\n";
echo "\n";
var_dump($event);
echo "\n\n";
});
// listen for "user/created" event
$manager->listen('events', 'user/created', function (\Superbalist\EventPubSub\EventInterface $event) {
echo "Listener 'user/created' received new event on channel 'events':\n";
echo "\n";
var_dump($event);
echo "\n\n";
});
// listen for "user/*" event
$manager->listen('events', 'user/*', function (\Superbalist\EventPubSub\EventInterface $event) {
echo "Listener 'user/*' received new event on channel 'events':\n";
echo "\n";
var_dump($event);
echo "\n\n";
});
// listen for "user/created/1.0" event
$manager->listen('events', 'user/created/1.0', function (\Superbalist\EventPubSub\EventInterface $event) {
echo "Listener 'user/created/1.0' received new event on channel 'events':\n";
echo "\n";
var_dump($event);
echo "\n\n";
});
// listen for "order/created" event
$manager->listen('events', 'order/created', function (\Superbalist\EventPubSub\EventInterface $event) {
echo "Listener 'order/created' received new event on channel 'events':\n";
echo "\n";
var_dump($event);
echo "\n\n";
});
// publish an event
$event = new \Superbalist\EventPubSub\Events\TopicEvent(
'user',
'created',
'1.0',
[
'user' => [
'id' => 1456,
'first_name' => 'Joe',
'last_name' => 'Soap',
'email' => '[email protected]',
],
]
);
$manager->dispatch('events', $event);
// publish an event
$event = new \Superbalist\EventPubSub\Events\TopicEvent(
'order',
'created',
'2.1',
[
'order' => [
'id' => 1456,
],
]
);
$manager->dispatch('events', $event);