Skip to content

Commit 2aef83e

Browse files
bug #41777 [DependencyInjection] accept service locator definitions with no class (nicolas-grekas)
This PR was merged into the 5.3 branch. Discussion ---------- [DependencyInjection] accept service locator definitions with no class | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #40861, fix #41612 | License | MIT | Doc PR | - Commits ------- 6bc8ec6c9a [DependencyInjection] accept service locator definitions with no class
2 parents 2cc94bc + f9985f3 commit 2aef83e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Compiler/CheckDefinitionValidityPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function process(ContainerBuilder $container)
4444
}
4545

4646
// non-synthetic, non-abstract service has class
47-
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass() && (!$definition->getFactory() || !preg_match(FileLoader::ANONYMOUS_ID_REGEXP, $id))) {
47+
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass() && !$definition->hasTag('container.service_locator') && (!$definition->getFactory() || !preg_match(FileLoader::ANONYMOUS_ID_REGEXP, $id))) {
4848
if ($definition->getFactory()) {
4949
throw new RuntimeException(sprintf('Please add the class to service "%s" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.', $id));
5050
}

Tests/Compiler/CheckDefinitionValidityPassTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass(
3737
$this->process($container);
3838
}
3939

40+
public function testProcessAcceptsServiceLocatorWithoutClass()
41+
{
42+
$container = new ContainerBuilder();
43+
$container->register('a')->addTag('container.service_locator');
44+
45+
$this->process($container);
46+
47+
$this->addToAssertionCount(1);
48+
}
49+
4050
public function testProcessDetectsFactoryWithoutClass()
4151
{
4252
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)