Skip to content

Introduce support for various dependency injection containers #271

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

Open
cweagans opened this issue Feb 2, 2017 · 4 comments
Open

Introduce support for various dependency injection containers #271

cweagans opened this issue Feb 2, 2017 · 4 comments

Comments

@cweagans
Copy link
Contributor

cweagans commented Feb 2, 2017

There are various DI container libraries available right now. Ideally, this language server would be able to look at something like this:

$container->get('service.name')->

and be able to resolve service.name to a class in the container and provide completions for that class.

To further complicate this, there are multiple ways that some containers can be configured. The symfony container can be configured via an XML file, a YAML file, or directly wiring things up in PHP - or any combination of these things! Perhaps a reasonable MVP for this functionality would be to support one container configured in one way + lay the groundwork for supporting other containers?

What do you think about this? Is it worthwhile? Or is it better to just rely on developers to do something like this:

$myclass = $container->get('service.name');
/** @var MyClass $myclass */
$myclass->

and parse the @var docblocks?

@felixfbecker
Copy link
Owner

Usually you shouldn't interact with a container directly. You should typehint your functions and let the container autowire the dependencies.
@var is supported.
Anything else would require support for generics, and there isn't a documentation standard for this.

@staabm
Copy link
Contributor

staabm commented Feb 2, 2017

The phpstorm IDE supports some extended metadata in which one can describe additional types for autocompletion purposes...

Maybe the language server can also interpret this file format and make use of it?

https://confluence.jetbrains.com/plugins/servlet/mobile#content/view/51186876

@cweagans
Copy link
Contributor Author

cweagans commented Feb 2, 2017

Usually, yes. However, consider something like Drupal. Large parts of the CMS were rewritten for D8, but there is still some procedural code present. This procedural code has mostly evolved into being wrappers around OO code that's accessed through the DI container though, and for the time being, module authors occasionally have to write some procedural code of their own. If it's not worth doing this, it's cool. Just thought I'd float the idea.

@felixfbecker
Copy link
Owner

@staabm I am against adding language-server specific metadata files. Everything should go through type inference and docblock annotations.

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

No branches or pull requests

3 participants