Adds a service as event subscriber

@param string $serviceId The service ID of the subscriber service
@param string $class The service's class name (which must implement EventSubscriberInterface)
333451
public function addSubscriberService($serviceId, $class)
    {
        $rfc = new \ReflectionClass($class);
        if (!$rfc->implementsInterface('Symfony\Component\EventDispatcher\EventSubscriberInterface')) {
            throw new \InvalidArgumentException(
                "$class must implement Symfony\Component\EventDispatcher\EventSubscriberInterface"
            );
        }

        foreach ($class::getSubscribedEvents() as $eventName => $params) {
            if (is_string($params)) {
                $this->addListenerService($eventName, array($serviceId, $params), 0);
            } elseif (is_string($params[0])) {
                $this->addListenerService($eventName, array($serviceId, $params[0]), isset($params[1]) ? $params[1] : 0);
            } else {
                foreach ($params as $listener) {
                    $this->addListenerService($eventName, array($serviceId, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
                }
            }
        }
    }
674449
public function subscribe($eventType, $callback)
    {
        $callback = $this->makeEventCallback($callback);
        if (!isset($this->eventList[$eventType]) || !is_array($this->eventList[$eventType])) {
            $this->eventList[$eventType] = [];
        }
        array_push($this->eventList[$eventType], $callback);
        return $callback['id'];
    }
441468
protected function registerObserver($class)
    {
        $className = is_string($class) ? $class : get_class($class);

        foreach ($this->getObservableEvents() as $event) {
            if (method_exists($class, $event)) {
                static::registerModelEvent($event, $className . '@' . $event);
            }
        }
    }
504138
protected function encapsulate($class, $serviceConfig)
    {
        $encapsulators = $this->encapsulatorFactory->getEncapsulators();

        foreach ($encapsulators as $encapsulator) {
            $class = $encapsulator->encapsulate($this, $class, $serviceConfig);
        }

        return $class;
    }
466560
public List<Object> getSubscribers(final Class<?> eventType, final String eventId) {
        final List<Object> eventSubs = new ArrayList<>();

        synchronized (registeredSubMap) {
            for (Map.Entry<Object, List<SubIdentifier>> entry : registeredSubMap.entrySet()) {
                for (SubIdentifier sub : entry.getValue()) {
                    if (sub.isMyEvent(eventType, eventId)) {
                        eventSubs.add(entry.getKey());

                        break;
                    }
                }
            }
        }

        return eventSubs;
    }
1332630
public function afterCompile(ClassType $class)
	{
		$initialize = $class->getMethod('initialize');
		$initialize->addBody('$proxyAutolader = (new Doctrine\Common\Proxy\Autoloader)->register(?, ?);', [
			$this->config['proxyDir'],
			$this->config['proxyNamespace']
		]);
		$initialize->addBody('Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(\'class_exists\');');

		$initialize->addBody('$subscribers = $this->findByType(?);', ['\Doctrine\Common\EventSubscriber']);
		$initialize->addBody('foreach ($subscribers as $subscriber) { $this->getService(?)->addEventSubscriber($this->getService($subscriber)); }', [$this->prefix('eventManager')]);
	}
925628
private function tryAutowiring($serviceId, $serviceKey)
    {
        if (!class_exists($serviceKey) || !is_subclass_of($serviceKey, ConfigurableService::class)) {
            throw new ServiceNotFoundException($serviceId);
        }
        return new $serviceKey();
    }
308319
public function addInstance(string $class, $service, bool $share = true)
    {
        $this->services[$class] = $service;
        $this->instantiated[$class] = $service;
        $this->shared[$class] = $share;
    }
220033
final public function set(?string $id, string $class = null): ServiceConfigurator
    {
        $defaults = $this->defaults;
        $allowParent = !$defaults->getChanges() && empty($this->instanceof);

        $definition = new Definition();

        if (null === $id) {
            if (!$class) {
                throw new \LogicException('Anonymous services must have a class name.');
            }

            $id = sprintf('.%d_%s', ++$this->anonymousCount, preg_replace('/^.*\\\\/', '', $class).'~'.$this->anonymousHash);
            $definition->setPublic(false);
        } else {
            $definition->setPublic($defaults->isPublic());
        }

        $definition->setAutowired($defaults->isAutowired());
        $definition->setAutoconfigured($defaults->isAutoconfigured());
        $definition->setBindings($defaults->getBindings());
        $definition->setChanges([]);

        $configurator = new ServiceConfigurator($this->container, $this->instanceof, $allowParent, $this, $definition, $id, $defaults->getTags(), $this->path);

        return null !== $class ? $configurator->class($class) : $configurator;
    }
393052
public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        if ($subscriber instanceof HttpClientEventSubscriber) {
            $subscriber->attachHttpClient($this);
        }

        $this->eventDispatcher->addSubscriber($subscriber);
    }
1093258
public function addEventSubscriber(AnEventSubscriberInterface $subscriber, $priority = null)
    {
        $handle = $subscriber->getHandle();
    
        if (! isset($this->_subscribers[$handle])) {
            $subscriptions = $subscriber->getSubscriptions();
            $priority = is_int($priority) ? $priority : $subscriber->getPriority();
    
            foreach ($subscriptions as $subscription) {
                $this->addEventListener($subscription, $subscriber, $priority);
            }
    
            $this->_subscribers[$handle] = $subscriber;
        }
    
        return $this;
    }
1341418
protected function _attachSubscriber(EventListenerInterface $subscriber)
    {
        foreach ((array)$subscriber->implementedEvents() as $eventKey => $function) {
            $options = [];
            $method = $function;
            if (is_array($function) && isset($function['callable'])) {
                list($method, $options) = $this->_extractCallable($function, $subscriber);
            } elseif (is_array($function) && is_numeric(key($function))) {
                foreach ($function as $f) {
                    list($method, $options) = $this->_extractCallable($f, $subscriber);
                    $this->on($eventKey, $options, $method);
                }
                continue;
            }
            if (is_string($method)) {
                $method = [$subscriber, $function];
            }
            $this->on($eventKey, $options, $method);
        }
    }
923038
public function getService($serviceClass)
    {
        $dfpServices = new DfpServices();

        $session = $this->session();

        return $dfpServices->get($session, $serviceClass);
    }
1310810
public function createService($serviceType)
    {
        $class = sprintf('%s\services\%s', __NAMESPACE__, ucwords($serviceType));
        if (class_exists($class)) {
            $handler = new $class($this);
            return $handler;
        } else {
            throw new Exception("Unknown service: $serviceType");
        }
    }
1313170
public static <E extends Event> void subscribe(Class<E> event, final Listener<E> listener) {
        getEventBus().subscribe(event, listener);
    }
988052
public function registerService(string $className, string $serviceId): void
    {
        assert(
            Validate::implementsInterface($className, EventSubscriber::class),
            sprintf('Invalid subscriber class: %s', $className)
        );
        /** @var EventSubscriber $className The subscriber class name */
        foreach ($className::eventRegistration() as $eventType => $params) {
            $eventType = ClassName::underscore($eventType);
            if (is_string($params)) {
                $this->addHandlerService($eventType, $serviceId, $params);
            } elseif (is_string($params[0])) {
                $priority = isset($params[1]) ? (int) $params[1] : 0;
                $this->addHandlerService($eventType, $serviceId, $params[0], $priority);
            } else {
                foreach ($params as $handler) {
                    $priority = isset($handler[1]) ? (int) $handler[1] : 0;
                    $this->addHandlerService($eventType, $serviceId, $handler[0], $priority);
                }
            }
        }
    }
352844
final public function set(string $id, string $class = null): ServiceConfigurator
    {
        $this->__destruct();

        return $this->parent->set($id, $class);
    }