8000 Annotation routing in the core · Issue #25103 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Annotation routing in the core #25103

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

Closed
stof opened this issue Nov 22, 2017 · 7 comments · Fixed by sensiolabs/SensioFrameworkExtraBundle#562
Closed

Annotation routing in the core #25103

stof opened this issue Nov 22, 2017 · 7 comments · Fixed by sensiolabs/SensioFrameworkExtraBundle#562
Labels
Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@stof
Copy link
Member
stof commented Nov 22, 2017
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 4.1

Currently, we have 2 separate annotation loaders for the routing: one in SensioFrameworkExtraBundle (SFEB) and one in FrameworkBundle (FB) which was added more recently. The component only has an abstract class (used by both).

The FB loader was added more recently (in 3.4), as we encouraged using annotation more and more and people wanting to have support in core. But it is missing a few features:

  • generated controller name is not as clean as the SFEB one when using __invoke (probably added in SFEB after the port to core, and not backported)
  • missing support for service id AFAIK (the core annotation does not have the service property)
  • SFEB supports extra @Method annotations (and its subclasses for @GET and @POST). I'm not sure how common they are. An option could be to deprecate them.

Having 2 diverging implementations makes maintenance harder (and enabling SFEB changes the loader being used, so adding a new feature in the FB loader is dangerous as installing SFEB would replace it, and the annotation Flex alias installs SFEB).

Here are my suggestions:

  • fix the support for __invoke in FB so that both loaders are in sync in 3.4 (I would consider it a bug that the implementation is different here)
  • evaluate the possibility for SFEB to extend the FB implementation so that it does not have to duplicate the logic (especially for future core features). Requires bumping min version to Symfony 3.4 in SFEB.
  • consider moving the AnnotatedRouteControllerLoader to the component rather than FB (there is nothing really specific to the bundle in it)
  • consider deprecating the SFEB routing layer (depends on the usage of @Route(service="...") and @Method()
@backbone87
Copy link
Contributor
backbone87 commented Nov 25, 2017

Just an additional note regarding route names:
When using ADR style controllers, it would be super helpful, if the generate route names match the action class name. That way one can use $urlGenerator->generate(MyAction::class) to generate routes.

@Pierstoval
Copy link
Contributor

As Route annotations have been backported to core, I totally like the idea of deprecating @Route and @Method in SFEB and move them to core.

@javiereguiluz javiereguiluz added Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Dec 6, 2017
@Tobion
Copy link
Contributor
Tobion commented Feb 9, 2018

missing support for service id AFAIK (the core annotation does not have the service property)

It's correct that FB does not support it. But I was thinking through it and IMO we don't need it anymore.

  • Either you use class-named services, then you don't need the "service" property at all. See also Deprecate bundle:controller:action and service:method notation #26085
  • Or you don't use class-named services. In this case the better solution to me, is for people to create a alias in the container from the controller class to to service id instead of specifying the service id in the routing. Then you're set as well and that is already common practice with autowiring.

consider moving the AnnotatedRouteControllerLoader to the component rather than FB (there is nothing really specific to the bundle in it)

The AnnotatedRouteControllerLoader uses "_controller" key which the routing component didn't know about in the past and was independent of that. But with #23227 and similar PRs this independence got removed. So we could inded move it to the component as well.

SFEB supports extra @method annotations (and its subclasses for @get and @post). I'm not sure how common they are. An option could be to deprecate them.

I think sometimes @Get and @Post read more naturally and can be useful when developing APIs especially. So IMO it doesn't hurt to port them as well.

@Taluu
Copy link
Contributor
Taluu commented Feb 10, 2018

AFAIC, I'm using the @method a lot (if not all the time), while @get and @post, well... nope, but I think it could be ported. IMO, @get and @post could be ported while adding support for @patch, @put, and @delete annotations. We could then deprecate @method (because it feels more "natural" to use the other ones)

@Tobion
Copy link
Contributor
Tobion commented Feb 10, 2018

Actually @Get etc are not part of FrameworkExtraBundle, but FosRestBundle. ^^ Another source of more confusion.

@backbone87
Copy link
Contributor

For method one can use FB Route annotation‘s property „method“. Having 2 or 3 ways to configure the same thing in the same place just causes confusion. I am in favor of deprecating/not porting @method and not adding additional route related annotations (except for ones that are meant to be used within a route annotation itself)

@Pierstoval
Copy link
Contributor

I don't see why using more and more annotations when @Route("/", methods={"GET"}) is also self-explanatory.
For the ones thinking it's more readable, why this:

/**
 * @Route("/article/{slug}",
 *     defaults={"slug":"home"},
 *     requirements={"slug":"\w+"}
 * )
 * @Method("GET")
 */

Would it be more readable than this:

/**
 * @Route("/article/{slug}",
 *     defaults={"slug":"home"},
 *     requirements={"slug":"\w+"},
 *     methods={"GET"}
 * )
 */

The method is a part of the route, and having tons of annotations just says that there might be a different logic for the @Method annotation where there isn't.

I think we should encourage people using one single @Route annotation for the whole route. After all, a Route is an object, so is an annotation, so if it represents the same api than the Route object in the component, it's more consistent IMO.

fabpot added a commit to sensiolabs/SensioFrameworkExtraBundle that referenced this issue Feb 24, 2018
…favor of Symfony Core (Tobion)

This PR was merged into the 5.1.x-dev branch.

Discussion
----------

Deprecate routing annotation of FrameworkExtraBundle in favor of Symfony Core

Since symfony/symfony#23044 routing annotation is part of Symfony Core.

The only extra features that the routing annotation from SensioFrameworkExtraBundle has are
- service config for `@Route` which we don't need anymore
    - Either you use class-named services, then you don't need the "service" property at all.
    - Or you don't use class-named services. In this case the better solution to me, is for people to create a alias in the container from the controller class to to service id instead of specifying the service id in the routing. Then you're set as well and that is already common practice with autowiring.
- `@Method` does not provide real value as people agree in symfony/symfony#25103

This resolves symfony/symfony#25103

Commits
-------

444683c Deprecate routing annotation of FrameworkExtraBundle in favor of Symfony Core
fabpot added a commit that referenced this issue Feb 26, 2018
…s (Tobion)

This PR was merged into the 3.4 branch.

Discussion
----------

Set controller without __invoke method from invokable class

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License       | MIT
| Doc PR        |

Fixes one part of #25103

Commits
-------

cc68c50 Set controller without __invoke method from invokable class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
6 participants
0