Skip to content

Commit 4119caf

Browse files
committed
[DependencyInjection] fixed the creation of synthetic services in ContainerBuilder
1 parent 5663820 commit 4119caf

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@ public function findDefinition($id)
725725
*/
726726
private function createService(Definition $definition, $id)
727727
{
728+
if ($definition->isSynthetic()) {
729+
throw new \RuntimeException(sprintf('You have requested a synthetic service ("%s"). The DIC does not know how to construct this service.', $id));
730+
}
731+
728732
if (null !== $definition->getFile()) {
729733
require_once $this->getParameterBag()->resolveValue($definition->getFile());
730734
}

tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ public function testCreateServiceConfigurator()
315315
}
316316
}
317317

318+
/**
319+
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
320+
* @expectedException \RuntimeException
321+
*/
322+
public function testCreateSyntheticService()
323+
{
324+
$builder = new ContainerBuilder();
325+
$builder->register('foo', 'FooClass')->setSynthetic(true);
326+
$builder->get('foo');
327+
}
328+
318329
/**
319330
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::resolveServices
320331
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy