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

Make the annotation/attribute reader optional in the extension metadata factory #2728

Conversation

mbabker
Copy link
Contributor

@mbabker mbabker commented Nov 28, 2023

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 to doctrine/annotations, a similar approach to what is proposed in #2683 is used where the fallback will go to the annotation driver if doctrine/annotations is installed, and now it will try falling back to the attribute driver if doctrine/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 internal getDefaultAnnotationReader() 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 a require-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.

Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (2ba8f94) 79.38% compared to head (cf77b7d) 79.27%.

Files Patch % Lines
src/Mapping/ExtensionMetadataFactory.php 70.58% 5 Missing ⚠️
src/Mapping/MappedEventSubscriber.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2728      +/-   ##
==========================================
- Coverage   79.38%   79.27%   -0.11%     
==========================================
  Files         162      162              
  Lines        8498     8513      +15     
==========================================
+ Hits         6746     6749       +3     
- Misses       1752     1764      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mbabker mbabker force-pushed the optional-reader-for-metadata-factory branch from 181ca22 to 5ac3458 Compare December 5, 2023 15:13
@mbabker mbabker marked this pull request as ready for review December 5, 2023 15:14
@franmomu franmomu changed the title [WIP] Make the annotation/attribute reader optional in the extension metadata factory Make the annotation/attribute reader optional in the extension metadata factory Dec 5, 2023
@franmomu franmomu merged commit 680e4b4 into doctrine-extensions:main Dec 5, 2023
16 of 18 checks passed
@franmomu
Copy link
Collaborator

franmomu commented Dec 5, 2023

thanks @mbabker!

@mbabker mbabker deleted the optional-reader-for-metadata-factory branch December 5, 2023 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants