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 d8afb57

Browse filesBrowse files
committed
[DependencyInjection] Handle null factory class in ContainerBuilder::createService
1 parent e15ccda commit d8afb57
Copy full SHA for d8afb57

File tree

Expand file treeCollapse file tree

2 files changed

+3
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+3
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/ContainerBuilder.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ private function createService(Definition $definition, array &$inlineServices, b
10981098

10991099
if (null !== $factory = $definition->getFactory()) {
11001100
if (\is_array($factory)) {
1101-
$factory = [$this->doResolveServices($parameterBag->resolveValue($factory[0]), $inlineServices, $isConstructorArgument), $factory[1]];
1101+
$factory = [$this->doResolveServices($parameterBag->resolveValue($factory[0]), $inlineServices, $isConstructorArgument) ?? $class, $factory[1]];
11021102
} elseif (!\is_string($factory)) {
11031103
throw new RuntimeException(sprintf('Cannot create service "%s" because of invalid factory.', $id));
11041104
} elseif (str_starts_with($factory, '@=')) {

‎src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,13 @@ public function testCreateServiceFactory()
547547
$builder->register('qux', 'Bar\FooClass')->setFactory(['Bar\FooClass', 'getInstance']);
548548
$builder->register('bar', 'Bar\FooClass')->setFactory([new Definition('Bar\FooClass'), 'getInstance']);
549549
$builder->register('baz', 'Bar\FooClass')->setFactory([new Reference('bar'), 'getInstance']);
550+
$builder->register('quux', 'Bar\FooClass')->setFactory([null, 'getInstance']);
550551

551552
$this->assertTrue($builder->get('foo')->called, '->createService() calls the factory method to create the service instance');
552553
$this->assertTrue($builder->get('qux')->called, '->createService() calls the factory method to create the service instance');
553554
$this->assertTrue($builder->get('bar')->called, '->createService() uses anonymous service as factory');
554555
$this->assertTrue($builder->get('baz')->called, '->createService() uses another service as factory');
556+
$this->assertTrue($builder->get('quux')->called, '->createService() uses same class as factory');
555557
}
556558

557559
public function testCreateServiceMethodCalls()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.