composer require graychen/container
首先我们在文件中引入我们的容器
use graychen\container\Container;
然后我们再将类注册到容器中,用字符串进行映射
$container = new Container();
$container->setShared("logShared", function ($content="") {
return new Log($content);
});
$log=$container->get("logShared", array("writeContent"));
$container = new Container();
$container->set("log", "graychen\container\\tests\Fixtures\Log");
$log=$container->get("log", array("setString"));
$container = new Container();
$container->offsetSet("log", new Log());
$container->offsetGet("log")
$container->offsetExists("log")
$container->offsetUnset("write")