forked from gopeak/dectask
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_test.php
More file actions
90 lines (73 loc) · 1.85 KB
/
event_test.php
File metadata and controls
90 lines (73 loc) · 1.85 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
echo " ?\"ddd\"><><>\n";
echo htmlspecialchars(" ?\"ddd\"><><>");
die;
require './app/globals.php';
use Symfony\Contracts\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class Order
{
public $no = '';
public $status = '';
public function __construct($no, $status)
{
$this->no =$no;
$this->status = $status;
}
}
/**
* The order.placed event is dispatched each time an order is created
* in the system.
*/
class OrderPlacedEvent extends Event
{
const NAME = 'order.placed';
protected $order;
public function __construct(Order $order)
{
$this->order = $order;
}
public function getOrder()
{
return $this->order;
}
}
class StoreSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
'kernel.response'=> [
['onKernelResponsePre', 10],
['onKernelResponsePost', -10],
],
OrderPlacedEvent::NAME => 'onStoreOrder',
];
}
public function onKernelResponsePre(Event $event)
{
// ...
var_dump('onKernelResponsePre');
}
public function onKernelResponsePost(Event $event)
{
// ...
var_dump('onKernelResponsePost');
}
public function onStoreOrder(OrderPlacedEvent $event)
{
// ...
var_dump($event);
var_dump('onStoreOrder');
}
}
$dispatcher = new EventDispatcher();
// the order is somehow created or retrieved
// ...
$subscriber = new StoreSubscriber();
$dispatcher->addSubscriber($subscriber);
// creates the OrderPlacedEvent and dispatches it
$order = new Order(time(), mt_rand(1,10));
$event = new OrderPlacedEvent($order);
$dispatcher->dispatch($event, OrderPlacedEvent::NAME);