|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Symnedi\EventDispatcher\Tests\NetteEvent\EventSubscriber; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
6
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationEvent; |
|
7
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationExceptionEvent; |
|
8
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationPresenterEvent; |
|
9
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationRequestEvent; |
|
10
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationResponseEvent; |
|
11
|
|
|
use Symnedi\EventDispatcher\NetteApplicationEvents; |
|
12
|
|
|
use Symnedi\EventDispatcher\Tests\NetteEvent\EventStateStorage; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
final class ApplicationSubscriber implements EventSubscriberInterface |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var EventStateStorage |
|
20
|
|
|
*/ |
|
21
|
|
|
private $eventStateStorage; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
public function __construct(EventStateStorage $eventStateStorage) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->eventStateStorage = $eventStateStorage; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function getSubscribedEvents() |
|
34
|
|
|
{ |
|
35
|
|
|
return [ |
|
36
|
|
|
NetteApplicationEvents::ON_REQUEST => 'onRequest', |
|
37
|
|
|
NetteApplicationEvents::ON_STARTUP => 'onStartup', |
|
38
|
|
|
NetteApplicationEvents::ON_PRESENTER => 'onPresenter', |
|
39
|
|
|
NetteApplicationEvents::ON_SHUTDOWN => 'onShutdown', |
|
40
|
|
|
NetteApplicationEvents::ON_RESPONSE => 'onResponse', |
|
41
|
|
|
NetteApplicationEvents::ON_ERROR => 'onError' |
|
42
|
|
|
]; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
public function onRequest(ApplicationRequestEvent $applicationRequestEvent) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->eventStateStorage->addEventState(NetteApplicationEvents::ON_REQUEST, $applicationRequestEvent); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
public function onStartup(ApplicationEvent $applicationEvent) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->eventStateStorage->addEventState(NetteApplicationEvents::ON_STARTUP, $applicationEvent); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
public function onPresenter(ApplicationPresenterEvent $applicationPresenterEvent) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->eventStateStorage->addEventState(NetteApplicationEvents::ON_PRESENTER, $applicationPresenterEvent); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
public function onShutdown(ApplicationExceptionEvent $applicationExceptionEvent) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->eventStateStorage->addEventState(NetteApplicationEvents::ON_SHUTDOWN, $applicationExceptionEvent); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
public function onError(ApplicationExceptionEvent $applicationExceptionEvent) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->eventStateStorage->addEventState(NetteApplicationEvents::ON_ERROR, $applicationExceptionEvent); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
public function onResponse(ApplicationResponseEvent $applicationResponseEvent) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->eventStateStorage->addEventState(NetteApplicationEvents::ON_RESPONSE, $applicationResponseEvent); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|