コード例 #1
0
 /**
  * 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();
 }
コード例 #2
0
 /**
  * {@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);
 }
コード例 #3
0
 /**
  * @param ehough_iconic_ContainerBuilder $container
  * @param array            $config
  *
  * @return Boolean Whether the configuration is enabled
  *
  * @throws ehough_iconic_exception_InvalidArgumentException When the config is not enableable
  */
 protected function isConfigEnabled(ehough_iconic_ContainerBuilder $container, array $config)
 {
     if (!array_key_exists('enabled', $config)) {
         throw new ehough_iconic_exception_InvalidArgumentException("The config array has no 'enabled' key.");
     }
     return (bool) $container->getParameterBag()->resolveValue($config['enabled']);
 }
コード例 #4
0
ファイル: ContainerBuilder.php プロジェクト: ehough/iconic
 /**
  * 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));
     }
 }