ozziest / di
DI is a simple dependency injection manager.
1.0.1
2016-05-30 06:56 UTC
Requires (Dev)
- phpunit/phpunit: ~4.1
This package is not auto-updated.
Last update: 2024-12-21 21:03:04 UTC
README
This is a simple dependency injection manager.
Installation
To install through composer, simply put the following in your composer.json
file:
{ "require": { "ozziest/di": "dev-master" } }
$ composer update
Usage
class CustomModel { public function __construct(IDB $db) { } } class MyController { public function __construct(IModel $model, IRepository $repository, CustomModel $model) { } } Ozziest\DI::bind('IModel', 'MyModel'); Ozziest\DI::bind('IRepository', 'MyRepository'); Ozziest\DI::bind('IDB', 'MyDB'); $instance = Ozziest\DI::resolve('MyController'); // equals this $instance = new MyController( new MyModel(), new MyRepository(), new CustomModel(new MyDB()) );