Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Routing] Support the "attribute" type (alias of "annotation") in annotation loaders #44615

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 1 commit into from
Feb 23, 2022

Conversation

fancyweb
Copy link
Contributor

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR -

Minor DX feature. I migrated several projects to PHP 8 and they now use the Route class as an attribute. They don't require doctrine/annotations anymore. There is no PHPDoc annotations left in the code. For example, I declare the routes like this:

<?php

declare(strict_types=1);

use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return static function (RoutingConfigurator $routes): void {
    $routes
        ->import('../../src/Controller', 'annotation')
        ->namePrefix('app_');
};

I'd like to use attribute as the type instead of annotation now because it makes more sense. Also, it's easier to explain it to newcomers.

@derrabus
Copy link
Member

No strong feelings here. Please note that selecting annotation currently enables support for attributes as well. Adding an alias would do the same thing, meaning that setting attribute would also enable Doctrine-style annotations. Not sure if that makes it any less confusing for newcomers.

To explain why things currently are as they are: annotation simply means that the controller classes are annotated with the route configuration. That setting does not say how they're annotated. Our reader supports two possible ways, Doctrine-style annotations and PHP's native attributes. I realize that this might cause confusion because for many PHP developers, the word "annotations" has become a synonym for the Doctrine Annotations library.

The alternative would have been to create a separate reader for attributes. This is kind-of what Doctrine ORM did.

I ultimately decided against that because I wanted people to be able to mix and match both annotation types, to allow an iterative transition from Doctrine-style annotations to attributes. Simply registering both readers on the same controllers would have made that iterative approach a bit difficult because the order in which routes are registered could matter under certain circumstances.

src/Symfony/Component/Routing/CHANGELOG.md Outdated Show resolved Hide resolved
@fancyweb fancyweb force-pushed the routing/attribute-type branch 2 times, most recently from 73a668f to 4dce9d2 Compare December 31, 2021 08:02
@fancyweb fancyweb force-pushed the routing/attribute-type branch from 4dce9d2 to f309fa1 Compare January 26, 2022 17:49
@fancyweb fancyweb force-pushed the routing/attribute-type branch from f309fa1 to 23dc924 Compare February 22, 2022 14:05
@fancyweb
Copy link
Contributor Author

@nicolas-grekas or anybody else, what do you think of this one? Looks like we are stuck with a +1 and a +0 😅

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

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.