本文整理汇总了PHP中Symfony\Components\DependencyInjection\BuilderConfiguration::setDefinitions方法的典型用法代码示例。如果您正苦于以下问题:PHP BuilderConfiguration::setDefinitions方法的具体用法?PHP BuilderConfiguration::setDefinitions怎么用?PHP BuilderConfiguration::setDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Components\DependencyInjection\BuilderConfiguration
的用法示例。
在下文中一共展示了BuilderConfiguration::setDefinitions方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDefinitions
public function testDefinitions()
{
$configuration = new BuilderConfiguration();
$definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'));
$configuration->setDefinitions($definitions);
$this->assertEquals($definitions, $configuration->getDefinitions(), '->setDefinitions() sets the service definitions');
$this->assertTrue($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$this->assertFalse($configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$this->assertEquals($foo, $configuration->getDefinition('foobar'), '->getDefinition() returns a service definition if defined');
$this->assertTrue($configuration->setDefinition('foobar', new Definition('FooBarClass')) === $configuration, '->setDefinition() implements a fuild interface');
$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$this->assertEquals(array_merge($definitions, $defs), $configuration->getDefinitions(), '->addDefinitions() adds the service definitions');
try {
$configuration->getDefinition('baz');
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
} catch (\Exception $e) {
$this->assertInstanceOf('\\InvalidArgumentException', $e, '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
$this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
}
示例2: array
}
$configuration->setAlias('barbar', 'foofoo');
$t->is($configuration->getAliases(), array('bar' => 'foo', 'barbar' => 'foofoo'), '->getAliases() returns an array of all defined aliases');
$configuration->addAliases(array('foo' => 'bar'));
$t->is($configuration->getAliases(), array('bar' => 'foo', 'barbar' => 'foofoo', 'foo' => 'bar'), '->addAliases() adds some aliases');
// ->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()
$t->diag('->setDefinitions() ->addDefinitions() ->getDefinitions() ->setDefinition() ->getDefinition() ->hasDefinition()');
$configuration = new BuilderConfiguration();
$definitions = array(
'foo' => new Definition('FooClass'),
'bar' => new Definition('BarClass'),
);
$configuration->setDefinitions($definitions);
$t->is($configuration->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
$t->ok($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$t->ok(!$configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$t->is($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$t->ok($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$t->is($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
try
{
$configuration->getDefinition('baz');
$t->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
示例3: testDefinitions
public function testDefinitions()
{
$configuration = new BuilderConfiguration();
$definitions = array('foo' => new Definition('FooClass'), 'bar' => new Definition('BarClass'));
$configuration->setDefinitions($definitions);
$this->assertEquals($configuration->getDefinitions(), $definitions, '->setDefinitions() sets the service definitions');
$this->assertTrue($configuration->hasDefinition('foo'), '->hasDefinition() returns true if a service definition exists');
$this->assertTrue(!$configuration->hasDefinition('foobar'), '->hasDefinition() returns false if a service definition does not exist');
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$this->assertEquals($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$this->assertTrue($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');
$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$this->assertEquals($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');
try {
$configuration->getDefinition('baz');
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
} catch (\InvalidArgumentException $e) {
}
}