/**
  * Processes the ContainerBuilder to resolve parameter placeholders.
  *
  * @param ehough_iconic_ContainerBuilder $container
  *
  * @throws ehough_iconic_exception_ParameterNotFoundException
  */
 public function process(ehough_iconic_ContainerBuilder $container)
 {
     $parameterBag = $container->getParameterBag();
     foreach ($container->getDefinitions() as $id => $definition) {
         try {
             $definition->setClass($parameterBag->resolveValue($definition->getClass()));
             $definition->setFile($parameterBag->resolveValue($definition->getFile()));
             $definition->setArguments($parameterBag->resolveValue($definition->getArguments()));
             $calls = array();
             foreach ($definition->getMethodCalls() as $name => $arguments) {
                 $calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments);
             }
             $definition->setMethodCalls($calls);
             $definition->setProperties($parameterBag->resolveValue($definition->getProperties()));
         } catch (ehough_iconic_exception_ParameterNotFoundException $e) {
             $e->setSourceId($id);
             throw $e;
         }
     }
     $aliases = array();
     foreach ($container->getAliases() as $name => $target) {
         $aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target);
     }
     $container->setAliases($aliases);
     $parameterBag->resolve();
 }
 /**
  * Processes a ContainerBuilder object to populate the service reference graph.
  *
  * @param ehough_iconic_ContainerBuilder $container
  */
 public function process(ehough_iconic_ContainerBuilder $container)
 {
     $this->container = $container;
     $this->graph = $container->getCompiler()->getServiceReferenceGraph();
     $this->graph->clear();
     foreach ($container->getDefinitions() as $id => $definition) {
         if ($definition->isSynthetic() || $definition->isAbstract()) {
             continue;
         }
         $this->currentId = $id;
         $this->currentDefinition = $definition;
         $this->processArguments($definition->getArguments());
         if ($definition->getFactoryService()) {
             $this->processArguments(array(new ehough_iconic_Reference($definition->getFactoryService())));
         }
         if (!$this->onlyConstructorArguments) {
             $this->processArguments($definition->getMethodCalls());
             $this->processArguments($definition->getProperties());
             if ($definition->getConfigurator()) {
                 $this->processArguments(array($definition->getConfigurator()));
             }
         }
     }
     foreach ($container->getAliases() as $id => $alias) {
         $this->graph->connect($id, $alias, (string) $alias, $this->getDefinition((string) $alias), null);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(ehough_iconic_ContainerBuilder $container)
 {
     $parameters = $container->getParameterBag()->all();
     $definitions = $container->getDefinitions();
     $aliases = $container->getAliases();
     foreach ($container->getExtensions() as $extension) {
         if ($extension instanceof ehough_iconic_extension_PrependExtensionInterface) {
             $extension->prepend($container);
         }
     }
     foreach ($container->getExtensions() as $name => $extension) {
         if (!($config = $container->getExtensionConfig($name))) {
             // this extension was not called
             continue;
         }
         $config = $container->getParameterBag()->resolveValue($config);
         $tmpContainer = new ehough_iconic_ContainerBuilder($container->getParameterBag());
         $tmpContainer->setResourceTracking($container->isTrackingResources());
         if (class_exists('\\Symfony\\Component\\Config\\Resource\\FileResource')) {
             $tmpContainer->addObjectResource($extension);
         }
         $extension->load($config, $tmpContainer);
         $container->merge($tmpContainer);
     }
     $container->addDefinitions($definitions);
     $container->addAliases($aliases);
     $container->getParameterBag()->add($parameters);
 }
 /**
  * Removes private aliases from the ContainerBuilder
  *
  * @param ehough_iconic_ContainerBuilder $container
  */
 public function process(ehough_iconic_ContainerBuilder $container)
 {
     $compiler = $container->getCompiler();
     $formatter = $compiler->getLoggingFormatter();
     foreach ($container->getAliases() as $id => $alias) {
         if ($alias->isPublic()) {
             continue;
         }
         $container->removeAlias($id);
         $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'private alias'));
     }
 }
 /**
  * Updates references to remove aliases.
  *
  * @param ehough_iconic_ContainerBuilder $container The container
  * @param string           $currentId The alias identifier being replaced
  * @param string           $newId     The id of the service the alias points to
  */
 private function updateReferences($container, $currentId, $newId)
 {
     foreach ($container->getAliases() as $id => $alias) {
         if ($currentId === (string) $alias) {
             $container->setAlias($id, $newId);
         }
     }
     foreach ($container->getDefinitions() as $id => $definition) {
         $this->sourceId = $id;
         $definition->setArguments($this->updateArgumentReferences($definition->getArguments(), $currentId, $newId));
         $definition->setMethodCalls($this->updateArgumentReferences($definition->getMethodCalls(), $currentId, $newId));
         $definition->setProperties($this->updateArgumentReferences($definition->getProperties(), $currentId, $newId));
     }
 }
 /**
  * Processes the ContainerBuilder to replace references to aliases with actual service references.
  *
  * @param ehough_iconic_ContainerBuilder $container
  */
 public function process(ehough_iconic_ContainerBuilder $container)
 {
     $this->container = $container;
     foreach ($container->getDefinitions() as $definition) {
         if ($definition->isSynthetic() || $definition->isAbstract()) {
             continue;
         }
         $definition->setArguments($this->processArguments($definition->getArguments()));
         $definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
         $definition->setProperties($this->processArguments($definition->getProperties()));
     }
     foreach ($container->getAliases() as $id => $alias) {
         $aliasId = (string) $alias;
         if ($aliasId !== ($defId = $this->getDefinitionId($aliasId))) {
             $container->setAlias($id, new ehough_iconic_Alias($defId, $alias->isPublic()));
         }
     }
 }
예제 #7
0
 /**
  * Merges a ContainerBuilder with the current ContainerBuilder configuration.
  *
  * Service definitions overrides the current defined ones.
  *
  * But for parameters, they are overridden by the current ones. It allows
  * the parameters passed to the container constructor to have precedence
  * over the loaded ones.
  *
  * $container = new ContainerBuilder(array('foo' => 'bar'));
  * $loader = new LoaderXXX($container);
  * $loader->load('resource_name');
  * $container->register('foo', new stdClass());
  *
  * In the above example, even if the loaded resource defines a foo
  * parameter, the value will still be 'bar' as defined in the ContainerBuilder
  * constructor.
  *
  * @param ehough_iconic_ContainerBuilder $container The ContainerBuilder instance to merge.
  *
  *
  * @throws ehough_iconic_exception_BadMethodCallException When this ContainerBuilder is frozen
  *
  * @api
  */
 public function merge(ehough_iconic_ContainerBuilder $container)
 {
     if ($this->isFrozen()) {
         throw new ehough_iconic_exception_BadMethodCallException('Cannot merge on a frozen container.');
     }
     $this->addDefinitions($container->getDefinitions());
     $this->addAliases($container->getAliases());
     $this->getParameterBag()->add($container->getParameterBag()->all());
     if ($this->trackResources) {
         foreach ($container->getResources() as $resource) {
             $this->addResource($resource);
         }
     }
     foreach ($this->extensions as $name => $extension) {
         if (!isset($this->extensionConfigs[$name])) {
             $this->extensionConfigs[$name] = array();
         }
         $this->extensionConfigs[$name] = array_merge($this->extensionConfigs[$name], $container->getExtensionConfig($name));
     }
 }