DI是一个简单的依赖注入管理器。

1.0.1 2016-05-30 06:56 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:36:40 UTC


README

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

这是一个简单的依赖注入管理器。

安装

要通过composer安装,只需在您的composer.json文件中添加以下内容

{
    "require": {
        "ozziest/di": "dev-master"
    }
}
$ composer update

用法

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())
);