Skip to content

Commit 87598e2

Browse files
Merge branch '2.8' into 3.1
* 2.8: [ci] Testing with UTC hides bugs [DI] Fix error when trying to resolve a DefinitionDecorator [DoctrineBridge] Fix deprecation message/documentation of implementing UserProviderInterface using the entity provider [Validator] improve and added more Indonesian translation.
2 parents e5e5273 + 9d2c503 commit 87598e2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ContainerBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,10 @@ public function findDefinition($id)
794794
*/
795795
private function createService(Definition $definition, $id, $tryProxy = true)
796796
{
797+
if ('Symfony\Component\DependencyInjection\Definition' !== get_class($definition)) {
798+
throw new RuntimeException(sprintf('Constructing service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
799+
}
800+
797801
if ($definition->isSynthetic()) {
798802
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id));
799803
}

Tests/ContainerBuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\ContainerInterface;
2121
use Symfony\Component\DependencyInjection\Definition;
22+
use Symfony\Component\DependencyInjection\DefinitionDecorator;
2223
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2324
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
2425
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
@@ -380,6 +381,20 @@ public function testResolveServices()
380381
$this->assertEquals($builder->get('foo'), $builder->resolveServices(new Expression('service("foo")')), '->resolveServices() resolves expressions');
381382
}
382383

384+
/**
385+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
386+
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
387+
*/
388+
public function testResolveServicesWithDecoratedDefinition()
389+
{
390+
$builder = new ContainerBuilder();
391+
$builder->setDefinition('grandpa', new Definition('stdClass'));
392+
$builder->setDefinition('parent', new DefinitionDecorator('grandpa'));
393+
$builder->setDefinition('foo', new DefinitionDecorator('parent'));
394+
395+
$builder->get('foo');
396+
}
397+
383398
public function testMerge()
384399
{
385400
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));

0 commit comments

Comments
 (0)