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

Create AttributeLoader instead use AnnotationLoader #48350

Closed
alamirault opened this issue Nov 27, 2022 · 6 comments
Closed

Create AttributeLoader instead use AnnotationLoader #48350

alamirault opened this issue Nov 27, 2022 · 6 comments

Comments

@alamirault
Copy link
Contributor

Description

Today, symfony AnnotationLoader load for Doctrine annotations and PHP 8 attributes.

For new projects, only attributes are enough and keep naming AnnotationLoader can confuse (load also attributes).

WDYT about creating AttributeLoader ?

Some files and impacts:

Symfony\Component\Validator\Mapping\Loader\AnnotationLoader -> New class Symfony\Component\Validator\Mapping\Loader\AttributeLoader :

  • Symfony\Component\Validator::enableAnnotationMapping() -> Introduce new method enableAttributeMapping
  • New boolean node in framework configuration: enable_attributes

Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader -> New class Symfony\Component\Serializer\Mapping\Loader\AttributeLoader:

  • New boolean node in framework configuration: enable_attributes

Example

No response

@GromNaN
Copy link
Member

GromNaN commented Nov 28, 2022

Hello, the Doctrine Annotations Reader is an optional dependency of Symfony\Component\Validator\Mapping\Loader\AttributeLoader. When the package doctrine/annotations is not installed, only attributes are read.

Do you need an explicit way to disable the annotation? What is the benefit of disabling reading annotations when doctrine/annotations is installed?

Here is the code that could be updated to disable annotation reader with a new option:

if (\array_key_exists('enable_annotations', $config) && $config['enable_annotations']) {
$validatorBuilder->addMethodCall('enableAnnotationMapping', [true]);
if ($this->isInitializedConfigEnabled('annotations')) {
$validatorBuilder->addMethodCall('setDoctrineAnnotationReader', [new Reference('annotation_reader')]);
}
}

@derrabus
Copy link
Member

If we deprecate Doctrine Annotations completely, renaming classes, methods etc. would be the next logical step. But not before that.

@alamirault
Copy link
Contributor Author

This PR #49358 and following Renaming will fix this issue

@derrabus
Copy link
Member

This PR #49358 and following Renaming will fix this issue

For Routing, yes. We would need to do the same for Serializer and Validator then.

@carsonbot
Copy link

Thank you for this issue.
There has not been a lot of activity here for a while. Has this been resolved?

@alamirault
Copy link
Contributor Author

It's done in #51425. Thanks @alexandre-daubois

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants