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