Skip to content

Commit

Permalink
bug #41777 [DependencyInjection] accept service locator definitions w…
Browse files Browse the repository at this point in the history
…ith 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
-------

6bc8ec6 [DependencyInjection] accept service locator definitions with no class
  • Loading branch information
nicolas-grekas committed Jun 23, 2021
2 parents 8a8d2a6 + 6bc8ec6 commit 1a535ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -44,7 +44,7 @@ public function process(ContainerBuilder $container)
}

// non-synthetic, non-abstract service has class
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass() && (!$definition->getFactory() || !preg_match(FileLoader::ANONYMOUS_ID_REGEXP, $id))) {
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass() && !$definition->hasTag('container.service_locator') && (!$definition->getFactory() || !preg_match(FileLoader::ANONYMOUS_ID_REGEXP, $id))) {
if ($definition->getFactory()) {
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));
}
Expand Down
Expand Up @@ -37,6 +37,16 @@ public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass(
$this->process($container);
}

public function testProcessAcceptsServiceLocatorWithoutClass()
{
$container = new ContainerBuilder();
$container->register('a')->addTag('container.service_locator');

$this->process($container);

$this->addToAssertionCount(1);
}

public function testProcessDetectsFactoryWithoutClass()
{
$container = new ContainerBuilder();
Expand Down

0 comments on commit 1a535ba

Please sign in to comment.