From 4197696d419362ca09c94d16e4919f2a7dfe3993 Mon Sep 17 00:00:00 2001 From: kiler129 Date: Wed, 23 Nov 2016 11:45:56 -0600 Subject: [PATCH 1/3] [DI] Fixed custom services definition BC break introduced in ec7e70fb2b1a8c6263528b5ffa1f065e510e4f88 --- .../DependencyInjection/ContainerBuilder.php | 4 ++-- .../Tests/ContainerBuilderTest.php | 11 +++++++++- .../Tests/Fixtures/CustomDefinition.php | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/CustomDefinition.php diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 7c9f5a243190a..28ff635854b48 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -840,8 +840,8 @@ public function findDefinition($id) */ 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()) { diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 8f8c8b179f790..7da5e01e4afce 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -29,6 +29,7 @@ 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 @@ public function testResolveServices() /** * @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 @@ public function testResolveServicesWithDecoratedDefinition() $builder->get('foo'); } + public function testResolveServicesWithCustomDefinitionClass() + { + $builder = new ContainerBuilder(); + $builder->setDefinition('foo', new CustomDefinition(\stdClass::class)); + + $this->assertInstanceOf(\stdClass::class, $builder->get('foo')); + } + public function testMerge() { $container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo'))); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CustomDefinition.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CustomDefinition.php new file mode 100644 index 0000000000000..3aac54ff6abdb --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CustomDefinition.php @@ -0,0 +1,20 @@ + + * + * 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 +{ + +} From 0222936fe559df48d4a44820a6faf150b6472164 Mon Sep 17 00:00:00 2001 From: kiler129 Date: Wed, 23 Nov 2016 11:54:35 -0600 Subject: [PATCH 2/3] [DI] Fixed CS --- .../DependencyInjection/Tests/Fixtures/CustomDefinition.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CustomDefinition.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CustomDefinition.php index 3aac54ff6abdb..65eea2106ed70 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CustomDefinition.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/CustomDefinition.php @@ -11,10 +11,8 @@ namespace Symfony\Component\DependencyInjection\Tests\Fixtures; - use Symfony\Component\DependencyInjection\Definition; class CustomDefinition extends Definition { - } From 8325f1889078a84708da5f6e19d8e1676d2d12f9 Mon Sep 17 00:00:00 2001 From: kiler129 Date: Wed, 23 Nov 2016 11:57:57 -0600 Subject: [PATCH 3/3] [DI] Fixed for older PHPs --- .../DependencyInjection/Tests/ContainerBuilderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 7da5e01e4afce..cb91eb50ed2d9 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -423,9 +423,9 @@ public function testResolveServicesWithDecoratedDefinition() public function testResolveServicesWithCustomDefinitionClass() { $builder = new ContainerBuilder(); - $builder->setDefinition('foo', new CustomDefinition(\stdClass::class)); + $builder->setDefinition('foo', new CustomDefinition('stdClass')); - $this->assertInstanceOf(\stdClass::class, $builder->get('foo')); + $this->assertInstanceOf('stdClass', $builder->get('foo')); } public function testMerge()