Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4119caf

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

File tree

2 files changed

+15
-0
lines changed
Filter options

2 files changed

+15
-0
lines changed

‎src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+4Lines 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

Copy file name to clipboardExpand all lines: tests/Symfony/Tests/Component/DependencyInjection/ContainerBuilderTest.php
+11Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.