Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../vendor/symfony/event-di...
File: EventDispatcher.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;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* The EventDispatcherInterface is the central point of Symfony's event listener system.
[14] Fix | Delete
*
[15] Fix | Delete
* Listeners are registered on the manager and events are dispatched through the
[16] Fix | Delete
* manager.
[17] Fix | Delete
*
[18] Fix | Delete
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
[19] Fix | Delete
* @author Jonathan Wage <jonwage@gmail.com>
[20] Fix | Delete
* @author Roman Borschel <roman@code-factory.org>
[21] Fix | Delete
* @author Bernhard Schussek <bschussek@gmail.com>
[22] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[23] Fix | Delete
* @author Jordi Boggiano <j.boggiano@seld.be>
[24] Fix | Delete
* @author Jordan Alliot <jordan.alliot@gmail.com>
[25] Fix | Delete
*/
[26] Fix | Delete
class EventDispatcher implements EventDispatcherInterface
[27] Fix | Delete
{
[28] Fix | Delete
private $listeners = array();
[29] Fix | Delete
private $sorted = array();
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* {@inheritdoc}
[33] Fix | Delete
*/
[34] Fix | Delete
public function dispatch($eventName, Event $event = null)
[35] Fix | Delete
{
[36] Fix | Delete
if (null === $event) {
[37] Fix | Delete
$event = new Event();
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
$event->setDispatcher($this);
[41] Fix | Delete
$event->setName($eventName);
[42] Fix | Delete
[43] Fix | Delete
if ($listeners = $this->getListeners($eventName)) {
[44] Fix | Delete
$this->doDispatch($listeners, $eventName, $event);
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
return $event;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* {@inheritdoc}
[52] Fix | Delete
*/
[53] Fix | Delete
public function getListeners($eventName = null)
[54] Fix | Delete
{
[55] Fix | Delete
if (null !== $eventName) {
[56] Fix | Delete
if (!isset($this->listeners[$eventName])) {
[57] Fix | Delete
return array();
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
if (!isset($this->sorted[$eventName])) {
[61] Fix | Delete
$this->sortListeners($eventName);
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
return $this->sorted[$eventName];
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
foreach ($this->listeners as $eventName => $eventListeners) {
[68] Fix | Delete
if (!isset($this->sorted[$eventName])) {
[69] Fix | Delete
$this->sortListeners($eventName);
[70] Fix | Delete
}
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
return array_filter($this->sorted);
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Gets the listener priority for a specific event.
[78] Fix | Delete
*
[79] Fix | Delete
* Returns null if the event or the listener does not exist.
[80] Fix | Delete
*
[81] Fix | Delete
* @param string $eventName The name of the event
[82] Fix | Delete
* @param callable $listener The listener
[83] Fix | Delete
*
[84] Fix | Delete
* @return int|null The event listener priority
[85] Fix | Delete
*/
[86] Fix | Delete
public function getListenerPriority($eventName, $listener)
[87] Fix | Delete
{
[88] Fix | Delete
if (!isset($this->listeners[$eventName])) {
[89] Fix | Delete
return;
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
foreach ($this->listeners[$eventName] as $priority => $listeners) {
[93] Fix | Delete
if (false !== \in_array($listener, $listeners, true)) {
[94] Fix | Delete
return $priority;
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* {@inheritdoc}
[101] Fix | Delete
*/
[102] Fix | Delete
public function hasListeners($eventName = null)
[103] Fix | Delete
{
[104] Fix | Delete
return (bool) $this->getListeners($eventName);
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* {@inheritdoc}
[109] Fix | Delete
*/
[110] Fix | Delete
public function addListener($eventName, $listener, $priority = 0)
[111] Fix | Delete
{
[112] Fix | Delete
$this->listeners[$eventName][$priority][] = $listener;
[113] Fix | Delete
unset($this->sorted[$eventName]);
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* {@inheritdoc}
[118] Fix | Delete
*/
[119] Fix | Delete
public function removeListener($eventName, $listener)
[120] Fix | Delete
{
[121] Fix | Delete
if (!isset($this->listeners[$eventName])) {
[122] Fix | Delete
return;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
foreach ($this->listeners[$eventName] as $priority => $listeners) {
[126] Fix | Delete
if (false !== ($key = array_search($listener, $listeners, true))) {
[127] Fix | Delete
unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]);
[128] Fix | Delete
}
[129] Fix | Delete
}
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* {@inheritdoc}
[134] Fix | Delete
*/
[135] Fix | Delete
public function addSubscriber(EventSubscriberInterface $subscriber)
[136] Fix | Delete
{
[137] Fix | Delete
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
[138] Fix | Delete
if (\is_string($params)) {
[139] Fix | Delete
$this->addListener($eventName, array($subscriber, $params));
[140] Fix | Delete
} elseif (\is_string($params[0])) {
[141] Fix | Delete
$this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
[142] Fix | Delete
} else {
[143] Fix | Delete
foreach ($params as $listener) {
[144] Fix | Delete
$this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
/**
[151] Fix | Delete
* {@inheritdoc}
[152] Fix | Delete
*/
[153] Fix | Delete
public function removeSubscriber(EventSubscriberInterface $subscriber)
[154] Fix | Delete
{
[155] Fix | Delete
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
[156] Fix | Delete
if (\is_array($params) && \is_array($params[0])) {
[157] Fix | Delete
foreach ($params as $listener) {
[158] Fix | Delete
$this->removeListener($eventName, array($subscriber, $listener[0]));
[159] Fix | Delete
}
[160] Fix | Delete
} else {
[161] Fix | Delete
$this->removeListener($eventName, array($subscriber, \is_string($params) ? $params : $params[0]));
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Triggers the listeners of an event.
[168] Fix | Delete
*
[169] Fix | Delete
* This method can be overridden to add functionality that is executed
[170] Fix | Delete
* for each listener.
[171] Fix | Delete
*
[172] Fix | Delete
* @param callable[] $listeners The event listeners
[173] Fix | Delete
* @param string $eventName The name of the event to dispatch
[174] Fix | Delete
* @param Event $event The event object to pass to the event handlers/listeners
[175] Fix | Delete
*/
[176] Fix | Delete
protected function doDispatch($listeners, $eventName, Event $event)
[177] Fix | Delete
{
[178] Fix | Delete
foreach ($listeners as $listener) {
[179] Fix | Delete
if ($event->isPropagationStopped()) {
[180] Fix | Delete
break;
[181] Fix | Delete
}
[182] Fix | Delete
\call_user_func($listener, $event, $eventName, $this);
[183] Fix | Delete
}
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Sorts the internal list of listeners for the given event by priority.
[188] Fix | Delete
*
[189] Fix | Delete
* @param string $eventName The name of the event
[190] Fix | Delete
*/
[191] Fix | Delete
private function sortListeners($eventName)
[192] Fix | Delete
{
[193] Fix | Delete
krsort($this->listeners[$eventName]);
[194] Fix | Delete
$this->sorted[$eventName] = \call_user_func_array('array_merge', $this->listeners[$eventName]);
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function