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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Routing] Add FQCN and FQCN::method aliases when applicable #50084

Merged
merged 1 commit into from Jun 20, 2023

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Apr 20, 2023

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

See #49981, I think it's a great idea 馃槂

  • We add an FQCN alias only if the target class has an __invoke method that adds a route AND if the target class added 1 route exactly.
  • We add a FQCN::method alias for every method that defines only one route.

Copy link
Member

@nicolas-grekas nicolas-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 :)

What about deprecating the name generated by getDefaultRouteName (when it exists) and always adding an alias named FQCN::method (or just FQCN when method is __invoke)

@fancyweb fancyweb force-pushed the routing/invokable-fqcn-alias branch from 6f19dad to ce17164 Compare April 21, 2023 15:57
@fancyweb fancyweb changed the title [Routing] Add FQCN aliases for routes targeting invokable classes defining one route only [Routing] Add FQCN and FQCN::method aliases when applicable Apr 21, 2023
}
}

if ($fqcnAlias && 1 === $collection->count()) {
$collection->addAlias($class->name, $invokeRouteName = key($collection->all()));
$collection->addAlias(sprintf('%s::__invoke', $class->name), $invokeRouteName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That means we add an "FQCN::__invoke" alias for controllers like this:

#[Route(path: '/foo')]
final class FooController
{
    public function __invoke():
    {
    }
}

@stof
Copy link
Member

stof commented Apr 21, 2023

This does not seem to deprecate the default name though AFAICT

@fancyweb
Copy link
Contributor Author

@stof Indeed, I don't think it's worth it to deprecate the default name and Nicolas agreed after discussing it with him on Slack.

@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@fancyweb fancyweb force-pushed the routing/invokable-fqcn-alias branch from ce17164 to 9fa5bae Compare May 25, 2023 16:37
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Please update the PR description for 6.4 and give some example use cases

src/Symfony/Component/Routing/CHANGELOG.md Show resolved Hide resolved
@fabpot
Copy link
Member

fabpot commented Jun 20, 2023

Thank you @fancyweb.

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.

None yet

6 participants