Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Routing] Document the Route attribute#14230

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
wouterj merged 1 commit intosymfony:5.xfromderrabus:feature/route-attributes
Oct 11, 2020

Conversation

derrabus
Copy link
Member

This PR documents the new#[Route] attribute that was introduced withsymfony/symfony#37474 and thuscloses#14188.

For the routing configuration via Doctrine Annotations as well as PHP attributes, we use the very same class,Symfony\Component\Routing\Annotation\Route. This means that both mechanisms are equally powerful. Right now, there's nothing you can do with@Route that is impossible with#[Route] and vice versa. The main difference is that you don't need an external library for attributes because they're a native language feature.

Because of that, I'd like to shift the general recommendation to use annotation towards attributes and recommend annotations as the fallback for projects that need to remain compatible with PHP 7.

Right now, the@Route annotation is used throughout the documentation in two different ways:

  1. Demonstrate how to use the annotation

In this case, I've added an additional code block that shows the same configuration for attributes. I've consistently placed the attribute block before the annotation block.

  1. Give context about the route configuration.

When a code block illustrates the logic inside a controller action and the annotation is only used to provide context, I think it would create too much noise to show the attributeand the annotation way. Inrouting.rst, I have replaced the annotation with an equal attribute in such cases. I think it would be a good idea to do the same with the rest of the documentation, but I'd like to discuss this with you before I change all those spots.

routing.rst Outdated

class BlogController
{
#[Route('/blog/{page}', name: 'blog_index', defaults: ['page' => 1, 'title' => 'Hello world!'])]
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

💡 I've kept this attribute single-line in order to remain consistent with the existing annotation block. But I think, the example would be more readable with we defined the attribute/annotation multi-line.

OskarStark reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I prefer multiline too, please adjust the examples. If you like here or in a separate PR first, your choice 😃

Copy link
Member

@wouterjwouterj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks a lot, not only for single-handly making Symfony PHP 8 compatible, but also documenting all great new features!

When a code block illustrates the logic inside a controller action and the annotation is only used to provide context, I think it would create too much noise to show the attribute and the annotation way. In routing.rst, I have replaced the annotation with an equal attribute in such cases. I think it would be a good idea to do the same with the rest of the documentation, but I'd like to discuss this with you before I change all those spots.

I agree that having both would create too much noise. I however think we should stick to using annotations in these places. Examples are often used to copy/paste by beginners and I want everyone to be able to use and understand our code examples (as long as they're on a Symfony-supported PHP version). So I think our code examples should always base on the lower bound of Symfony's PHP requirements, which at this moment is 7.2.5 for Symfony 5.2.

derrabus reacted with heart emoji
routing.rst Outdated
Comment on lines 31 to 34
.. versionadded:: 5.2

The ability to use PHP attributes to configure routes was introduced in
Symfony 5.2.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this should be moved after thecomposer require ... example + we should reword that paragraph and the next one. It is no longer required to install doctrine annotations if you're using PHP 8 attributes

derrabus reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I agree. I was thinking, we should also change the recipes. Ifdoctrine/annotations is an optional dependency now, the routes snippet that enables attributes/annotations should not be attached to thedoctrine/annotations package anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That's exactly what I was thinking. The big question is then: what should be the trigger for this recipe? Maybe, we should make it the default routing config when installing in a PHP 8 application? (I don't think that's a feature of Flex atm)

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We could add the file to thesymfony/routing recipe for 5.2. If we're on PHP 7, that file should have no effect. 🤔

@derrabus
Copy link
MemberAuthor

So I think our code examples should always base on the lower bound of Symfony's PHP requirements, which at this moment is 7.2.5 for Symfony 5.2.

That would likely mean we cannot switch the code examples to attributes before Symfony 7.0 in 2023. I'm rolling back the examples in question, but we might want to reconsider this rule in a year or so.

@derrabusderrabusforce-pushed thefeature/route-attributes branch 2 times, most recently from7628b3e to35a1c49CompareSeptember 12, 2020 13:25
@wouterj
Copy link
Member

That would likely mean we cannot switch the code examples to attributes before Symfony 7.0 in 2023. I'm rolling back the examples in question, but we might want to reconsider this rule in a year or so.

Yeah, and maybe the other doc team members have another opinion than me :). Btw, I think it's also good to consider PHP 8 as lower bound for Symfony 6, given that it does bring significant new features (like attributes) and is released a year before Symfony 6.0.

routing.rst Outdated

class BlogController
{
#[Route('/blog/{page}', name: 'blog_index', defaults: ['page' => 1, 'title' => 'Hello world!'])]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I prefer multiline too, please adjust the examples. If you like here or in a separate PR first, your choice 😃

@OskarStark
Copy link
Contributor

@derrabus I mergedOskarStark/doctor-rst#758, can you please rebase to get the latest DOCtor-RST build? Thanks 🙏

derrabus reacted with thumbs up emoji

@derrabusderrabusforce-pushed thefeature/route-attributes branch from35a1c49 toeade19cCompareOctober 2, 2020 12:12
@derrabus
Copy link
MemberAuthor

@derrabus can you please rebase to get the latest DOCtor-RST build? Thanks 🙏

Done!

@wouterjwouterj added this to the5.2 milestoneOct 3, 2020
@xabbuhxabbuh changed the base branch frommaster to5.xOctober 6, 2020 11:53
@derrabusderrabusforce-pushed thefeature/route-attributes branch fromeade19c tod261a29CompareOctober 11, 2020 18:55
@derrabus
Copy link
MemberAuthor

Sorry for the delay. The blocks are swapped now.

OskarStark reacted with thumbs up emoji

@wouterjwouterjforce-pushed thefeature/route-attributes branch fromd261a29 to4ca794eCompareOctober 11, 2020 20:34
@wouterj
Copy link
Member

Thanks again@derrabus!

@wouterjwouterj merged commit7cfdbfc intosymfony:5.xOct 11, 2020
@derrabusderrabus deleted the feature/route-attributes branchOctober 12, 2020 09:39
@NyholmNyholm mentioned this pull requestOct 13, 2020
OskarStark added a commit that referenced this pull requestOct 14, 2020
This PR was merged into the 5.x branch.Discussion----------Use updated dependenciesCurrently I fail to build the docs in 5.x. They complain on php-attributes.This PR make sure to use@derrabus PRfabpot/sphinx-php#49 released in 2.0.2.This change was missing from#14230Commits-------3c0372a Use updated dependencies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@xabbuhxabbuhxabbuh left review comments

@wouterjwouterjwouterj approved these changes

@OskarStarkOskarStarkOskarStark approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
5.2
Development

Successfully merging this pull request may close these issues.

[RFC][Routing] Added the Route attribute
5 participants
@derrabus@wouterj@OskarStark@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp