定制 niletphp/dependency-container 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

niletphp/dependency-container

Composer 安装命令:

composer require niletphp/dependency-container

包简介

The NiletPHP dependency injection container.

README 文档

README

Dependency container which provides an easy way for managing dependencies in your PHP projects.

Requirements

PHP >= 7.0

Install

Composer

{
    "require": {
        "niletphp/dependency-container": ">=v1.0"
    }
}

Examples

$dc = new Nilet\Components\Container\DependencyContainer();

Resolve dependencies for a given concrete and return a new instance of it

$dc->create("Nilet\Foo");

Bind a concrete to interface. Resolving such binding will always return new concrete instance

$dc->bind("Nilet\FooInterface", "Nilet\Foo");
$dc->bind("Nilet\FooInterface", function ($dc) {
    return new Nilet\Foo();
});
$dc->create("Nilet\FooInterface");

Share a concrete (singleton).

$dc->share("Nilet\Foo");
$dc->share("Nilet\Foo", function ($dc) {
    return new Nilet\Foo();
});

Binding a concrete (singleton) to an Interface

$dc->bindShared("Nilet\FooInterface", "Nilet\Foo");
$dc->bindShared("Nilet\FooInterface", function ($dc) {
    return new Nilet\Foo();
});

Register a concrete instance (singleton).

$foo = new Nilet\Foo();
$dc->instance("Nilet\Foo", $foo);

Retrieve a concrete.

$dc->get("Nilet\Foo");

$dc->bindShared("Nilet\FooInterface", "Nilet\Foo");
$dc->get("Nilet\FooInterface");

Determine if a given concrete (singleton) has been resolved.

$dc->bindShared("Nilet\FooInterface", "Nilet\Foo");
$dc->get("Nilet\FooInterface");
if ($dc->isResolved("Nilet\FooInterface")) { // evaluates to true
    // do something
} else {
    // do something else
}

Determine if a given concrete is shared.

$dc->share("Nilet\Foo");
if ($dc->isShared("Nilet\Foo")) { // evaluates to true
    // do something
} else {
    // do something else
}

Determine if a given interface is bound.

$dc->bind("Nilet\FooInterface", "Nilet\Foo");
if ($dc->isBound("Nilet\FooInterface")) { //evaluates to true
    // do something
} else {
    // do something else
}

Determine if a given interface is bound/shared.

$dc->bindShared("Nilet\FooInterface", "Nilet\Foo");
if ($dc->isBoundShared("Nilet\FooInterface")) { //evaluates to true
    // do something
} else {
    // do something else
}

统计信息

  • 总下载量: 151
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固