{@inheritdoc}

@param  object|string  $subscriber
@return void
548126
public function subscribe($subscriber)
    {
        if (is_object($subscriber)) {
            $subscriber->subscribe($this);
            return;
        }
        $this->subscribe(new $subscriber);
    }
191529
public function registerSubscriptions(EventDispatcher $dispatcher)
    {
        if ($this->registered) {
            throw new \RuntimeException('Cannot register debug toolbar subscriptions when already registered.');
        }

        foreach ($this->toolbar->getExtensions() as $extension) {
            if ( ! $extension instanceof EventSubscriberInterface) {
                continue;
            }

            $dispatcher->addSubscriber($extension);
        }

        $this->registered = true;
    }
141813
public function it_should_have_listener_after_adding_subscriber(MockSubscriber $sub)
    {
        $events = [
            'test1' => [
                [
                    [
                        $sub,
                        'method1'
                    ],
                    [
                        $sub,
                        'method2'
                    ]
                ]
            ]
        ];
        $this->getListeners()
             ->shouldHaveCount(0);
        $sub->getSubscribedEvents()
            ->willReturn($events);
        $this->addSubscriber($sub);
        $this->getListeners()
             ->shouldHaveCount(1);
        $this->getListeners()
             ->shouldHaveKey('test1');
    }
444284
public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        foreach ($subscriber->getSubscribedEvents() as $name => $params) {
            if (is_string($params)) {
                $this->addListener($name, [$subscriber, $params]);
            } elseif(is_string($params[0]) && is_numeric($params[1])) {
                $this->addListener($name, [$subscriber, $params[0]], $params[1]);
            } else {
                foreach ($params as $param) {
                    if (is_string($param)) {
                        $this->addListener($name, [$subscriber, $param]);
                    } else {
                        $this->addListener($name, [$subscriber, $param[0]], isset($param[1]) ? $param[1] : 0);
                    }
                }
            }
        }
    }
933667
public function dispatch($event): void
    {
        Assertion::isObject($event, 'An event should be an object');

        $eventName = get_class($event);
        $eventSubscribers = array_merge(
            $this->subscribedToAllEvents,
            $this->subscribers[$eventName] ?? []
        );

        foreach ($eventSubscribers as $eventSubscriber) {
            $eventSubscriber($event);
        }
    }
893009
private function doBeforeCompileLaziness(): void
	{
		$builder = $this->getContainerBuilder();
		$dispatcher = $builder->getDefinition($this->prefix('dispatcher'));

		$subscribers = $builder->findByType(EventSubscriberInterface::class);
		foreach ($subscribers as $name => $subscriber) {
			$events = call_user_func([$subscriber->getEntity(), 'getSubscribedEvents']);

			/**
			 * ['eventName' => 'methodName']
			 * ['eventName' => ['methodName', $priority]]
			 * ['eventName' => [['methodName1', $priority], ['methodName2']]]
			 */
			foreach ($events as $event => $args) {
				if (is_string($args)) {
					if (!method_exists((string) $subscriber->getType(), $args)) {
						throw new ServiceCreationException(sprintf('Event listener %s does not have callable method %s', $subscriber->getType(), $args));
					}

					$dispatcher->addSetup('addSubscriberLazy', [$event, $name]);
				} elseif (is_string($args[0])) {
					if (!method_exists((string) $subscriber->getType(), $args[0])) {
						throw new ServiceCreationException(sprintf('Event listener %s does not have callable method %s', $subscriber->getType(), $args[0]));
					}

					$dispatcher->addSetup('addSubscriberLazy', [$event, $name]);
				} else {
					foreach ($args as $arg) {
						if (!method_exists((string) $subscriber->getType(), $arg[0])) {
							throw new ServiceCreationException(sprintf('Event listener %s does not have callable method %s', $subscriber->getType(), $arg[0]));
						}

						$dispatcher->addSetup('addSubscriberLazy', [$event, $name]);
					}
				}
			}
		}
	}
734382
public function addSubscriber(SubscriberInterface $instance) {

		// make sure that an already registered object is removed before re-registering
		
		$this->removeSubscriber($instance);

		// register object hash

		$this->registeredHashes[] = spl_object_hash($instance);

		// parameters contain at least a method name; additionally a priority can be added
		
		foreach($instance::getEventsToSubscribe() as $eventName => $parameters) {

			$parameters	= (array) $parameters;
			$methodName	= array_shift($parameters); 

			if(count($parameters)) {
				$priority = (int) $parameters[0];
			}
			else {
				$priority = 0;
			}

			if(!isset($this->registry[$eventName]) || !isset($this->registry[$eventName][$priority])) {
				$this->registry[$eventName][$priority] = [];
			}

			$this->registry[$eventName][$priority][] = [$instance, $methodName];

			// force re-sort upon next dispatch

			unset ($this->sortedRegistry[$eventName]);

		}
		
	}
1342964
protected function checkMethod($subscriber, $event, $method)
    {
        if (!is_string($method)) {
            $message = 'Listener definition for event "%s" contains an invalid method reference: %s';
            $this->addProblem(sprintf($message, $event, $this->exporter->export($method)));
            return;
        }
        if (!method_exists($subscriber, $method)) {
            $message = 'Listener definition for event "%s" references method "%s", '
                     . 'but the method does not exist on subscriber.';
            $this->addProblem(sprintf($message, $event, $method));
            return;
        }
        if (!is_callable(array($subscriber, $method))) {
            $message = 'Listener definition for event "%s" references method "%s", '
                     . 'but the method is not publicly accessible.';
            $this->addProblem(sprintf($message, $event, $method));
            return;
        }
    }
1144093
private function processEventSubscribers()
    {
        if (isset($this->configuration['events']['subscribers'])) {
            foreach ($this->configuration['events']['subscribers'] as $i => $subscriber) {
                if (is_string($subscriber)) {
                    $this->configuration['events']['subscribers'][$i] = array('class' => $subscriber);
                }
            }
        }
    }
1028877
public function changeEmailAddress(Subscriber &$subscriber, $new_email)
		{
			$form_data = array(
				'email'     => $subscriber->getEmail(),
				'email_new' => $new_email
			);
			$this->call('change', $form_data);

			$subscriber->setEmail($new_email);
		}
510639
public function dispatchEvent(String $eventId, $subscriber=null)
	{
		if (isset(EventManager::$listeners[$eventId])) {
			foreach(EventManager::$listeners[$eventId] as $listener) {
				call_user_func_array($listener, [$subscriber]);
			}
		}
	}
651573
private void complete(Subscriber<? super T> subscriber) {
        if (!subscriber.isUnsubscribed()) {
            debug("onCompleted");
            subscriber.onCompleted();
        } else
            debug("unsubscribed");
    }
443206
public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        if (!$this->hasSubscriber($subscriber)) {
            $this->subscribers[] = $subscriber;
        }

        return $this;
    }
998371
public function subscribe()
    {
        foreach (static::$eventHandlerMap as $eventName => $handler) {
            $this->events->listen($eventName, [$this, $handler]);
        }
    }
1263937
private function getDataFromSubscription(Subscriber $subscriber)
    {
        $data = [
            'subscriber' => $subscriber->getData(),
        ];

        if ($subscriber->getConfirmationLink()) {
            $data['subscriber'] = $subscriber->getData();
        }
        if ($subscriber->getCustomerId()) {
            $customer = $this->customerFactory->create()->load($subscriber->getCustomerId());
            $data['customer'] = $customer->getData();
        }
        return $data;
    }
55742
public void setSubscribe(boolean subscribe) {
        addField(ConfigureNodeFields.subscribe, FormField.Type.bool);
        setAnswer(ConfigureNodeFields.subscribe.getFieldName(), subscribe);
    }
643703
public function delete($listId, Subscriber $subscriber)
    {
        $subscriberHash = $this->mailchimp->subscriberHash($subscriber->getEmail());
        $result = $this->mailchimp->delete("lists/$listId/members/$subscriberHash");

        if (!$this->mailchimp->success()) {
            $this->throwMailchimpError($this->mailchimp->getLastResponse());
        }

        return $result;
    }