Skip to content

Commit 7a5e11e

Browse files
kiler129nicolas-grekas
authored andcommitted
[DI] Fixed custom services definition BC break introduced in ec7e70fb…
1 parent 30d161c commit 7a5e11e

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,8 @@ public function findDefinition($id)
840840
*/
841841
public function createService(Definition $definition, $id, $tryProxy = true)
842842
{
843-
if ('Symfony\Component\DependencyInjection\Definition' !== get_class($definition)) {
844-
throw new RuntimeException(sprintf('Constructing service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
843+
if ($definition instanceof DefinitionDecorator) {
844+
throw new RuntimeException(sprintf('Constructing decorated service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
845845
}
846846

847847
if ($definition->isSynthetic()) {

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
3030
use Symfony\Component\DependencyInjection\Scope;
3131
use Symfony\Component\Config\Resource\FileResource;
32+
use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition;
3233
use Symfony\Component\ExpressionLanguage\Expression;
3334

3435
class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
@@ -407,7 +408,7 @@ public function testResolveServices()
407408

408409
/**
409410
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
410-
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
411+
* @expectedExceptionMessage Constructing decorated service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
411412
*/
412413
public function testResolveServicesWithDecoratedDefinition()
413414
{
@@ -419,6 +420,14 @@ public function testResolveServicesWithDecoratedDefinition()
419420
$builder->get('foo');
420421
}
421422

423+
public function testResolveServicesWithCustomDefinitionClass()
424+
{
425+
$builder = new ContainerBuilder();
426+
$builder->setDefinition('foo', new CustomDefinition('stdClass'));
427+
428+
$this->assertInstanceOf('stdClass', $builder->get('foo'));
429+
}
430+
422431
public function testMerge()
423432
{
424433
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
13+
14+
use Symfony\Component\DependencyInjection\Definition;
15+
16+
class CustomDefinition extends Definition
17+
{
18+
}

0 commit comments

Comments
 (0)