本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::setDefinitions方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::setDefinitions方法的具体用法?PHP ContainerBuilder::setDefinitions怎么用?PHP ContainerBuilder::setDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::setDefinitions方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Processes the ContainerBuilder for inline service definitions.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$this->compiler = $container->getCompiler();
$this->formatter = $this->compiler->getLoggingFormatter();
$this->graph = $this->compiler->getServiceReferenceGraph();
$container->setDefinitions($this->inlineArguments($container, $container->getDefinitions(), true));
}
示例2: getContainerBuilders
public static function getContainerBuilders()
{
$builder1 = new ContainerBuilder();
$builder1->setDefinitions(self::getContainerDefinitions());
$builder1->setAliases(self::getContainerAliases());
return array('builder_1' => $builder1);
}
示例3: testDefinitions
/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::setDefinitions
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getDefinitions
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::setDefinition
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getDefinition
*/
public function testDefinitions()
{
$builder = new ContainerBuilder();
$definitions = array(
'foo' => new Definition('Bar\FooClass'),
'bar' => new Definition('BarClass'),
);
$builder->setDefinitions($definitions);
$this->assertEquals($definitions, $builder->getDefinitions(), '->setDefinitions() sets the service definitions');
$this->assertTrue($builder->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$this->assertFalse($builder->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$builder->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$this->assertEquals($foo, $builder->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
$this->assertTrue($builder->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fluid interface by returning the service reference');
$builder->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$this->assertEquals(array_merge($definitions, $defs), $builder->getDefinitions(), '->addDefinitions() adds the service definitions');
try {
$builder->getDefinition('baz');
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
} catch (\InvalidArgumentException $e) {
$this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
}
示例4: process
/**
* Process the ContainerBuilder to replace ChildDefinition instances with their real Definition instances.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$this->compiler = $container->getCompiler();
$this->formatter = $this->compiler->getLoggingFormatter();
$container->setDefinitions($this->resolveArguments($container, $container->getDefinitions(), true));
}
示例5: cloneContainer
private function cloneContainer()
{
$parameterBag = new ParameterBag($this->container->getParameterBag()->all());
$container = new ContainerBuilder($parameterBag);
$container->setDefinitions($this->container->getDefinitions());
$container->setAliases($this->container->getAliases());
$container->setResources($this->container->getResources());
foreach ($this->container->getExtensions() as $extension) {
$container->registerExtension($extension);
}
return $container;
}
示例6: testProcess
public function testProcess()
{
$container = new ContainerBuilder();
$container->setParameter('ezpublish.config_resolver.updateable_services', array());
$updateableServices = array();
$def1Arg1 = 'foo';
$def1Arg2 = new Reference('foo.bar');
$def1 = new Definition('stdClass', array($def1Arg1, $def1Arg2));
$def2 = new Definition('stdClass', array('$bar;some_namespace$', array()));
$def3 = new Definition('stdClass', array('$content.default_ttl;ezsettings;ezdemo_site_admin$'));
$def4 = new Definition('stdClass', array('$languages$'));
$def5Arg1 = new Reference('def3');
$def5 = new Definition('stdClass', array($def5Arg1));
$def6Arg1 = new Reference('def1');
$def6Arg2 = new Reference('def4');
$def6 = new Definition('stdClass', array($def6Arg1, $def6Arg2));
$def7MethodCalls = array(array('setFoo', array('something', new Reference('def1'))), array('setBar', array(array('baz'))));
$def7 = new Definition('stdClass');
$def7->setMethodCalls($def7MethodCalls);
$def8MethodCalls = array(array('setFoo', array('$foo$')), array('setBar', array('$bar;baz$')));
$def8 = new Definition('stdClass');
$def8->setMethodCalls($def8MethodCalls);
$container->setDefinitions(array('def1' => $def1, 'def2' => $def2, 'def3' => $def3, 'def4' => $def4, 'def5' => $def5, 'def6' => $def6, 'def7' => $def7, 'def8' => $def8));
$configResolverPass = new ConfigResolverParameterPass(new DynamicSettingParser());
$configResolverPass->process($container);
// Ensure that non concerned services stayed untouched.
self::assertSame($def1Arg1, $def1->getArgument(0));
self::assertSame($def1Arg2, $def1->getArgument(1));
self::assertSame($def1, $container->getDefinition('def1'));
self::assertSame($def5Arg1, $def5->getArgument(0));
self::assertSame($def5, $container->getDefinition('def5'));
self::assertSame($def6Arg1, $def6->getArgument(0));
self::assertSame($def6Arg2, $def6->getArgument(1));
self::assertSame($def6, $container->getDefinition('def6'));
self::assertSame($def7MethodCalls, $def7->getMethodCalls());
self::assertSame($def7, $container->getDefinition('def7'));
// Check that concerned services arguments have been correctly transformed.
$def2arg1 = $def2->getArgument(0);
self::assertInstanceOf('Symfony\\Component\\ExpressionLanguage\\Expression', $def2arg1);
self::assertSame('service("ezpublish.config.resolver").getParameter("bar", "some_namespace", null)', (string) $def2arg1);
// Also check 2nd argument
self::assertSame(array(), $def2->getArgument(1));
$def3arg1 = $def3->getArgument(0);
self::assertInstanceOf('Symfony\\Component\\ExpressionLanguage\\Expression', $def3arg1);
self::assertSame('service("ezpublish.config.resolver").getParameter("content.default_ttl", "ezsettings", "ezdemo_site_admin")', (string) $def3arg1);
$def4arg1 = $def4->getArgument(0);
self::assertInstanceOf('Symfony\\Component\\ExpressionLanguage\\Expression', $def4arg1);
self::assertSame('service("ezpublish.config.resolver").getParameter("languages", null, null)', (string) $def4arg1);
$def8Calls = $def8->getMethodCalls();
self::assertSame(count($def8MethodCalls), count($def8Calls));
self::assertSame($def8MethodCalls[0][0], $def8Calls[0][0]);
self::assertInstanceOf('Symfony\\Component\\ExpressionLanguage\\Expression', $def8Calls[0][1][0]);
$exprSetFoo = 'service("ezpublish.config.resolver").getParameter("foo", null, null)';
self::assertSame($exprSetFoo, (string) $def8Calls[0][1][0]);
self::assertSame($def8MethodCalls[1][0], $def8Calls[1][0]);
self::assertInstanceOf('Symfony\\Component\\ExpressionLanguage\\Expression', $def8Calls[1][1][0]);
$exprSetBar = 'service("ezpublish.config.resolver").getParameter("bar", "baz", null)';
self::assertSame($exprSetBar, (string) $def8Calls[1][1][0]);
$updateableServices['def8'] = array(array('setFoo', $exprSetFoo), array('setBar', $exprSetBar));
self::assertTrue($container->hasParameter('ezpublish.config_resolver.resettable_services'));
self::assertEquals(array('def2', 'def3', 'def4', 'def5', 'def6'), $container->getParameter('ezpublish.config_resolver.resettable_services'));
self::assertEquals($updateableServices, $container->getParameter('ezpublish.config_resolver.updateable_services'));
}
示例7: setDefinitions
public function setDefinitions(array $definitions)
{
return $this->delegate->setDefinitions($definitions);
}
示例8: testProcess
public function testProcess()
{
$container = new ContainerBuilder();
$dynamicSettingsServices = array();
$def1Arg1 = 'foo';
$def1Arg2 = new Reference('foo.bar');
$def1 = new Definition('stdClass', array($def1Arg1, $def1Arg2));
$def2 = new Definition('stdClass', array('$bar;some_namespace$', array()));
$def3 = new Definition('stdClass', array('$content.default_ttl;ezsettings;ezdemo_site_admin$'));
$def4 = new Definition('stdClass', array('$languages$'));
$def5Arg1 = new Reference('def3');
$def5 = new Definition('stdClass', array($def5Arg1));
$def6Arg1 = new Reference('def1');
$def6Arg2 = new Reference('def4');
$def6 = new Definition('stdClass', array($def6Arg1, $def6Arg2));
$def7MethodCalls = array(array('setFoo', array('something', new Reference('def1'))), array('setBar', array(array('baz'))));
$def7 = new Definition('stdClass');
$def7->setMethodCalls($def7MethodCalls);
$def8MethodCalls = array(array('setFoo', array('$foo$')), array('setBar', array('$bar;baz$')));
$def8 = new Definition('stdClass');
$def8->setMethodCalls($def8MethodCalls);
$container->setDefinitions(array('def1' => $def1, 'def2' => $def2, 'def3' => $def3, 'def4' => $def4, 'def5' => $def5, 'def6' => $def6, 'def7' => $def7, 'def8' => $def8));
$configResolverPass = new ConfigResolverParameterPass(new DynamicSettingParser());
$configResolverPass->process($container);
// Ensure that non concerned services stayed untouched.
$this->assertSame($def1Arg1, $def1->getArgument(0));
$this->assertSame($def1Arg2, $def1->getArgument(1));
$this->assertSame($def1, $container->getDefinition('def1'));
$this->assertSame($def5Arg1, $def5->getArgument(0));
$this->assertSame($def5, $container->getDefinition('def5'));
$this->assertSame($def6Arg1, $def6->getArgument(0));
$this->assertSame($def6Arg2, $def6->getArgument(1));
$this->assertSame($def6, $container->getDefinition('def6'));
$this->assertSame($def7MethodCalls, $def7->getMethodCalls());
$this->assertSame($def7, $container->getDefinition('def7'));
// Check that concerned services arguments have been correctly transformed.
/** @var Reference $def2arg1 */
$def2arg1 = $def2->getArgument(0);
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $def2arg1);
$expectedServiceHelperId1 = 'ezpublish.config_resolver.fake.bar_some_namespace_';
$dynamicSettingsServices[] = $expectedServiceHelperId1;
$this->assertSame((string) $def2arg1, $expectedServiceHelperId1);
$this->assertTrue($container->has($expectedServiceHelperId1));
$defHelper1 = $container->getDefinition($expectedServiceHelperId1);
$this->assertSame('ezpublish.config.resolver', $defHelper1->getFactoryService());
$this->assertSame('getParameter', $defHelper1->getFactoryMethod());
$this->assertSame(array('bar', 'some_namespace', null), $defHelper1->getArguments());
// Also check 2nd argument
$this->assertSame(array(), $def2->getArgument(1));
/** @var Reference $def3arg1 */
$def3arg1 = $def3->getArgument(0);
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $def3arg1);
$expectedServiceHelperId2 = 'ezpublish.config_resolver.fake.content.default_ttl_ezsettings_ezdemo_site_admin';
$dynamicSettingsServices[] = $expectedServiceHelperId2;
$this->assertSame((string) $def3arg1, $expectedServiceHelperId2);
$this->assertTrue($container->has($expectedServiceHelperId2));
$defHelper2 = $container->getDefinition($expectedServiceHelperId2);
$this->assertSame('ezpublish.config.resolver', $defHelper2->getFactoryService());
$this->assertSame('getParameter', $defHelper2->getFactoryMethod());
$this->assertSame(array('content.default_ttl', 'ezsettings', 'ezdemo_site_admin'), $defHelper2->getArguments());
/** @var Reference $def4arg1 */
$def4arg1 = $def4->getArgument(0);
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $def4arg1);
$expectedServiceHelperId3 = 'ezpublish.config_resolver.fake.languages__';
$dynamicSettingsServices[] = $expectedServiceHelperId3;
$this->assertSame((string) $def4arg1, $expectedServiceHelperId3);
$this->assertTrue($container->has($expectedServiceHelperId3));
$defHelper3 = $container->getDefinition($expectedServiceHelperId3);
$this->assertSame('ezpublish.config.resolver', $defHelper3->getFactoryService());
$this->assertSame('getParameter', $defHelper3->getFactoryMethod());
$this->assertSame(array('languages', null, null), $defHelper3->getArguments());
/** @var Reference $def4arg1 */
$def8Calls = $def8->getMethodCalls();
$this->assertSame(count($def8MethodCalls), count($def8Calls));
$this->assertSame($def8MethodCalls[0][0], $def8Calls[0][0]);
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $def8Calls[0][1][0]);
$expectedServiceHelperId4 = 'ezpublish.config_resolver.fake.foo__';
$dynamicSettingsServices[] = $expectedServiceHelperId4;
$this->assertSame((string) $def8Calls[0][1][0], $expectedServiceHelperId4);
$this->assertTrue($container->has($expectedServiceHelperId4));
$defHelper4 = $container->getDefinition($expectedServiceHelperId4);
$this->assertSame('ezpublish.config.resolver', $defHelper4->getFactoryService());
$this->assertSame('getParameter', $defHelper4->getFactoryMethod());
$this->assertSame(array('foo', null, null), $defHelper4->getArguments());
$this->assertSame($def8MethodCalls[1][0], $def8Calls[1][0]);
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $def8Calls[1][1][0]);
$expectedServiceHelperId5 = 'ezpublish.config_resolver.fake.bar_baz_';
$dynamicSettingsServices[] = $expectedServiceHelperId5;
$this->assertSame((string) $def8Calls[1][1][0], $expectedServiceHelperId5);
$this->assertTrue($container->has($expectedServiceHelperId5));
$defHelper5 = $container->getDefinition($expectedServiceHelperId5);
$this->assertSame('ezpublish.config.resolver', $defHelper5->getFactoryService());
$this->assertSame('getParameter', $defHelper5->getFactoryMethod());
$this->assertSame(array('bar', 'baz', null), $defHelper5->getArguments());
$this->assertTrue($container->hasParameter('ezpublish.config_resolver.resettable_services'));
$this->assertEquals(array('def2', 'def3', 'def4', 'def5', 'def6'), $container->getParameter('ezpublish.config_resolver.resettable_services'));
$this->assertTrue($container->hasParameter('ezpublish.config_resolver.dynamic_settings_services'));
$this->assertEquals($dynamicSettingsServices, $container->getParameter('ezpublish.config_resolver.dynamic_settings_services'));
}
示例9: setUp
protected function setUp()
{
$this->containerBuilder = new ContainerBuilder();
$this->containerBuilder->setDefinitions(['twig.social.renderer' => new Definition(null, [0, 1]), 'social.publishing.repository' => new Definition(null, [0, 1, 2]), 'social.netizen.repository' => new Definition(null, [0, 1, 2]), 'social.private_message.repository' => new Definition(null, [0, 1, 2]), 'social.abusereport.repository' => new Definition(null, [0, 1, 2]), 'security.netizen.provider' => new Definition(null, [0, 1])]);
$this->sut = new ImportAliases();
}
示例10: load
/**
* Loads a specific configuration.
*
* @param array $config An array of configuration values
* @param ContainerBuilder $container A ContainerBuilder instance
*
* @throws \InvalidArgumentException When provided tag is not defined in this extension
*
* @api
*/
public function load(array $config, ContainerBuilder $container)
{
$config = $this->processConfiguration(new Configuration(), $config);
$container->setDefinitions(array('mongodb.document_manager' => $this->getManagerDefinition(), 'mongodb.connection' => $this->getConnectionDefinition($config), 'mongodb.configuration' => $this->getConfigurationDefinition($config)));
}
示例11: setDefinitions
/**
* Sets the service definitions.
*
* @param tubepress_api_ioc_DefinitionInterface[] $definitions An array of service definitions
*
* @api
* @since 4.0.0
*/
public function setDefinitions(array $definitions)
{
$symfonyDefinitions = array_map(array($this, 'toSymfonyDefinition'), $definitions);
$this->_delegateContainerBuilder->setDefinitions($symfonyDefinitions);
}