示例#1
0
 /**
  * Merges a BuilderConfiguration with the current Builder 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 Builder(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 builder
  * constructor.
  */
 public function merge(BuilderConfiguration $configuration = null)
 {
     if (null === $configuration) {
         return;
     }
     $this->addDefinitions($configuration->getDefinitions());
     $this->addAliases($configuration->getAliases());
     $parameterBag = $this->getParameterBag();
     $currentParameters = $parameterBag->all();
     foreach ($configuration->getParameterBag()->all() as $key => $value) {
         $parameterBag->set($key, $value);
     }
     $parameterBag->add($currentParameters);
     foreach ($parameterBag->all() as $key => $value) {
         $parameterBag->set($key, self::resolveValue($value, $this->getParameterBag()->all()));
     }
 }