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

[FrameworkBundle] Add support for route attributes in kernel controller methods#46115

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
fabpot merged 0 commits intosymfony:6.1fromdunglas:feat/route-attributes-in-kernel
Apr 20, 2022

Conversation

@dunglas
Copy link
Member

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
Ticketsn/a
LicenseMIT
Doc PRtodo

Simplify creating single file projects using route attributes:

<?phprequire__DIR__.'/vendor/autoload.php';useSymfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;useSymfony\Component\HttpFoundation\Response;useSymfony\Component\HttpKernel\KernelasBaseKernel;useSymfony\Component\Routing\Annotation\Route;class Kernelextends BaseKernel{use MicroKernelTrait;    #[Route('/')]publicfunctionhomepage()    {returnnewResponse('Hello, world');    }}$app =newKernel($_SERVER['APP_ENV'] ??'prod',$_SERVER['APP_DEBUG'] ??false);if (\PHP_SAPI ==='cli') {$application =newApplication($app);exit($application->run());}$request = Request::createFromGlobals();$response =$app->handle($request);$response->send();$app->terminate($request,$response);

This will also allow removing these lines from the FrameworkBundle recipe:https://github.com/symfony/recipes/blob/master/symfony/routing/6.0/config/routes.yaml#L5-L7

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Nice :)
please add a line on the changelog of the component
we now need to update the recipe for symfony/routing 6.1
can you please send a PR ?

@fancyweb
Copy link
Contributor

Should we deprecate declaring routes with the->controller([$this, 'foo']) or->controller($this->foo(...)) syntaxes then? I feel like being able to use theRoute attribute directly without any configuration fills the same need but in a better way.

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedApr 20, 2022
edited
Loading

Deprecating always has a cost, which needs to be justified. What would be the justification for the migration cost?

@dunglas
Copy link
MemberAuthor

dunglas commentedApr 20, 2022
edited
Loading

The "old" syntax still has use cases: for instance, you may want to register methods as controllers dynamically (using reflection or complex things like this). I would keep it (and it has been supported for years). However, we could update the docs to promote the new syntax.

nicolas-grekas reacted with thumbs up emoji

Copy link
Member

@chalasrchalasr left a comment

Choose a reason for hiding this comment

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

Cool

@fabpot
Copy link
Member

Thank you@dunglas.

@fabpotfabpot closed thisApr 20, 2022
@fabpotfabpotforce-pushed thefeat/route-attributes-in-kernel branch from6e35580 to0ae445cCompareApril 20, 2022 13:55
@fabpotfabpot merged commite740a11 intosymfony:6.1Apr 20, 2022
@dunglasdunglas deleted the feat/route-attributes-in-kernel branchApril 20, 2022 14:26
@fabpotfabpot mentioned this pull requestApr 27, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@GromNaNGromNaNGromNaN approved these changes

@chalasrchalasrchalasr approved these changes

+1 more reviewer

@fancywebfancywebfancyweb approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.1

Development

Successfully merging this pull request may close these issues.

7 participants

@dunglas@fancyweb@nicolas-grekas@fabpot@GromNaN@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp