1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Webino (http://webino.sk/) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/webino/WebinoDebug/ for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk/) |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace WebinoDebug\Listener; |
11
|
|
|
|
12
|
|
|
use WebinoDebug\Service\EventProfiler; |
13
|
|
|
use Zend\EventManager\EventInterface; |
14
|
|
|
use Zend\EventManager\SharedEventManagerInterface; |
15
|
|
|
use Zend\EventManager\SharedListenerAggregateInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class EventProfilerListener |
19
|
|
|
*/ |
20
|
|
|
class EventProfilerListener implements SharedListenerAggregateInterface |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Event highest priority |
24
|
|
|
*/ |
25
|
|
|
const HIGHEST_PRIORITY = 9999999999; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var EventProfiler |
29
|
|
|
*/ |
30
|
|
|
protected $eventProfiler; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \Zend\Stdlib\CallbackHandler[] |
34
|
|
|
*/ |
35
|
|
|
protected $listeners = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param object|EventProfiler $eventProfiler |
39
|
|
|
*/ |
40
|
|
|
public function __construct(EventProfiler $eventProfiler) |
41
|
|
|
{ |
42
|
|
|
$this->eventProfiler = $eventProfiler; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function attachShared(SharedEventManagerInterface $events) |
49
|
|
|
{ |
50
|
|
|
$this->listeners[] = $events->attach('*', '*', [$this, 'onAnyEvent'], self::HIGHEST_PRIORITY); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function detachShared(SharedEventManagerInterface $events) |
57
|
|
|
{ |
58
|
|
|
foreach ($this->listeners as $key => $listener) { |
59
|
|
|
if ($events->detach('*', '*', $listener)) { |
|
|
|
|
60
|
|
|
unset($this->listeners[$key]); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param EventInterface $event |
67
|
|
|
*/ |
68
|
|
|
public function onAnyEvent(EventInterface $event) |
69
|
|
|
{ |
70
|
|
|
$this->eventProfiler->setEvent($event); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.