[DI] Fix error when trying to resolve a DefinitionDecorator
This commit is contained in:
parent
ef40651dd3
commit
8e0da2f39e
@ -840,6 +840,10 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
*/
|
||||
public function createService(Definition $definition, $id, $tryProxy = true)
|
||||
{
|
||||
if ('Symfony\Component\DependencyInjection\Definition' !== get_class($definition)) {
|
||||
throw new RuntimeException(sprintf('Constructing service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
|
||||
}
|
||||
|
||||
if ($definition->isSynthetic()) {
|
||||
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id));
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
||||
@ -404,6 +405,20 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($builder->get('foo'), $builder->resolveServices(new Expression('service("foo")')), '->resolveServices() resolves expressions');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
|
||||
*/
|
||||
public function testResolveServicesWithDecoratedDefinition()
|
||||
{
|
||||
$builder = new ContainerBuilder();
|
||||
$builder->setDefinition('grandpa', new Definition('stdClass'));
|
||||
$builder->setDefinition('parent', new DefinitionDecorator('grandpa'));
|
||||
$builder->setDefinition('foo', new DefinitionDecorator('parent'));
|
||||
|
||||
$builder->get('foo');
|
||||
}
|
||||
|
||||
public function testMerge()
|
||||
{
|
||||
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
|
||||
|
Reference in New Issue
Block a user