Skip to content

Conversation

@fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Apr 12, 2022

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

I have some routes defined in Kernel.php with the following syntax:

$routes->add('app_foo', '/foo')
    ->methods(['GET'])
    ->controller([$this, 'fooRoute']);

I'd like to switch them to:

$routes->add('app_foo', '/foo')
    ->methods(['GET'])
    ->controller($this->fooRoute(...));

Because I'd like to use first-class callable syntax everywhere in the project.


if (\is_array($controller) && [0, 1] === array_keys($controller) && $this === $controller[0]) {
$route->setDefault('_controller', ['kernel', $controller[1]]);
} elseif ($controller instanceof \Closure && $this === ($r = new \ReflectionFunction($controller))->getClosureThis() && !str_contains($r->name, '{closure}')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anonymous functions and outside closures will continue to fail.

@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

@nicolas-grekas nicolas-grekas merged commit 7751cd3 into symfony:6.1 Apr 12, 2022
@fancyweb fancyweb deleted the fwb/kernel-fcc-route branch April 12, 2022 14:05
@fabpot fabpot mentioned this pull request Apr 15, 2022
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.

3 participants