/** * 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. */ public function merge(ContainerBuilder $container) { if (true === $this->isFrozen()) { throw new \LogicException('Cannot merge on a frozen container.'); } $this->addDefinitions($container->getDefinitions()); $this->addAliases($container->getAliases()); $this->parameterBag->add($container->getParameterBag()->all()); foreach ($container->getResources() as $resource) { $this->addResource($resource); } foreach ($container->getExtensionContainers() as $name => $container) { if (isset($this->extensionContainers[$name])) { $this->extensionContainers[$name]->merge($container); } else { $this->extensionContainers[$name] = $container; } } }
/** * @covers Symfony\Components\DependencyInjection\ContainerBuilder::getResources * @covers Symfony\Components\DependencyInjection\ContainerBuilder::addResource */ public function testResources() { $container = new ContainerBuilder(); $container->addResource($a = new FileResource(__DIR__ . '/Fixtures/xml/services1.xml')); $container->addResource($b = new FileResource(__DIR__ . '/Fixtures/xml/services2.xml')); $this->assertEquals(array($a, $b), $container->getResources(), '->getResources() returns an array of resources read for the current configuration'); }