Skip to content

Add support for single action controllers, with __invoke method #645

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
Jun 17, 2025

Conversation

pawel-kowalczyk-alpy
Copy link
Contributor

@pawel-kowalczyk-alpy pawel-kowalczyk-alpy commented Jun 6, 2025

PR sponsored by AlpinResorts

@pawel-kowalczyk-alpy pawel-kowalczyk-alpy force-pushed the 3.x branch 2 times, most recently from ee10814 to 83b698e Compare June 6, 2025 16:23
@pawel-kowalczyk-alpy
Copy link
Contributor Author

Looks like PHPStan jobs are broken, not related to my changes

@pawel-kowalczyk-alpy
Copy link
Contributor Author

Friendly ping to @dbu

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thanks for looking into this, we should indeed support __invoke controllers.

i will have a look at the phpstan failure.

@@ -27,12 +27,23 @@ public function onKernelRequest(RequestEvent $event): void
$request = $event->getRequest();
$controller = $this->controllerResolver->getController($request);

if (!is_array($controller) || 2 !== count($controller)) {
if (false === $controller) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems a bit dangerous to me. what if the $controller is something weird, like a different kind of array, or some non-array non-object but not false?

should we not add the is_object condition here? that should also avoid the uncertainty below whether method and class are null or set.

Suggested change
if (false === $controller) {
if (!is_object($controller) && (!is_array($controller) || 2 !== count($controller))) {

or we could do an if object, elseif array, else return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Return type for \Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::getController is callable|false, so return values are limited, but you are right, there can be string for example.

I've changed a logic, now it will work only for object and array with two elements

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

great, thanks a lot! i like to be very defensive with these things, you never know what explodes randomly for people...

@dbu dbu merged commit acecc7d into FriendsOfSymfony:3.x Jun 17, 2025
10 of 12 checks passed
@pawel-kowalczyk-alpy
Copy link
Contributor Author

Nice! Any chance for a release soon? Thanks anyway

@dbu
Copy link
Contributor

dbu commented Jun 17, 2025

yes, "soon" :-) i hope that we can wrap up #646 and include that in the release. if that does not happen this week, i will release what we have.

@pawel-kowalczyk-alpy
Copy link
Contributor Author

Sure, good luck :)

@dbu
Copy link
Contributor

dbu commented Jun 17, 2025

we have been quick :-D here you go: https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/releases/tag/3.2.0

@pawel-kowalczyk-alpy
Copy link
Contributor Author

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants