Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../vendor/symfony/event-di.../Debug
File: TraceableEventDispatcher.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of the Symfony package.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier <fabien@symfony.com>
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
namespace Symfony\Component\EventDispatcher\Debug;
[11] Fix | Delete
[12] Fix | Delete
use Psr\Log\LoggerInterface;
[13] Fix | Delete
use Symfony\Component\EventDispatcher\Event;
[14] Fix | Delete
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
[15] Fix | Delete
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
[16] Fix | Delete
use Symfony\Component\Stopwatch\Stopwatch;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Collects some data about event listeners.
[20] Fix | Delete
*
[21] Fix | Delete
* This event dispatcher delegates the dispatching to another one.
[22] Fix | Delete
*
[23] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[24] Fix | Delete
*/
[25] Fix | Delete
class TraceableEventDispatcher implements TraceableEventDispatcherInterface
[26] Fix | Delete
{
[27] Fix | Delete
protected $logger;
[28] Fix | Delete
protected $stopwatch;
[29] Fix | Delete
[30] Fix | Delete
private $called;
[31] Fix | Delete
private $dispatcher;
[32] Fix | Delete
private $wrappedListeners;
[33] Fix | Delete
[34] Fix | Delete
public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null)
[35] Fix | Delete
{
[36] Fix | Delete
$this->dispatcher = $dispatcher;
[37] Fix | Delete
$this->stopwatch = $stopwatch;
[38] Fix | Delete
$this->logger = $logger;
[39] Fix | Delete
$this->called = array();
[40] Fix | Delete
$this->wrappedListeners = array();
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* {@inheritdoc}
[45] Fix | Delete
*/
[46] Fix | Delete
public function addListener($eventName, $listener, $priority = 0)
[47] Fix | Delete
{
[48] Fix | Delete
$this->dispatcher->addListener($eventName, $listener, $priority);
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* {@inheritdoc}
[53] Fix | Delete
*/
[54] Fix | Delete
public function addSubscriber(EventSubscriberInterface $subscriber)
[55] Fix | Delete
{
[56] Fix | Delete
$this->dispatcher->addSubscriber($subscriber);
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* {@inheritdoc}
[61] Fix | Delete
*/
[62] Fix | Delete
public function removeListener($eventName, $listener)
[63] Fix | Delete
{
[64] Fix | Delete
if (isset($this->wrappedListeners[$eventName])) {
[65] Fix | Delete
foreach ($this->wrappedListeners[$eventName] as $index => $wrappedListener) {
[66] Fix | Delete
if ($wrappedListener->getWrappedListener() === $listener) {
[67] Fix | Delete
$listener = $wrappedListener;
[68] Fix | Delete
unset($this->wrappedListeners[$eventName][$index]);
[69] Fix | Delete
break;
[70] Fix | Delete
}
[71] Fix | Delete
}
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
return $this->dispatcher->removeListener($eventName, $listener);
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* {@inheritdoc}
[79] Fix | Delete
*/
[80] Fix | Delete
public function removeSubscriber(EventSubscriberInterface $subscriber)
[81] Fix | Delete
{
[82] Fix | Delete
return $this->dispatcher->removeSubscriber($subscriber);
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* {@inheritdoc}
[87] Fix | Delete
*/
[88] Fix | Delete
public function getListeners($eventName = null)
[89] Fix | Delete
{
[90] Fix | Delete
return $this->dispatcher->getListeners($eventName);
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* {@inheritdoc}
[95] Fix | Delete
*/
[96] Fix | Delete
public function getListenerPriority($eventName, $listener)
[97] Fix | Delete
{
[98] Fix | Delete
if (!method_exists($this->dispatcher, 'getListenerPriority')) {
[99] Fix | Delete
return 0;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
return $this->dispatcher->getListenerPriority($eventName, $listener);
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* {@inheritdoc}
[107] Fix | Delete
*/
[108] Fix | Delete
public function hasListeners($eventName = null)
[109] Fix | Delete
{
[110] Fix | Delete
return $this->dispatcher->hasListeners($eventName);
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* {@inheritdoc}
[115] Fix | Delete
*/
[116] Fix | Delete
public function dispatch($eventName, Event $event = null)
[117] Fix | Delete
{
[118] Fix | Delete
if (null === $event) {
[119] Fix | Delete
$event = new Event();
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
if (null !== $this->logger && $event->isPropagationStopped()) {
[123] Fix | Delete
$this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
$this->preProcess($eventName);
[127] Fix | Delete
$this->preDispatch($eventName, $event);
[128] Fix | Delete
[129] Fix | Delete
$e = $this->stopwatch->start($eventName, 'section');
[130] Fix | Delete
[131] Fix | Delete
$this->dispatcher->dispatch($eventName, $event);
[132] Fix | Delete
[133] Fix | Delete
if ($e->isStarted()) {
[134] Fix | Delete
$e->stop();
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
$this->postDispatch($eventName, $event);
[138] Fix | Delete
$this->postProcess($eventName);
[139] Fix | Delete
[140] Fix | Delete
return $event;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* {@inheritdoc}
[145] Fix | Delete
*/
[146] Fix | Delete
public function getCalledListeners()
[147] Fix | Delete
{
[148] Fix | Delete
$called = array();
[149] Fix | Delete
foreach ($this->called as $eventName => $listeners) {
[150] Fix | Delete
foreach ($listeners as $listener) {
[151] Fix | Delete
$info = $this->getListenerInfo($listener->getWrappedListener(), $eventName);
[152] Fix | Delete
$called[$eventName.'.'.$info['pretty']] = $info;
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
return $called;
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* {@inheritdoc}
[161] Fix | Delete
*/
[162] Fix | Delete
public function getNotCalledListeners()
[163] Fix | Delete
{
[164] Fix | Delete
try {
[165] Fix | Delete
$allListeners = $this->getListeners();
[166] Fix | Delete
} catch (\Exception $e) {
[167] Fix | Delete
if (null !== $this->logger) {
[168] Fix | Delete
$this->logger->info('An exception was thrown while getting the uncalled listeners.', array('exception' => $e));
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
// unable to retrieve the uncalled listeners
[172] Fix | Delete
return array();
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
$notCalled = array();
[176] Fix | Delete
foreach ($allListeners as $eventName => $listeners) {
[177] Fix | Delete
foreach ($listeners as $listener) {
[178] Fix | Delete
$called = false;
[179] Fix | Delete
if (isset($this->called[$eventName])) {
[180] Fix | Delete
foreach ($this->called[$eventName] as $l) {
[181] Fix | Delete
if ($l->getWrappedListener() === $listener) {
[182] Fix | Delete
$called = true;
[183] Fix | Delete
[184] Fix | Delete
break;
[185] Fix | Delete
}
[186] Fix | Delete
}
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
if (!$called) {
[190] Fix | Delete
$info = $this->getListenerInfo($listener, $eventName);
[191] Fix | Delete
$notCalled[$eventName.'.'.$info['pretty']] = $info;
[192] Fix | Delete
}
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
uasort($notCalled, array($this, 'sortListenersByPriority'));
[197] Fix | Delete
[198] Fix | Delete
return $notCalled;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Proxies all method calls to the original event dispatcher.
[203] Fix | Delete
*
[204] Fix | Delete
* @param string $method The method name
[205] Fix | Delete
* @param array $arguments The method arguments
[206] Fix | Delete
*
[207] Fix | Delete
* @return mixed
[208] Fix | Delete
*/
[209] Fix | Delete
public function __call($method, $arguments)
[210] Fix | Delete
{
[211] Fix | Delete
return \call_user_func_array(array($this->dispatcher, $method), $arguments);
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* Called before dispatching the event.
[216] Fix | Delete
*
[217] Fix | Delete
* @param string $eventName The event name
[218] Fix | Delete
* @param Event $event The event
[219] Fix | Delete
*/
[220] Fix | Delete
protected function preDispatch($eventName, Event $event)
[221] Fix | Delete
{
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Called after dispatching the event.
[226] Fix | Delete
*
[227] Fix | Delete
* @param string $eventName The event name
[228] Fix | Delete
* @param Event $event The event
[229] Fix | Delete
*/
[230] Fix | Delete
protected function postDispatch($eventName, Event $event)
[231] Fix | Delete
{
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
private function preProcess($eventName)
[235] Fix | Delete
{
[236] Fix | Delete
foreach ($this->dispatcher->getListeners($eventName) as $listener) {
[237] Fix | Delete
$info = $this->getListenerInfo($listener, $eventName);
[238] Fix | Delete
$name = isset($info['class']) ? $info['class'] : $info['type'];
[239] Fix | Delete
$wrappedListener = new WrappedListener($listener, $name, $this->stopwatch, $this);
[240] Fix | Delete
$this->wrappedListeners[$eventName][] = $wrappedListener;
[241] Fix | Delete
$this->dispatcher->removeListener($eventName, $listener);
[242] Fix | Delete
$this->dispatcher->addListener($eventName, $wrappedListener, $info['priority']);
[243] Fix | Delete
}
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
private function postProcess($eventName)
[247] Fix | Delete
{
[248] Fix | Delete
unset($this->wrappedListeners[$eventName]);
[249] Fix | Delete
$skipped = false;
[250] Fix | Delete
foreach ($this->dispatcher->getListeners($eventName) as $listener) {
[251] Fix | Delete
if (!$listener instanceof WrappedListener) { // #12845: a new listener was added during dispatch.
[252] Fix | Delete
continue;
[253] Fix | Delete
}
[254] Fix | Delete
// Unwrap listener
[255] Fix | Delete
$priority = $this->getListenerPriority($eventName, $listener);
[256] Fix | Delete
$this->dispatcher->removeListener($eventName, $listener);
[257] Fix | Delete
$this->dispatcher->addListener($eventName, $listener->getWrappedListener(), $priority);
[258] Fix | Delete
[259] Fix | Delete
$info = $this->getListenerInfo($listener->getWrappedListener(), $eventName);
[260] Fix | Delete
if ($listener->wasCalled()) {
[261] Fix | Delete
if (null !== $this->logger) {
[262] Fix | Delete
$this->logger->debug(sprintf('Notified event "%s" to listener "%s".', $eventName, $info['pretty']));
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
if (!isset($this->called[$eventName])) {
[266] Fix | Delete
$this->called[$eventName] = new \SplObjectStorage();
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
$this->called[$eventName]->attach($listener);
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
if (null !== $this->logger && $skipped) {
[273] Fix | Delete
$this->logger->debug(sprintf('Listener "%s" was not called for event "%s".', $info['pretty'], $eventName));
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
if ($listener->stoppedPropagation()) {
[277] Fix | Delete
if (null !== $this->logger) {
[278] Fix | Delete
$this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s".', $info['pretty'], $eventName));
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
$skipped = true;
[282] Fix | Delete
}
[283] Fix | Delete
}
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
/**
[287] Fix | Delete
* Returns information about the listener.
[288] Fix | Delete
*
[289] Fix | Delete
* @param object $listener The listener
[290] Fix | Delete
* @param string $eventName The event name
[291] Fix | Delete
*
[292] Fix | Delete
* @return array Information about the listener
[293] Fix | Delete
*/
[294] Fix | Delete
private function getListenerInfo($listener, $eventName)
[295] Fix | Delete
{
[296] Fix | Delete
$info = array(
[297] Fix | Delete
'event' => $eventName,
[298] Fix | Delete
'priority' => $this->getListenerPriority($eventName, $listener),
[299] Fix | Delete
);
[300] Fix | Delete
[301] Fix | Delete
// unwrap for correct listener info
[302] Fix | Delete
if ($listener instanceof WrappedListener) {
[303] Fix | Delete
$listener = $listener->getWrappedListener();
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
if ($listener instanceof \Closure) {
[307] Fix | Delete
$info += array(
[308] Fix | Delete
'type' => 'Closure',
[309] Fix | Delete
'pretty' => 'closure',
[310] Fix | Delete
);
[311] Fix | Delete
} elseif (\is_string($listener)) {
[312] Fix | Delete
try {
[313] Fix | Delete
$r = new \ReflectionFunction($listener);
[314] Fix | Delete
$file = $r->getFileName();
[315] Fix | Delete
$line = $r->getStartLine();
[316] Fix | Delete
} catch (\ReflectionException $e) {
[317] Fix | Delete
$file = null;
[318] Fix | Delete
$line = null;
[319] Fix | Delete
}
[320] Fix | Delete
$info += array(
[321] Fix | Delete
'type' => 'Function',
[322] Fix | Delete
'function' => $listener,
[323] Fix | Delete
'file' => $file,
[324] Fix | Delete
'line' => $line,
[325] Fix | Delete
'pretty' => $listener,
[326] Fix | Delete
);
[327] Fix | Delete
} elseif (\is_array($listener) || (\is_object($listener) && \is_callable($listener))) {
[328] Fix | Delete
if (!\is_array($listener)) {
[329] Fix | Delete
$listener = array($listener, '__invoke');
[330] Fix | Delete
}
[331] Fix | Delete
$class = \is_object($listener[0]) ? \get_class($listener[0]) : $listener[0];
[332] Fix | Delete
try {
[333] Fix | Delete
$r = new \ReflectionMethod($class, $listener[1]);
[334] Fix | Delete
$file = $r->getFileName();
[335] Fix | Delete
$line = $r->getStartLine();
[336] Fix | Delete
} catch (\ReflectionException $e) {
[337] Fix | Delete
$file = null;
[338] Fix | Delete
$line = null;
[339] Fix | Delete
}
[340] Fix | Delete
$info += array(
[341] Fix | Delete
'type' => 'Method',
[342] Fix | Delete
'class' => $class,
[343] Fix | Delete
'method' => $listener[1],
[344] Fix | Delete
'file' => $file,
[345] Fix | Delete
'line' => $line,
[346] Fix | Delete
'pretty' => $class.'::'.$listener[1],
[347] Fix | Delete
);
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
return $info;
[351] Fix | Delete
}
[352] Fix | Delete
[353] Fix | Delete
private function sortListenersByPriority($a, $b)
[354] Fix | Delete
{
[355] Fix | Delete
if (\is_int($a['priority']) && !\is_int($b['priority'])) {
[356] Fix | Delete
return 1;
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
if (!\is_int($a['priority']) && \is_int($b['priority'])) {
[360] Fix | Delete
return -1;
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
if ($a['priority'] === $b['priority']) {
[364] Fix | Delete
return 0;
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
if ($a['priority'] > $b['priority']) {
[368] Fix | Delete
return -1;
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
return 1;
[372] Fix | Delete
}
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function