コード例 #1
0
 /**
  * Loads event subscribers from configuration
  */
 private function loadEventSubscribersFile()
 {
     // Load file.
     $bag = new ContainerLessBag();
     $fileLoader = $this->getServiceBag()->getFileLoader();
     $filename = $this->generateConfigFilePath('event_subscribers.yml');
     $fileLoader->loadFileToBag($filename, 'event_subscribers', $bag);
     // Resolve parameters.
     $fileLoader->resolveParameters($bag, $this->getParameterBag());
     $eventSubscribers = array();
     // Instantiate services and load then to the container.
     foreach ($bag->values() as $name => $values) {
         // Multiple definitions for the same event subscriber, abort.
         if (array_key_exists($name, $eventSubscribers)) {
             throw ConfigurationException::multipleEventSubscriberDefinitionsException($name);
         }
         // Check if class is set (null counts as unset).
         if (!isset($values['class'])) {
             throw ConfigurationException::configurationAttributeNotFoundException($filename, $name, 'class');
         }
         $class = $values['class'];
         $eventSubscriber = $this->instantiateClass($class, isset($values['arguments']) ? $values['arguments'] : array());
         if (!$eventSubscriber instanceof EventSubscriberInterface) {
             throw LogicException::mustImplementInterfaceException('EventSubscriberInterface', $class);
         }
         $eventSubscribers[$name] = $eventSubscriber;
     }
     // Register the event subscribers.
     foreach ($eventSubscribers as $eventSubscriber) {
         $this->registerEventSubscriber($eventSubscriber);
     }
 }