Download the PHP package gandung/dependency-injection without Composer
On this page you can find all versions of the php package gandung/dependency-injection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gandung/dependency-injection
More information about gandung/dependency-injection
Files in gandung/dependency-injection
Package dependency-injection
Short Description A dependency injection container
License MIT
Informations about the package dependency-injection
Simple Dependency Injection Library
This is my simple dependency injection library in PHP
Features:
Setter injection and method injection not yet implemented. Feel free to look, or clone it for your own needs.
Autowiring:
Assume you have a class:
And you have a class that depends on class Unused\Foo, however class Unused\Foo depends on class \SplPriorityQueue
You can resolve an instance of class Bar without resolving Bar and \SplPriorityQueue manually
Binding concrete dependency into unresolved abstract (only class name)
Now, $bar is an instance of Bar::class.
Binding concrete dependency into unresolved abstract (with closure)
Now, $bar is an instance of Bar::class too.
Shared binding concrete dependency into unresolved abstract (only class name)
Shared binding concrete dependency into unresolved abstract (with closure)
Binding typehinted interface into unresolved abstract (class based and with closure)
Assume you have an BaseInterface interface:
And a class which implements BaseInterface interface under the same namespace:
And a class which have typehinted interface in it's constructor
You can resolve class Foo with binding class Base into BaseInterface first.
Or, you and bind concrete implementation of BaseInterface with closure
Resolve concrete implementation which bound on interface directly
Assume you have an interface:
And, concrete class which implements Unused\BaseInterface
Bind concrete implementation on that interface first (use either direct class name or closure)
Then, get it directly.
Registering service under an alias (PSR-11 compatible.)
Assume you have a service which require a concrete implementation of a BaseInterface:
Just bind a concrete implementation of BaseInterface, then register FooService under an alias (e.g: foo.service)
Unit Testing
If you want to run unit tests:
If you need more verbose: