PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / prefixed / symfony / http-kernel / Debug / TraceableEventDispatcher.php
matomo / app / vendor / prefixed / symfony / http-kernel / Debug Last commit date
FileLinkFormatter.php 1 year ago TraceableEventDispatcher.php 1 year ago
TraceableEventDispatcher.php
89 lines
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 namespace Matomo\Dependencies\Symfony\Component\HttpKernel\Debug;
12
13 use Matomo\Dependencies\Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher as BaseTraceableEventDispatcher;
14 use Matomo\Dependencies\Symfony\Component\HttpKernel\KernelEvents;
15 /**
16 * Collects some data about event listeners.
17 *
18 * This event dispatcher delegates the dispatching to another one.
19 *
20 * @author Fabien Potencier <fabien@symfony.com>
21 */
22 class TraceableEventDispatcher extends BaseTraceableEventDispatcher
23 {
24 /**
25 * {@inheritdoc}
26 */
27 protected function beforeDispatch(string $eventName, object $event)
28 {
29 switch ($eventName) {
30 case KernelEvents::REQUEST:
31 $event->getRequest()->attributes->set('_stopwatch_token', substr(hash('sha256', uniqid(mt_rand(), \true)), 0, 6));
32 $this->stopwatch->openSection();
33 break;
34 case KernelEvents::VIEW:
35 case KernelEvents::RESPONSE:
36 // stop only if a controller has been executed
37 if ($this->stopwatch->isStarted('controller')) {
38 $this->stopwatch->stop('controller');
39 }
40 break;
41 case KernelEvents::TERMINATE:
42 $sectionId = $event->getRequest()->attributes->get('_stopwatch_token');
43 if (null === $sectionId) {
44 break;
45 }
46 // There is a very special case when using built-in AppCache class as kernel wrapper, in the case
47 // of an ESI request leading to a `stale` response [B] inside a `fresh` cached response [A].
48 // In this case, `$token` contains the [B] debug token, but the open `stopwatch` section ID
49 // is equal to the [A] debug token. Trying to reopen section with the [B] token throws an exception
50 // which must be caught.
51 try {
52 $this->stopwatch->openSection($sectionId);
53 } catch (\LogicException $e) {
54 }
55 break;
56 }
57 }
58 /**
59 * {@inheritdoc}
60 */
61 protected function afterDispatch(string $eventName, object $event)
62 {
63 switch ($eventName) {
64 case KernelEvents::CONTROLLER_ARGUMENTS:
65 $this->stopwatch->start('controller', 'section');
66 break;
67 case KernelEvents::RESPONSE:
68 $sectionId = $event->getRequest()->attributes->get('_stopwatch_token');
69 if (null === $sectionId) {
70 break;
71 }
72 $this->stopwatch->stopSection($sectionId);
73 break;
74 case KernelEvents::TERMINATE:
75 // In the special case described in the `preDispatch` method above, the `$token` section
76 // does not exist, then closing it throws an exception which must be caught.
77 $sectionId = $event->getRequest()->attributes->get('_stopwatch_token');
78 if (null === $sectionId) {
79 break;
80 }
81 try {
82 $this->stopwatch->stopSection($sectionId);
83 } catch (\LogicException $e) {
84 }
85 break;
86 }
87 }
88 }
89