8000 [FrameworkBundle] Add support for first-class callable route controller in MicroKernelTrait by fancyweb · Pull Request #46009 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Add support for first-class callable route controller in MicroKernelTrait #46009

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

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CHANGELOG
* Add `xliff` support in addition to `xlf` for `XliffFileDumper`
* Deprecate the `reset_on_message` config option. It can be set to `true` only and does nothing now
* Add `trust_x_sendfile_type_header` option
* Add support for first-class callable route controller in `MicroKernelTrait`

6.0
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection

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.

$route->setDefault('_controller', ['kernel', $r->name]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public function testFlexStyle()
$response = $kernel->handle($request);

$this->assertEquals('Have a great day!', $response->getContent());

$request = Request::create('/h');
$response = $kernel->handle($request);

$this->assertEquals('Have a great day!', $response->getContent());
}

public function testSecretLoadedFromExtension()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function __destruct()
protected function configureRoutes(RoutingConfigurator $routes): void
{
$routes->add('halloween', '/')->controller([$this, 'halloweenAction']);
$routes->add('halloween2', '/h')->controller($this->halloweenAction(...));
}

protected function configureContainer(ContainerConfigurator $c): void
Expand Down
0