Skip to content

Instantly share code, notes, and snippets.

@mnapoli
Last active May 7, 2018 07:58
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mnapoli/6159681 to your computer and use it in GitHub Desktop.
Save mnapoli/6159681 to your computer and use it in GitHub Desktop.
DI containers usage comparison

DI containers usage comparison

DI containers are sorted alphabetically.

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: 7
    • make: 2
    • resolve: 2
    • array access: 1
  • Read mandatory number of parameters is always 1
  • Test existence:
    • with: 9
    • without: 4
  • Test existence method name:
    • has: 4
    • bound: 2
    • hasOption: 1
    • array access: 2
  • Not found behavior:
    • exception: 10
    • null: 2
  • ArrayAccess:
    • no: 8
    • yes: 4
@thejw23
Copy link

thejw23 commented Dec 3, 2013

https://github.com/granula/inversion might be quite interesting addon to mentioned modules.

@teresko
Copy link

teresko commented May 6, 2014

How exactly you came has() being the common name for:

can return an entry for the given identifier

Especially since only 4 out of 9 actually even had a method with such name and (from the surface-scan) it looks like at least two are just checking whether they have configuration for such instance. And the rest are checking whether they have already created such instance.

Neither of those sound like checking, if container "can create". Hell .. I am not even sure how you could check it beforehand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment