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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[Route] attribute on invocable controller cannot be found #2176

Closed
alcohol opened this issue Jun 12, 2023 · 3 comments
Closed

#[Route] attribute on invocable controller cannot be found #2176

alcohol opened this issue Jun 12, 2023 · 3 comments
Labels

Comments

@alcohol
Copy link

alcohol commented Jun 12, 2023

For the most part, this plugin works great. But I noticed in a project that a select few routes kept showing up as missing according to the plugin:

image

The only thing that all these missing routes have in common, is that they are specified (as attributes) on a class level rather than a method level, e.g.:

<?php declare(strict_types=1);

namespace Foo;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

#[Route(path: '/bar', name: 'bar')]
class Bar
{
    public function __invoke(Request $request): Response
    {
        return new Response();
    }
}

PHPStorm version 2023.1 and also 2023.2 EAP
Plugin version 2022.1.250

@KatoPue
Copy link

KatoPue commented Oct 6, 2023

I got the same issue with the class level php attributes.
For PhpDock annotations it seems to work, at least in an older project of mine I have no issues.

PHPStorm version 2023.2
Plugin version 2022.1.258

@alcohol
Copy link
Author

alcohol commented Oct 6, 2023

I can confirm that if I move the annotation to the method level (__invoke() in the example) that the route is recognized and no longer triggers a 'missing route' hint.

@MV1908
Copy link

MV1908 commented Jan 8, 2024

I have the same problem. I upgraded a small project from an old symfony version (4.4) to 7.0 and converted the annotations to attributes.
I went to the same point with @alcohol (moving the attribute to the method level) to make it working.

That add precision, this was not an issue when using annotations on the class level on invokable controllers. This only happens when using attributes on the class level.

In the official Symfony documentation, the route attribute is placed on class level in invokable controllers : https://symfony.com/doc/current/controller/service.html#invokable-controllers

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

No branches or pull requests

4 participants