Make the annotation/attribute reader optional in the extension metadata factory #2728
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.
Continuing the effort toward completing #2683, this will make the annotation reader optional in
Gedmo\Mapping\ExtensionMetadataFactory
.As this factory only needs the annotation reader when creating an annotation or attribute driver, this means it should not be a hard requirement when working with other driver mappings (i.e. XML or deprecated YAML support). So, the factory's constructor now allows creating it without the reader and checks when it's creating drivers if the reader is needed.
The factory's
getDriver()
method also had a fallback to a default annotation driver if an extension didn't provide a driver in another format. With that being hard coupled todoctrine/annotations
, a similar approach to what is proposed in #2683 is used where the fallback will go to the annotation driver ifdoctrine/annotations
is installed, and now it will try falling back to the attribute driver ifdoctrine/annotations
is not installed and the app is running on PHP 8.To make this work, the private state in the base
Gedmo\Mapping\MappedEventSubscriber
class now initializes the annotation reader properties to false, and either through setter injection or the internalgetDefaultAnnotationReader()
those will flip to either a reader instance or null. The setter isn't documented to support the new internal false condition, and everything else is private, so we should be good on B/C here.In theory, after this PR,
doctrine/annotations
could become arequire-dev
dependency as I think we've now got everything in the production code with a hard Annotations package dependency reviewed, but there's a long way to go before we could even consider a test run for this package with it fully uninstalled since so many of the tests absolutely require either annotation or YAML support.