Merge branch '2.3' into 2.6
* 2.3: [DependencyInjection] fixed service resolution for factories Conflicts: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
This commit is contained in:
commit
d2fc77e4d1
@ -37,6 +37,7 @@ class ResolveParameterPlaceHoldersPass implements CompilerPassInterface
|
||||
$definition->setClass($parameterBag->resolveValue($definition->getClass()));
|
||||
$definition->setFile($parameterBag->resolveValue($definition->getFile()));
|
||||
$definition->setArguments($parameterBag->resolveValue($definition->getArguments()));
|
||||
$definition->setFactoryClass($parameterBag->resolveValue($definition->getFactoryClass()));
|
||||
|
||||
$calls = array();
|
||||
foreach ($definition->getMethodCalls() as $name => $arguments) {
|
||||
|
@ -1332,7 +1332,9 @@ EOF;
|
||||
if (null !== $value->getFactoryClass()) {
|
||||
return sprintf("call_user_func(array(%s, '%s')%s)", $this->dumpValue($value->getFactoryClass()), $value->getFactoryMethod(), count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
|
||||
} elseif (null !== $value->getFactoryService()) {
|
||||
return sprintf("%s->%s(%s)", $this->getServiceCall($value->getFactoryService()), $value->getFactoryMethod(), implode(', ', $arguments));
|
||||
$service = $this->dumpValue($definition->getFactoryService());
|
||||
|
||||
return sprintf("%s->%s(%s)", 0 === strpos($service, '$') ? sprintf('$this->get(%s)', $service) : $this->getServiceCall($value->getFactoryService()), $value->getFactoryMethod(), implode(', ', $arguments));
|
||||
} else {
|
||||
throw new RuntimeException('Cannot dump definitions which have factory method without factory service or factory class.');
|
||||
}
|
||||
|
@ -331,6 +331,33 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($builder->get('qux')->called, '->createService() calls the factory method to create the service instance');
|
||||
$this->assertTrue($builder->get('bar')->called, '->createService() uses anonymous service as factory');
|
||||
$this->assertTrue($builder->get('baz')->called, '->createService() uses another service as factory');
|
||||
|
||||
$builder
|
||||
->register('foo1', 'Bar\FooClass')
|
||||
->setFactoryClass('%foo_class%')
|
||||
->setFactoryMethod('getInstance')
|
||||
->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')))
|
||||
;
|
||||
$builder->setParameter('value', 'bar');
|
||||
$builder->setParameter('foo_class', 'Bar\FooClass');
|
||||
$this->assertTrue($builder->get('foo1')->called, '->createService() calls the factory method to create the service instance');
|
||||
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar')), $builder->get('foo1')->arguments, '->createService() passes the arguments to the factory method');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
|
||||
*/
|
||||
public function testCreateServiceFactoryService()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$builder->register('foo_service', 'Bar\FooClass');
|
||||
$builder
|
||||
->register('foo', 'Bar\FooClass')
|
||||
->setFactoryService('%foo_service%')
|
||||
->setFactoryMethod('getInstance')
|
||||
;
|
||||
$builder->setParameter('foo_service', 'foo_service');
|
||||
$this->assertTrue($builder->get('foo')->called, '->createService() calls the factory method to create the service instance');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user