feat(metadata) Load external PHP file resources #7017
Draft
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.
The idea of this PoC is to allow configuring resources and their operations with external PHP files instead of XML/YAML files, which will be useful for projects such as Sylius.
This PR is not ready to merge, there are no PHPUnit tests, I've just used a minimalist Symfony app to test it.
The goal of this PR is to open discussions and make an ADR later.
I already know there are also some discussions about customizing the existing operations but that could be based on this PHP file resource extractor. (I already made a PoC about that too in a CustomResourceMetadataCollectionFactory on the Sylius resource side).
The main issue is that we cannot load PHP files that are in the autoloader, cause it will throw an error, indicating the class already exist. That's the reason I added an "imports" part to the mapping configuration to solve the issue for the PoC.
we instanciate the ApiResource, so it's the same DX as we already have when configuring the entity with the attributes.
Here, it's just to show the current implementation with attributes still works.
We both have our Conference Entity with the ApiResource attribute and our Speaker entity configured with an external PHP file.
I've tried to get the collection and to add a new speaker and it works perfectly.