Skip to content

Commit 922837a

Browse files
Merge branch '3.1'
* 3.1: [YAML] Fix processing timestamp with timezone [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 Fix time-sensitive tests that use data providers [Validator] improve and added more Indonesian translation.
2 parents ff4845f + 87598e2 commit 922837a

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
@@ -835,6 +835,10 @@ public function findDefinition($id)
835835
*/
836836
private function createService(Definition $definition, $id, $tryProxy = true)
837837
{
838+
if ('Symfony\Component\DependencyInjection\Definition' !== get_class($definition)) {
839+
throw new RuntimeException(sprintf('Constructing service "%s" from a %s is not supported at build time.', $id, get_class($definition)));
840+
}
841+
838842
if ($definition->isSynthetic()) {
839843
throw new RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id));
840844
}

Tests/ContainerBuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
2121
use Symfony\Component\DependencyInjection\ContainerInterface;
2222
use Symfony\Component\DependencyInjection\Definition;
23+
use Symfony\Component\DependencyInjection\DefinitionDecorator;
2324
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2425
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2526
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
@@ -412,6 +413,20 @@ public function testResolveServices()
412413
$this->assertEquals($builder->get('foo'), $builder->resolveServices(new Expression('service("foo")')), '->resolveServices() resolves expressions');
413414
}
414415

416+
/**
417+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
418+
* @expectedExceptionMessage Constructing service "foo" from a Symfony\Component\DependencyInjection\DefinitionDecorator is not supported at build time.
419+
*/
420+
public function testResolveServicesWithDecoratedDefinition()
421+
{
422+
$builder = new ContainerBuilder();
423+
$builder->setDefinition('grandpa', new Definition('stdClass'));
424+
$builder->setDefinition('parent', new DefinitionDecorator('grandpa'));
425+
$builder->setDefinition('foo', new DefinitionDecorator('parent'));
426+
427+
$builder->get('foo');
428+
}
429+
415430
public function testMerge()
416431
{
417432
$container = new ContainerBuilder(new ParameterBag(array('bar' => 'foo')));

0 commit comments

Comments
 (0)