graychen/container

a container for interface and container

v1.0.0 2018-02-22 15:49 UTC

This package is not auto-updated.

Last update: 2024-12-21 21:25:35 UTC


README

StyleCI Build Status Scrutinizer Code Quality Code Coverage Code Coverage

如何导入

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")