sys流/依赖注入容器

1.2.1 2017-09-07 22:27 UTC

This package is not auto-updated.

Last update: 2024-09-13 22:39:37 UTC


README

用于保存使用仓库模式的模型。

安装

您可以通过 packagist.org 使用 composer 安装此包。

composer require systream/dependency-injection-container

composer.json

"require": {
    "systream/dependency-injection-container": "1.*"
}

此库需要 php 5.6 或更高版本,但也可以在 php 5.4 上运行。

用法

$di = new DependencyInjectionContainer();
$di->bind(FixtureTestInterface::class, function () {
	return new ObjectA();
});

$di->has(FixtureTestInterface::class); // will return true

$instance = $di->get(FixtureTestInterface::class); // will return ObjectA instance 

创建

class TestObjectB {
	public function __construct(FixtureTestInterface $test) {
	}
}

$di = new DependencyInjectionContainer();
$di->bind(FixtureTestInterface::class, function () {
	return new ObjectA();
});

$testObject = $di->create(TestObjectB::class); 

测试

Build Status