Download the PHP package oliver-schoendorn/dependency-injector without Composer
On this page you can find all versions of the php package oliver-schoendorn/dependency-injector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oliver-schoendorn/dependency-injector
More information about oliver-schoendorn/dependency-injector
Files in oliver-schoendorn/dependency-injector
Package dependency-injector
Short Description A very simple dependency injector that supports instance creation and auto wiring of classes, class methods and functions. Additionally it provides simple means of caching the necessary reflections to boost performance in heavy load environments.
License Apache-2.0
Informations about the package dependency-injector
PHP7 Dependency Injector
Installation
composer require oliver-schoendorn/dependency-injector
Don't forget to include the composer autoloader in your application bootstrap process.
Basic Usage
I recommend creating a single instance of the dependency injector during your applications bootstrap or request dispatching process.
The most common use case is to use the dependency injector to create instances of your controllers. In the following
example, the dependency injector is used to create an instance of FakeController
and to invoke the get
method of it.
All method parameters will be autowired.
Dealing with shared instances
Some dependencies should only have a single instance (or as few as possible), like a database connection for instance.
``
Handling multiple connections (simple)
Sometimes you have to deal with multiple database connections for example. The following example shows how to deal with multiple shared instances of the same class or interface.
Note however, that this approach will not work with auto wiring and also break the type hinting in PhpStorm.
Handling multiple connections (verbose)
To circumvent the issues of the previous approach, you could define two additional interface that will be substituted by the read or write connection: