예제 #1
0
 public function process(ehough_iconic_ContainerBuilder $container)
 {
     foreach ($container->getDefinitions() as $id => $definition) {
         if (!($decorated = $definition->getDecoratedService())) {
             continue;
         }
         $definition->setDecoratedService(null);
         list($inner, $renamedId) = $decorated;
         if (!$renamedId) {
             $renamedId = $id . '.inner';
         }
         // we create a new alias/service for the service we are replacing
         // to be able to reference it in the new one
         if ($container->hasAlias($inner)) {
             $alias = $container->getAlias($inner);
             $public = $alias->isPublic();
             $container->setAlias($renamedId, new ehough_iconic_Alias((string) $alias, false));
         } else {
             $definition = $container->getDefinition($inner);
             $public = $definition->isPublic();
             $definition->setPublic(false);
             $container->setDefinition($renamedId, $definition);
         }
         $container->setAlias($inner, new ehough_iconic_Alias($id, $public));
     }
 }
 /**
  * Process the Container to replace aliases with service definitions.
  *
  * @param ehough_iconic_ContainerBuilder $container
  *
  * @throws ehough_iconic_exception_InvalidArgumentException if the service definition does not exist
  */
 public function process(ehough_iconic_ContainerBuilder $container)
 {
     $this->compiler = $container->getCompiler();
     $this->formatter = $this->compiler->getLoggingFormatter();
     foreach ($container->getAliases() as $id => $alias) {
         $aliasId = (string) $alias;
         try {
             $definition = $container->getDefinition($aliasId);
         } catch (ehough_iconic_exception_InvalidArgumentException $e) {
             if (version_compare(PHP_VERSION, '5.3') < 0) {
                 throw new ehough_iconic_exception_InvalidArgumentException(sprintf('Unable to replace alias "%s" with "%s".', $alias, $id), null);
             } else {
                 throw new ehough_iconic_exception_InvalidArgumentException(sprintf('Unable to replace alias "%s" with "%s".', $alias, $id), null, $e);
             }
         }
         if ($definition->isPublic()) {
             continue;
         }
         $definition->setPublic(true);
         $container->setDefinition($id, $definition);
         $container->removeDefinition($aliasId);
         $this->updateReferences($container, $aliasId, $id);
         // we have to restart the process due to concurrent modification of
         // the container
         $this->process($container);
         break;
     }
 }
예제 #3
0
 public function process(ehough_iconic_ContainerBuilder $container)
 {
     if (!$container->hasDefinition($this->dispatcherService) && !$container->hasAlias($this->dispatcherService)) {
         return;
     }
     $definition = $container->findDefinition($this->dispatcherService);
     foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) {
         $def = $container->getDefinition($id);
         if (!$def->isPublic()) {
             throw new InvalidArgumentException(sprintf('The service "%s" must be public as event listeners are lazy-loaded.', $id));
         }
         if ($def->isAbstract()) {
             throw new InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id));
         }
         foreach ($events as $event) {
             $priority = isset($event['priority']) ? $event['priority'] : 0;
             if (!isset($event['event'])) {
                 throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag));
             }
             if (!isset($event['method'])) {
                 $event['method'] = 'on' . preg_replace_callback(array('/(?<=\\b)[a-z]/i', '/[^a-z0-9]/i'), array($this, '_upperMatches'), $event['event']);
                 $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
             }
             $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority));
         }
     }
     foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) {
         $def = $container->getDefinition($id);
         if (!$def->isPublic()) {
             throw new InvalidArgumentException(sprintf('The service "%s" must be public as event subscribers are lazy-loaded.', $id));
         }
         // We must assume that the class value has been correctly filled, even if the service is created by a factory
         $class = $def->getClass();
         $refClass = new ReflectionClass($class);
         $interface = 'ehough_tickertape_EventSubscriberInterface';
         if (!$refClass->implementsInterface($interface)) {
             throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
         }
         $definition->addMethodCall('addSubscriberService', array($id, $class));
     }
 }
 /**
  * Process the ContainerBuilder to replace ehough_iconic_DefinitionDecorator instances with their real ehough_iconic_Definition instances.
  *
  * @param ehough_iconic_ContainerBuilder $container
  */
 public function process(ehough_iconic_ContainerBuilder $container)
 {
     $this->container = $container;
     $this->compiler = $container->getCompiler();
     $this->formatter = $this->compiler->getLoggingFormatter();
     foreach (array_keys($container->getDefinitions()) as $id) {
         // yes, we are specifically fetching the definition from the
         // container to ensure we are not operating on stale data
         $definition = $container->getDefinition($id);
         if (!$definition instanceof ehough_iconic_DefinitionDecorator || $definition->isAbstract()) {
             continue;
         }
         $this->resolveDefinition($id, $definition);
     }
 }
 /**
  * Checks if the definition is inlineable.
  *
  * @param ehough_iconic_ContainerBuilder $container
  * @param string           $id
  * @param ehough_iconic_Definition       $definition
  *
  * @return bool    If the definition is inlineable
  */
 private function isInlineableDefinition(ehough_iconic_ContainerBuilder $container, $id, ehough_iconic_Definition $definition)
 {
     if (ehough_iconic_ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope()) {
         return true;
     }
     if ($definition->isPublic() || $definition->isLazy()) {
         return false;
     }
     if (!$this->graph->hasNode($id)) {
         return true;
     }
     if ($this->currentId == $id) {
         return false;
     }
     $ids = array();
     foreach ($this->graph->getNode($id)->getInEdges() as $edge) {
         $ids[] = $edge->getSourceNode()->getId();
     }
     if (count(array_unique($ids)) > 1) {
         return false;
     }
     return $container->getDefinition(reset($ids))->getScope() === $definition->getScope();
 }