comparison vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
28 private $container; 28 private $container;
29 29
30 /** 30 /**
31 * The service IDs of the event listeners and subscribers. 31 * The service IDs of the event listeners and subscribers.
32 */ 32 */
33 private $listenerIds = array(); 33 private $listenerIds = [];
34 34
35 /** 35 /**
36 * The services registered as listeners. 36 * The services registered as listeners.
37 */ 37 */
38 private $listeners = array(); 38 private $listeners = [];
39 39
40 public function __construct(ContainerInterface $container) 40 public function __construct(ContainerInterface $container)
41 { 41 {
42 $this->container = $container; 42 $this->container = $container;
43 43
44 $class = get_class($this); 44 $class = \get_class($this);
45 if ($this instanceof \PHPUnit_Framework_MockObject_MockObject || $this instanceof \Prophecy\Doubler\DoubleInterface) { 45 if ($this instanceof \PHPUnit_Framework_MockObject_MockObject || $this instanceof \Prophecy\Doubler\DoubleInterface) {
46 $class = get_parent_class($class); 46 $class = get_parent_class($class);
47 } 47 }
48 if (__CLASS__ !== $class) { 48 if (__CLASS__ !== $class) {
49 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); 49 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED);
64 */ 64 */
65 public function addListenerService($eventName, $callback, $priority = 0) 65 public function addListenerService($eventName, $callback, $priority = 0)
66 { 66 {
67 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); 67 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED);
68 68
69 if (!is_array($callback) || 2 !== count($callback)) { 69 if (!\is_array($callback) || 2 !== \count($callback)) {
70 throw new \InvalidArgumentException('Expected an array("service", "method") argument'); 70 throw new \InvalidArgumentException('Expected an ["service", "method"] argument');
71 } 71 }
72 72
73 $this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority); 73 $this->listenerIds[$eventName][] = [$callback[0], $callback[1], $priority];
74 } 74 }
75 75
76 public function removeListener($eventName, $listener) 76 public function removeListener($eventName, $listener)
77 { 77 {
78 $this->lazyLoad($eventName); 78 $this->lazyLoad($eventName);
79 79
80 if (isset($this->listenerIds[$eventName])) { 80 if (isset($this->listenerIds[$eventName])) {
81 foreach ($this->listenerIds[$eventName] as $i => list($serviceId, $method)) { 81 foreach ($this->listenerIds[$eventName] as $i => list($serviceId, $method)) {
82 $key = $serviceId.'.'.$method; 82 $key = $serviceId.'.'.$method;
83 if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) { 83 if (isset($this->listeners[$eventName][$key]) && $listener === [$this->listeners[$eventName][$key], $method]) {
84 unset($this->listeners[$eventName][$key]); 84 unset($this->listeners[$eventName][$key]);
85 if (empty($this->listeners[$eventName])) { 85 if (empty($this->listeners[$eventName])) {
86 unset($this->listeners[$eventName]); 86 unset($this->listeners[$eventName]);
87 } 87 }
88 unset($this->listenerIds[$eventName][$i]); 88 unset($this->listenerIds[$eventName][$i]);
147 public function addSubscriberService($serviceId, $class) 147 public function addSubscriberService($serviceId, $class)
148 { 148 {
149 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED); 149 @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED);
150 150
151 foreach ($class::getSubscribedEvents() as $eventName => $params) { 151 foreach ($class::getSubscribedEvents() as $eventName => $params) {
152 if (is_string($params)) { 152 if (\is_string($params)) {
153 $this->listenerIds[$eventName][] = array($serviceId, $params, 0); 153 $this->listenerIds[$eventName][] = [$serviceId, $params, 0];
154 } elseif (is_string($params[0])) { 154 } elseif (\is_string($params[0])) {
155 $this->listenerIds[$eventName][] = array($serviceId, $params[0], isset($params[1]) ? $params[1] : 0); 155 $this->listenerIds[$eventName][] = [$serviceId, $params[0], isset($params[1]) ? $params[1] : 0];
156 } else { 156 } else {
157 foreach ($params as $listener) { 157 foreach ($params as $listener) {
158 $this->listenerIds[$eventName][] = array($serviceId, $listener[0], isset($listener[1]) ? $listener[1] : 0); 158 $this->listenerIds[$eventName][] = [$serviceId, $listener[0], isset($listener[1]) ? $listener[1] : 0];
159 } 159 }
160 } 160 }
161 } 161 }
162 } 162 }
163 163
182 foreach ($this->listenerIds[$eventName] as list($serviceId, $method, $priority)) { 182 foreach ($this->listenerIds[$eventName] as list($serviceId, $method, $priority)) {
183 $listener = $this->container->get($serviceId); 183 $listener = $this->container->get($serviceId);
184 184
185 $key = $serviceId.'.'.$method; 185 $key = $serviceId.'.'.$method;
186 if (!isset($this->listeners[$eventName][$key])) { 186 if (!isset($this->listeners[$eventName][$key])) {
187 $this->addListener($eventName, array($listener, $method), $priority); 187 $this->addListener($eventName, [$listener, $method], $priority);
188 } elseif ($this->listeners[$eventName][$key] !== $listener) { 188 } elseif ($this->listeners[$eventName][$key] !== $listener) {
189 parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method)); 189 parent::removeListener($eventName, [$this->listeners[$eventName][$key], $method]);
190 $this->addListener($eventName, array($listener, $method), $priority); 190 $this->addListener($eventName, [$listener, $method], $priority);
191 } 191 }
192 192
193 $this->listeners[$eventName][$key] = $listener; 193 $this->listeners[$eventName][$key] = $listener;
194 } 194 }
195 } 195 }