DI containers are sorted alphabetically.
- Aura DI: source
- Auryn: source
- AWS/Guzzle: source
- Laravel 4: source
- League\Di: source
- Mouf: source
- Orno\Di: source
- PHP-DI: source
- Pimple: source
- PPI: source
- Symfony 2: source
- Zend Framework 2: source
Submit PR to expand.
Comparison:
| Container | Read | Test | Not found behavior | ArrayAccess |
|---|---|---|---|---|
| Aura DI | get($key) |
has($key) |
Exception | No |
| Auryn | make($key, [$params]) |
Exception | No | |
| AWS/Guzzle | get($key, [$throwAway]) |
array access | Exception | Yes |
| Laravel | make($key, [$params]) |
bound($key) |
Exception? | Yes |
| League\Di | resolve($key) |
bound($key) |
Exception | No |
| Mouf | get($key) |
has($key) |
Exception | No |
| Orno\Di | resolve($key, [$args]) |
? | No | |
| PHP-DI | get($key) |
has($key) |
Exception | No |
| Pimple | array access | array access | Exception | Yes |
| PPI | get($key, [$bool]) |
hasOption($key) |
Exception | Yes |
| Symfony | get($id, [$invalidBehavior]) |
has($key) |
Null or Exception | No |
| ZF2 | get($key, [$params]) |
Null | No |
Parameters surrounded by [] (like get($key, [$param])) are optional parameters.
Summary
- Read method name:
get: 7make: 2resolve: 2- array access: 1
- Read mandatory number of parameters is always 1
- Test existence:
- with: 9
- without: 4
- Test existence method name:
has: 4bound: 2hasOption: 1- array access: 2
- Not found behavior:
- exception: 10
- null: 2
- ArrayAccess:
- no: 8
- yes: 4
To get a binding from
League\Diyou actually useresolve($key). Thebuild($className)is a public method to automatically build an object, resolving any of it's dependencies from the container. The item$classNamedoesn't even need to be registered, and it can still build it.All items bound within the container are either a
Closureor an instance ofLeague\Definition. When callingresolve($key)on an item that is aClosure, it simply get's executed and returns the results. If the requested$keyis an instance ofLeague\Definition, it runs the magic__invoke()method from that instance, and there it builds the object by getting the constructor params and building each dependency as needed, resolving it from the parent container if available.So, to sum it up, you should change the
League\Dientry for the Read column frombuildtoresolve.