Skip to content

Commit 9d2c503

Browse files
Merge branch '2.7' into 2.8
* 2.7: [ci] Testing with UTC hides bugs [DI] Fix error when trying to resolve a DefinitionDecorator [Validator] improve and added more Indonesian translation.
2 parents 447a3c2 + ec7e70f commit 9d2c503

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
@@ -859,6 +859,10 @@ public function findDefinition($id)
859859
*/
860860
public function createService(Definition $definition, $id, $tryProxy = true)
861861
{
862+
if ('Symfony\Component\DependencyInjection\Definition' !== get_class($definition)) {
863+
throw new RuntimeException(sprintf('Constructing service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
864+
}
865+
862866
if ($definition->isSynthetic()) {
863867
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id));
864868
}

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\InactiveScopeException;
2425
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
@@ -430,6 +431,20 @@ public function testResolveServices()
430431
$this->assertEquals($builder->get('foo'), $builder->resolveServices(new Expression('service("foo")')), '->resolveServices() resolves expressions');
431432
}
432433

434+
/**
435+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
436+
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
437+
*/
438+
public function testResolveServicesWithDecoratedDefinition()
439+
{
440+
$builder = new ContainerBuilder();
441+
$builder->setDefinition('grandpa', new Definition('stdClass'));
442+
$builder->setDefinition('parent', new DefinitionDecorator('grandpa'));
443+
$builder->setDefinition('foo', new DefinitionDecorator('parent'));
444+
445+
$builder->get('foo');
446+
}
447+
433448
public function testMerge()
434449
{
435450
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));

0 commit comments

Comments
 (0)