Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining service locators without a class #40861

Closed
derrabus opened this issue Apr 18, 2021 · 2 comments
Closed

Defining service locators without a class #40861

derrabus opened this issue Apr 18, 2021 · 2 comments

Comments

@derrabus
Copy link
Member

Symfony version(s) affected: 5.3.0-beta1

Description
See nelmio/NelmioApiDocBundle#1807

In Symfony 5.2, it was possible to define a service locator service without defining the actual class of the service:

https://github.com/nelmio/NelmioApiDocBundle/blob/bf77277f2fe7c52a5226493d6593659ddb8b9fb8/DependencyInjection/NelmioApiDocExtension.php#L132-L138

In Symfony 5.3, this code fails:

The definition for "nelmio_api_doc.generator_locator" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.

According to the documentation, the Symfony\Component\DependencyInjection\ServiceLocator should be used in the definition.

The fix for NelmioApiDocBundle is trivial and I've already opened nelmio/NelmioApiDocBundle#1808 to address the issue. However, since this bundle broke because of a Symfony upgrade, I wanted to clarify if we want to treat this issue as a regression.

@nicolas-grekas
Copy link
Member

I'm closing because this is a compile-time behavior change that won't explode a prod system.
This was also relying on a side-effect that we cannot maintain.
Thanks for opening.

@nicolas-grekas
Copy link
Member

I changed my mind after reviewing #41612, see #41777

nicolas-grekas added a commit that referenced this issue Jun 23, 2021
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants