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

Suggest packages on missing autowiring aliases #30521

Closed
nicolas-grekas opened this issue Mar 11, 2019 · 7 comments
Closed

Suggest packages on missing autowiring aliases #30521

nicolas-grekas opened this issue Mar 11, 2019 · 7 comments
Labels
Help wanted Issues and PRs which are looking for volunteers to complete them. RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@nicolas-grekas
Copy link
Member

When I use a type-hint for an interface that is not installed, autowiring fails with a generic message, e.g.: Cannot autowire argument $client of "App\Controller\HelloController::index()": argument "$responseFactory" of method "Symfony\Component\HttpClient\Psr18Client::__construct()" has type "Psr\Http\Message\ResponseFactoryInterface" but this class was not found.

But in this example, we could suggest a solution: compose require nyholm/psr7 will install recipes for the interface. Maybe we could display this as a suggestion when we detect that flex is installed? We would do this for packages with official recipes only to reduce the scope.

Another example is Cannot determine controller argument for "App\Controller\HelloController::index()": the $client argument is type-hinted with the non-existent class or interface: "Psr\Http\Client\ClientInterface". when psr/http-client is missing.

@nicolas-grekas nicolas-grekas added RFC RFC = Request For Comments (proposals about features that you want to be discussed) Help wanted Issues and PRs which are looking for volunteers to complete them. labels Mar 11, 2019
@moynzzz
Copy link
Contributor

moynzzz commented Mar 13, 2019

I would like to work on this issue @nicolas-grekas how do you suggest implementing the desired functionality in terms of which packages interfaces should be suggested. Should we extract all possible interfaces from the packages that exist in the Symfony recipes repository or some more robust way of doing that?

@nicolas-grekas
Copy link
Member Author

From what I read, these two messages are found:

  1. in AutowirePass::createTypeNotFoundMessage()
  2. in RegisterControllerArgumentLocatorsPass::process()

I think we could add a static class in the DI component that would hard-code a few packages - let's start with only the ones mentionned in the description and see later if/how to grow the list?

@moynzzz
Copy link
Contributor

moynzzz commented Mar 18, 2019

Okay I'm working on a PR for this feature.

@moynzzz
Copy link
Contributor

moynzzz commented Mar 21, 2019

I have a qustion about how to check if flex is installed in a symfony application. I tried to check if flex class exists (Symfony\Flex\Flex) but it depends on Composer\Plugin\PluginInterface which is not autoloaded (because composer autoloader doesn't add it to the list of loaded classes which is expected we don't need it in our applications) and so the check will fail. A solution will be to check for a class that exists in the flex source like Symfony\Flex\Lock but I don't think this is the best one.

Does anybody have an idea how this can be solved?

@nicolas-grekas
Copy link
Member Author

A solution will be to check for a class that exists in the flex source like Symfony\Flex\Lock

I think that's the best solution actually :)

@Simperfit
Copy link
Contributor

@moynzzz Are you still working on it ?

@moynzzz
Copy link
Contributor

moynzzz commented Apr 7, 2019

@Simperfit Yes, I am. Sorry for the delay I was a little busy last month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help wanted Issues and PRs which are looking for volunteers to complete them. RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

No branches or pull requests

3 participants