8000 [DependencyInjection] Don't skip classes with private constructor when autodiscovering by nicolas-grekas · Pull Request #59712 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Don't skip classes with private constructor when autodiscovering #59712

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

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

nicolas-grekas
Copy link
Member
@nicolas-grekas nicolas-grekas commented Feb 6, 2025
Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #48392
License MIT

With value objects auto-discovery becoming more mainstream (see #59704), it's time to fix registering classes with private constructors.

Those are skipped today but with support for #[Autoconfigure(constructor: 'createInstance')] as introduced in #49665, this doesn't make sense anymore.

Best reviewed ignoring whitespace.

@stof
Copy link
Member
stof commented Feb 6, 2025

Do we still have a compiler pass validating that services are either instantiable classes or have a factory configured, so that we get a clean error at build time for services that miss this configuration ? And if yes, do we need to update its error message to mention the possibility to use #[Autoconfigure(constructor: ...)] for autoconfigured definitions ?

@nicolas-grekas
Copy link
Member Author

We do have a compiler pass but it didn't tell about the attribute. PR updated:

Invalid service "App\Foo": its constructor must be public. Did you miss configuring a factory or a static constructor? Try using the "#[Autoconfigure(constructor: ...)]" attribute for the latter.

@nicolas-grekas nicolas-grekas merged commit 4d9b7be into symfony:7.3 Feb 10, 2025
8 of 11 checks passed
@nicolas-grekas nicolas-grekas deleted the di-not-instantiables branch February 12, 2025 15:25
@fabpot fabpot mentioned this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DependencyInjection] Allow registering attributes on classes that cannot be instantiated
3 participants
0