本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::merge方法的具体用法?PHP ContainerBuilder::merge怎么用?PHP ContainerBuilder::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::merge方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMergingContainsHaveAllServicesAfterCompilation
/** @dataProvider provideAllServicesDefined */
public function testMergingContainsHaveAllServicesAfterCompilation($definitionId)
{
$container2 = new ContainerBuilder();
$container2->merge($this->container);
$container2->compile();
$this->assertTrue($container2->hasDefinition($definitionId));
}
示例2: load
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$extensionManager = new ExtensionManager();
foreach ($configs as $config) {
if (!isset($config['extensions'])) {
continue;
}
foreach ($config['extensions'] as $config) {
if (!isset($config['class'])) {
continue;
}
$extensionManager->activateExtension($config['class']);
}
}
$configuration = new Configuration($extensionManager->getActivatedExtensions());
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../resources'));
$loader->load('services.xml');
foreach ($extensionManager->getActivatedExtensions() as $extension) {
$extensionConfig = $config['extensions'][$extension->getName()];
$tempContainer = new ContainerBuilder(new ParameterBag(array()));
$tempContainer->addObjectResource($extension);
// load extension into temporary container
$extension->load($extensionConfig, $tempContainer);
// merge temporary container into normal one
$container->merge($tempContainer);
}
$settings = $this->createSettings($config);
$configurationDefinition = $container->findDefinition('pdepend.configuration');
$configurationDefinition->setArguments(array($settings));
}
示例3: resolve
private function resolve(Definition $definition)
{
if (!$this->container->isFrozen()) {
throw new \LogicException("cannot use create method on factory without freezing/compiling container");
}
$subContainer = new ContainerBuilder();
$subContainer->merge($this->container);
$subContainer->setDefinition("__tmp__", $definition);
$subContainer->compile();
$obj = $subContainer->get("__tmp__");
return $obj;
}
示例4: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
$parameters = $container->getParameterBag()->all();
$definitions = $container->getDefinitions();
$aliases = $container->getAliases();
foreach ($container->getExtensions() as $name => $extension) {
$tmpContainer = new ContainerBuilder($container->getParameterBag());
$tmpContainer->addObjectResource($extension);
$extension->load($container->getExtensionConfig($name), $tmpContainer);
$container->merge($tmpContainer);
}
$container->addDefinitions($definitions);
$container->addAliases($aliases);
$container->getParameterBag()->add($parameters);
}
示例5: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
$parameters = $container->getParameterBag()->all();
$definitions = $container->getDefinitions();
$aliases = $container->getAliases();
foreach ($container->getExtensionConfigs() as $name => $configs) {
list($namespace, $tag) = explode(':', $name);
$extension = $container->getExtension($namespace);
$tmpContainer = new ContainerBuilder($container->getParameterBag());
$tmpContainer->addObjectResource($extension);
$extension->load($tag, $configs, $tmpContainer);
$container->merge($tmpContainer);
}
$container->addDefinitions($definitions);
$container->addAliases($aliases);
$container->getParameterBag()->add($parameters);
}
示例6: process
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
$parameters = $container->getParameterBag()->all();
$definitions = $container->getDefinitions();
$aliases = $container->getAliases();
foreach ($container->getExtensions() as $name => $extension) {
if (!($config = $container->getExtensionConfig($name))) {
// this extension was not called
continue;
}
$config = $container->getParameterBag()->resolveValue($config);
$tmpContainer = new ContainerBuilder($container->getParameterBag());
$tmpContainer->addObjectResource($extension);
$extension->load($config, $tmpContainer);
$container->merge($tmpContainer);
}
$container->addDefinitions($definitions);
$container->addAliases($aliases);
$container->getParameterBag()->add($parameters);
}
示例7: testMergeLogicException
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::merge
* @expectedException \LogicException
*/
public function testMergeLogicException()
{
$container = new ContainerBuilder();
$container->setResourceTracking(false);
$container->compile();
$container->merge(new ContainerBuilder());
}
示例8: loadExtensionsConfiguration
/**
* Loads extensions configuration.
*
* @param array $config
* @param ContainerBuilder $container
*/
protected function loadExtensionsConfiguration(array $config, ContainerBuilder $container)
{
foreach ($config as $id => $extensionConfig) {
// load extension from manager
$extension = $this->extensionManager->getExtension($id);
// create temporary container
$tempContainer = new ContainerBuilder(new ParameterBag(array('behat.paths.base' => $container->getParameter('behat.paths.base'), 'behat.extension.classes' => $container->getParameter('behat.extension.classes'))));
$tempContainer->addObjectResource($extension);
// load extension into temporary container
$extension->load($extensionConfig, $tempContainer);
// merge temporary container into normal one
$container->merge($tempContainer);
// add extension compiler passes
array_map(array($container, 'addCompilerPass'), $extension->getCompilerPasses());
}
}
示例9: mergeContainer
public function mergeContainer(Container $container)
{
$this->container->merge($container);
}
示例10: testMergeLogicException
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::merge
* @expectedException LogicException
*/
public function testMergeLogicException()
{
$container = new ContainerBuilder();
$container->compile();
$container->merge(new ContainerBuilder());
}
示例11: testMerge
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::merge
*/
public function testMerge()
{
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
$config = new ContainerBuilder(new ParameterBag(array('foo' => 'bar')));
$container->merge($config);
$this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $container->getParameterBag()->all(), '->merge() merges current parameters with the loaded ones');
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
$config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%')));
$container->merge($config);
////// FIXME
$container->freeze();
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
$config = new ContainerBuilder(new ParameterBag(array('foo' => '%bar%', 'baz' => '%foo%')));
$container->merge($config);
////// FIXME
$container->freeze();
$this->assertEquals(array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new ContainerBuilder();
$container->register('foo', 'FooClass');
$container->register('bar', 'BarClass');
$config = new ContainerBuilder();
$config->setDefinition('baz', new Definition('BazClass'));
$config->setAlias('alias_for_foo', 'foo');
$container->merge($config);
$this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
$this->assertEquals(array('alias_for_foo' => 'foo'), $container->getAliases(), '->merge() registers defined aliases');
$container = new ContainerBuilder();
$container->register('foo', 'FooClass');
$config->setDefinition('foo', new Definition('BazClass'));
$container->merge($config);
$this->assertEquals('BazClass', $container->getDefinition('foo')->getClass(), '->merge() overrides already defined services');
}
示例12: prepend
/**
* Allow an extension to prepend the extension configurations.
*
* @param ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container)
{
if (!$this instanceof EntitiesOverridableExtensionInterface) {
return;
}
$mappingConfiguration = $this->getConfigurationInstance();
if ($mappingConfiguration instanceof ConfigurationInterface) {
$config = $container->getExtensionConfig($this::getExtensionName());
$config = $container->getParameterBag()->resolveValue($config);
$tmpContainer = new ContainerBuilder($container->getParameterBag());
$tmpContainer->setResourceTracking($container->isTrackingResources());
$tmpContainer->addObjectResource($this);
$this->loadMappingConfiguration($tmpContainer, $mappingConfiguration, $config);
$container->merge($tmpContainer);
}
/**
* Perform overrides for Doctrine ORM mapping resolves
*/
$overrides = $this->getEntitiesOverrides();
foreach ($overrides as $interface => $override) {
$overrides[$interface] = $container->getParameter($override);
}
$container->prependExtensionConfig('doctrine', ['orm' => ['resolve_target_entities' => $overrides]]);
}
示例13: testMergeLogicException
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::merge
* @expectedException LogicException
*/
public function testMergeLogicException()
{
if (!class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
$this->markTestSkipped('The "Config" component is not available');
}
$container = new ContainerBuilder();
$container->compile();
$container->merge(new ContainerBuilder());
}
示例14: loadExtensionsConfiguration
/**
* Loads extensions configuration.
*
* @param array $config
* @param ContainerBuilder $container
*/
protected function loadExtensionsConfiguration(array $config, ContainerBuilder $container)
{
foreach ($config as $id => $extensionConfig) {
// create temporary container
$tempContainer = new ContainerBuilder();
$tempContainer->setParameter('behat.paths.base', $this->basePath);
// load extension into it
$extension = $this->extensionManager->getExtension($id);
$extension->load($extensionConfig, $tempContainer);
// merge temporary container into normal one
$container->merge($tempContainer);
// add extension compiler passes
array_map(array($container, 'addCompilerPass'), $extension->getCompilerPasses());
}
}