Skip to content

Commit 3eb8a34

Browse files
bug symfony#20609 [DI] Fixed custom services definition BC break introduced in ec7e70fb… (kiler129)
This PR was squashed before being merged into the 2.7 branch (closes symfony#20609). Discussion ---------- [DI] Fixed custom services definition BC break introduced in ec7e70fb… | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no, fixes previous BC | Deprecations? | no | Tests pass? | yes (verified on Win only) | Fixed tickets | symfony#20608 | License | MIT | Doc PR | - Commits ------- 7a5e11e [DI] Fixed custom services definition BC break introduced in ec7e70fb…
2 parents af9c279 + 7a5e11e commit 3eb8a34

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 service "%s" from a parent definition is not supported at build time.', $id));
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
@@ -419,7 +420,7 @@ public function testResolveServices()
419420

420421
/**
421422
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
422-
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
423+
* @expectedExceptionMessage Constructing service "foo" from a parent definition is not supported at build time.
423424
*/
424425
public function testResolveServicesWithDecoratedDefinition()
425426
{
@@ -431,6 +432,14 @@ public function testResolveServicesWithDecoratedDefinition()
431432
$builder->get('foo');
432433
}
433434

435+
public function testResolveServicesWithCustomDefinitionClass()
436+
{
437+
$builder = new ContainerBuilder();
438+
$builder->setDefinition('foo', new CustomDefinition('stdClass'));
439+
440+
$this->assertInstanceOf('stdClass', $builder->get('foo'));
441+
}
442+
434443
public function testMerge()
435444
{
436445
$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)