stanlemon / simple-container

此包已弃用且不再维护。未建议替代包。

SimpleContainer 是一个简单的服务容器,支持依赖注入。

v0.1.1 2012-12-27 03:40 UTC

This package is auto-updated.

Last update: 2021-11-19 05:31:56 UTC


README

Build Status

SimpleContainer 是一个基本的服务容器,它可以存储键 => 值对象,并通过闭包懒加载它们。它还包括一个 newInstance() 方法,允许您通过构造函数和设置器注入依赖,从而实现非常基本的依赖注入。

示例用法

基本服务加载和检索

// Create the SimpleContainer
$container = new SimpleContainer();
// Set a service
$container->set('foo', function(){
	return new Foo();
});
// Get the service
$foo = $container->get('foo');
// Create a new class with services populaed
$bar = $container->newInstance('bar');
$bar->getFoo();