dev-master
9999999-devMagic type hinting for dependency injection container results
MIT
The Development Requires
by Jordi Martin
documentation dic ioc
Wallogit.com
2017 © Pedro Peláez
Magic type hinting for dependency injection container results
Dependency Injection Container Documentator, (*1)
Since I've been using Dependency Injection Containers in my projects, the IDEs no longer understands what’s going on in some places in my code., (*3)
This problems affect the code hints, autocompletion and refactoring tools when dealing with classes. Then my IDE becomes useless., (*4)
You can define class of the variable returned by DIC 'manually':, (*5)
/** @var YourClassType $mailer */ $mailer = $container['mailer'];
Use two asterisks and write the data type before the name of the variable. You can write the data type without the name of the variable (but not the name without the data type)., (*6)
In the major part of the IDEs this comment solves your problems. But..., (*7)
If you are a lazy person like me, you can use de DIC., (*8)
To document any variable from your code, you should enclose the variable with dd function, execute the code and black magic is going to happen (ok, not too magic, but it works)!, (*9)
Before:, (*10)
$mailer = dd($container['mailer']);
Start:, (*11)
/** @var YourClassType $mailer */ $mailer = $container['mailer'];
Create a composer.json defining the dependencies., (*12)
json
{
"require-dev": {
"jmartin82/DicDoc": "dev-master"
}
}, (*13)
Run Composer: php composer.phar install, (*14)
Magic type hinting for dependency injection container results
MIT
documentation dic ioc