[DI] Fixed custom services definition BC break introduced in ec7e70fb…

This commit is contained in:
kiler129 2016-11-23 11:45:56 -06:00 committed by Nicolas Grekas
parent 30d161c0ae
commit 7a5e11eb12
3 changed files with 30 additions and 3 deletions

View File

@ -840,8 +840,8 @@ 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 instanceof DefinitionDecorator) {
throw new RuntimeException(sprintf('Constructing decorated service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
}
if ($definition->isSynthetic()) {

View File

@ -29,6 +29,7 @@ use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
use Symfony\Component\ExpressionLanguage\Expression;
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
@ -407,7 +408,7 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
* @expectedExceptionMessage Constructing decorated service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
*/
public function testResolveServicesWithDecoratedDefinition()
{
@ -419,6 +420,14 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
$builder->get('foo');
}
public function testResolveServicesWithCustomDefinitionClass()
{
$builder = new ContainerBuilder();
$builder->setDefinition('foo', new CustomDefinition('stdClass'));
$this->assertInstanceOf('stdClass', $builder->get('foo'));
}
public function testMerge()
{
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));

View File

@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
use Symfony\Component\DependencyInjection\Definition;
class CustomDefinition extends Definition
{
}