Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../vendor/symfony/event-di...
File: ContainerAwareEventDispatcher.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
use Symfony\Component\DependencyInjection\ContainerInterface;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Lazily loads listeners and subscribers from the dependency injection
[16] Fix | Delete
* container.
[17] Fix | Delete
*
[18] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[19] Fix | Delete
* @author Bernhard Schussek <bschussek@gmail.com>
[20] Fix | Delete
* @author Jordan Alliot <jordan.alliot@gmail.com>
[21] Fix | Delete
*/
[22] Fix | Delete
class ContainerAwareEventDispatcher extends EventDispatcher
[23] Fix | Delete
{
[24] Fix | Delete
private $container;
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* The service IDs of the event listeners and subscribers.
[28] Fix | Delete
*/
[29] Fix | Delete
private $listenerIds = array();
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* The services registered as listeners.
[33] Fix | Delete
*/
[34] Fix | Delete
private $listeners = array();
[35] Fix | Delete
[36] Fix | Delete
public function __construct(ContainerInterface $container)
[37] Fix | Delete
{
[38] Fix | Delete
$this->container = $container;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* Adds a service as event listener.
[43] Fix | Delete
*
[44] Fix | Delete
* @param string $eventName Event for which the listener is added
[45] Fix | Delete
* @param array $callback The service ID of the listener service & the method
[46] Fix | Delete
* name that has to be called
[47] Fix | Delete
* @param int $priority The higher this value, the earlier an event listener
[48] Fix | Delete
* will be triggered in the chain.
[49] Fix | Delete
* Defaults to 0.
[50] Fix | Delete
*
[51] Fix | Delete
* @throws \InvalidArgumentException
[52] Fix | Delete
*/
[53] Fix | Delete
public function addListenerService($eventName, $callback, $priority = 0)
[54] Fix | Delete
{
[55] Fix | Delete
if (!\is_array($callback) || 2 !== \count($callback)) {
[56] Fix | Delete
throw new \InvalidArgumentException('Expected an array("service", "method") argument');
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
$this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority);
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
public function removeListener($eventName, $listener)
[63] Fix | Delete
{
[64] Fix | Delete
$this->lazyLoad($eventName);
[65] Fix | Delete
[66] Fix | Delete
if (isset($this->listenerIds[$eventName])) {
[67] Fix | Delete
foreach ($this->listenerIds[$eventName] as $i => $args) {
[68] Fix | Delete
list($serviceId, $method) = $args;
[69] Fix | Delete
$key = $serviceId.'.'.$method;
[70] Fix | Delete
if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) {
[71] Fix | Delete
unset($this->listeners[$eventName][$key]);
[72] Fix | Delete
if (empty($this->listeners[$eventName])) {
[73] Fix | Delete
unset($this->listeners[$eventName]);
[74] Fix | Delete
}
[75] Fix | Delete
unset($this->listenerIds[$eventName][$i]);
[76] Fix | Delete
if (empty($this->listenerIds[$eventName])) {
[77] Fix | Delete
unset($this->listenerIds[$eventName]);
[78] Fix | Delete
}
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
parent::removeListener($eventName, $listener);
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* {@inheritdoc}
[88] Fix | Delete
*/
[89] Fix | Delete
public function hasListeners($eventName = null)
[90] Fix | Delete
{
[91] Fix | Delete
if (null === $eventName) {
[92] Fix | Delete
return $this->listenerIds || $this->listeners || parent::hasListeners();
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
if (isset($this->listenerIds[$eventName])) {
[96] Fix | Delete
return true;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
return parent::hasListeners($eventName);
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* {@inheritdoc}
[104] Fix | Delete
*/
[105] Fix | Delete
public function getListeners($eventName = null)
[106] Fix | Delete
{
[107] Fix | Delete
if (null === $eventName) {
[108] Fix | Delete
foreach ($this->listenerIds as $serviceEventName => $args) {
[109] Fix | Delete
$this->lazyLoad($serviceEventName);
[110] Fix | Delete
}
[111] Fix | Delete
} else {
[112] Fix | Delete
$this->lazyLoad($eventName);
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
return parent::getListeners($eventName);
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* {@inheritdoc}
[120] Fix | Delete
*/
[121] Fix | Delete
public function getListenerPriority($eventName, $listener)
[122] Fix | Delete
{
[123] Fix | Delete
$this->lazyLoad($eventName);
[124] Fix | Delete
[125] Fix | Delete
return parent::getListenerPriority($eventName, $listener);
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
/**
[129] Fix | Delete
* Adds a service as event subscriber.
[130] Fix | Delete
*
[131] Fix | Delete
* @param string $serviceId The service ID of the subscriber service
[132] Fix | Delete
* @param string $class The service's class name (which must implement EventSubscriberInterface)
[133] Fix | Delete
*/
[134] Fix | Delete
public function addSubscriberService($serviceId, $class)
[135] Fix | Delete
{
[136] Fix | Delete
foreach ($class::getSubscribedEvents() as $eventName => $params) {
[137] Fix | Delete
if (\is_string($params)) {
[138] Fix | Delete
$this->listenerIds[$eventName][] = array($serviceId, $params, 0);
[139] Fix | Delete
} elseif (\is_string($params[0])) {
[140] Fix | Delete
$this->listenerIds[$eventName][] = array($serviceId, $params[0], isset($params[1]) ? $params[1] : 0);
[141] Fix | Delete
} else {
[142] Fix | Delete
foreach ($params as $listener) {
[143] Fix | Delete
$this->listenerIds[$eventName][] = array($serviceId, $listener[0], isset($listener[1]) ? $listener[1] : 0);
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
public function getContainer()
[150] Fix | Delete
{
[151] Fix | Delete
return $this->container;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* Lazily loads listeners for this event from the dependency injection
[156] Fix | Delete
* container.
[157] Fix | Delete
*
[158] Fix | Delete
* @param string $eventName The name of the event to dispatch. The name of
[159] Fix | Delete
* the event is the name of the method that is
[160] Fix | Delete
* invoked on listeners.
[161] Fix | Delete
*/
[162] Fix | Delete
protected function lazyLoad($eventName)
[163] Fix | Delete
{
[164] Fix | Delete
if (isset($this->listenerIds[$eventName])) {
[165] Fix | Delete
foreach ($this->listenerIds[$eventName] as $args) {
[166] Fix | Delete
list($serviceId, $method, $priority) = $args;
[167] Fix | Delete
$listener = $this->container->get($serviceId);
[168] Fix | Delete
[169] Fix | Delete
$key = $serviceId.'.'.$method;
[170] Fix | Delete
if (!isset($this->listeners[$eventName][$key])) {
[171] Fix | Delete
$this->addListener($eventName, array($listener, $method), $priority);
[172] Fix | Delete
} elseif ($this->listeners[$eventName][$key] !== $listener) {
[173] Fix | Delete
parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method));
[174] Fix | Delete
$this->addListener($eventName, array($listener, $method), $priority);
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
$this->listeners[$eventName][$key] = $listener;
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function