-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[JsonEncoder] Add JsonEncodable
attribute
#59401
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
+62
−5
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AsEncodableItem? Otherwise it does not match our As... naming or just "Encodable"? |
0e5c24d
to
b70b7ea
Compare
AsEncodable
attributeEncodable
attribute
0c4c28b
to
073610e
Compare
Kocal
reviewed
Jan 7, 2025
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/JsonEncoderTest.php
Outdated
Show resolved
Hide resolved
ad8e5a0
to
962ae14
Compare
chalasr
reviewed
Jan 8, 2025
962ae14
to
60fd915
Compare
Encodable
attributeJsonEncodable
attribute
GromNaN
reviewed
Jan 8, 2025
nicolas-grekas
approved these changes
Jan 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I like how we're using the container loading tools to do resource discovery quite seamlessly.
GromNaN
approved these changes
Jan 12, 2025
chalasr
approved these changes
Jan 12, 2025
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/JsonEncoderTest.php
Outdated
Show resolved
Hide resolved
60fd915
to
a12ad34
Compare
Thank you @mtarld. |
nicolas-grekas
added a commit
that referenced
this pull request
Feb 11, 2025
…)` and `ContainerBuilder::findExcludedServiceIds()` for auto-discovering value-objects (GromNaN) This PR was squashed before being merged into the 7.3 branch. Discussion ---------- [DependencyInjection] Add `Definition::addExcludedTag()` and `ContainerBuilder::findExcludedServiceIds()` for auto-discovering value-objects | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT We could **not** use the method `findTaggedServiceIds` in #59401 (comment), same for api-platform/core#6943. As "using the container loading tools to do resource discovery quite seamlessly" [seems to be a good idea](#59401 (review)), this changes make it easier. I'm not closed to alternative ideas if we want to go further with this use-case. ### Usage Let's create a `AppModel` attribute class and use it on any class of the project. In the extension class: ```php $this->registerAttributeForAutoconfiguration(AppModel::class, static function (ChildDefinition $definition) { $definition->addExcludedTag('app.model'); }); ``` In a compiler pass: ```php $classes = []; foreach($containerBuilder->findExcludedServiceIds('app.model') as $id => $tags) { $classes[] = $containerBuilder->getDefinition($id)->getClass(); } $containerBuilder->setParameter('.app.model_classes', $classes); ``` And this parameter can be injected into a service, or directly update a service definition to inject this list of classes. The attribute parameters can be injected into the tag, and retrieved in the compiler pass, for more advanced configuration. Commits ------- 7a0443b [DependencyInjection] Add `Definition::addExcludedTag()` and `ContainerBuilder::findExcludedServiceIds()` for auto-discovering value-objects
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add
JsonEncodable
attribute that autoconfiguresjson_encoder.encodable
tag.