| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\HttpKernel\DataCollector;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
|
|
|
15 |
use Symfony\Component\HttpFoundation\Request;
|
|
|
16 |
use Symfony\Component\HttpFoundation\RequestStack;
|
|
|
17 |
use Symfony\Component\HttpFoundation\Response;
|
|
|
18 |
use Symfony\Component\VarDumper\Cloner\Data;
|
|
|
19 |
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
|
|
20 |
use Symfony\Contracts\Service\ResetInterface;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
24 |
*
|
|
|
25 |
* @see TraceableEventDispatcher
|
|
|
26 |
*
|
|
|
27 |
* @final
|
|
|
28 |
*/
|
|
|
29 |
class EventDataCollector extends DataCollector implements LateDataCollectorInterface
|
|
|
30 |
{
|
|
|
31 |
private ?EventDispatcherInterface $dispatcher;
|
|
|
32 |
private ?RequestStack $requestStack;
|
|
|
33 |
private ?Request $currentRequest = null;
|
|
|
34 |
|
|
|
35 |
public function __construct(EventDispatcherInterface $dispatcher = null, RequestStack $requestStack = null)
|
|
|
36 |
{
|
|
|
37 |
$this->dispatcher = $dispatcher;
|
|
|
38 |
$this->requestStack = $requestStack;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public function collect(Request $request, Response $response, \Throwable $exception = null)
|
|
|
42 |
{
|
|
|
43 |
$this->currentRequest = $this->requestStack && $this->requestStack->getMainRequest() !== $request ? $request : null;
|
|
|
44 |
$this->data = [
|
|
|
45 |
'called_listeners' => [],
|
|
|
46 |
'not_called_listeners' => [],
|
|
|
47 |
'orphaned_events' => [],
|
|
|
48 |
];
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public function reset()
|
|
|
52 |
{
|
|
|
53 |
$this->data = [];
|
|
|
54 |
|
|
|
55 |
if ($this->dispatcher instanceof ResetInterface) {
|
|
|
56 |
$this->dispatcher->reset();
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public function lateCollect()
|
|
|
61 |
{
|
|
|
62 |
if ($this->dispatcher instanceof TraceableEventDispatcher) {
|
|
|
63 |
$this->setCalledListeners($this->dispatcher->getCalledListeners($this->currentRequest));
|
|
|
64 |
$this->setNotCalledListeners($this->dispatcher->getNotCalledListeners($this->currentRequest));
|
|
|
65 |
$this->setOrphanedEvents($this->dispatcher->getOrphanedEvents($this->currentRequest));
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
$this->data = $this->cloneVar($this->data);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* @see TraceableEventDispatcher
|
|
|
73 |
*/
|
|
|
74 |
public function setCalledListeners(array $listeners)
|
|
|
75 |
{
|
|
|
76 |
$this->data['called_listeners'] = $listeners;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* @see TraceableEventDispatcher
|
|
|
81 |
*/
|
|
|
82 |
public function getCalledListeners(): array|Data
|
|
|
83 |
{
|
|
|
84 |
return $this->data['called_listeners'];
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* @see TraceableEventDispatcher
|
|
|
89 |
*/
|
|
|
90 |
public function setNotCalledListeners(array $listeners)
|
|
|
91 |
{
|
|
|
92 |
$this->data['not_called_listeners'] = $listeners;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* @see TraceableEventDispatcher
|
|
|
97 |
*/
|
|
|
98 |
public function getNotCalledListeners(): array|Data
|
|
|
99 |
{
|
|
|
100 |
return $this->data['not_called_listeners'];
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* @param array $events An array of orphaned events
|
|
|
105 |
*
|
|
|
106 |
* @see TraceableEventDispatcher
|
|
|
107 |
*/
|
|
|
108 |
public function setOrphanedEvents(array $events)
|
|
|
109 |
{
|
|
|
110 |
$this->data['orphaned_events'] = $events;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* @see TraceableEventDispatcher
|
|
|
115 |
*/
|
|
|
116 |
public function getOrphanedEvents(): array|Data
|
|
|
117 |
{
|
|
|
118 |
return $this->data['orphaned_events'];
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
public function getName(): string
|
|
|
122 |
{
|
|
|
123 |
return 'events';
|
|
|
124 |
}
|
|
|
125 |
}
|