定制 kaihempel/simpledi 二次开发

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

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

kaihempel/simpledi

最新稳定版本:1.1.0

Composer 安装命令:

composer require kaihempel/simpledi

包简介

Simple dependency injection container

README 文档

README

Simple PHP dependency injection bundle

Build Status Scrutinizer Code Quality Code Coverage

This dependency injection container based on the idea to add the object construction code as closure. So every dependency can build with less convention restrictions.

Installing simpledi via Composer.

  "require": {
    "kaihempel/simpledi": "1.1.*"
  }

Create the dependency injection container instance:

  $di = new \SimpleDI\SimpleDI();

Adding closures for instance creation:

  $di->add('author', function($name) {
    return new Author($name);
  });

After adding the closure with the name "autor", the closure can be executed by calling the magic get method:

  $author = $di->getAuthor($name);

To create instance with further dependencys, the dependency injection container can be commited to the closure by using the "use" keyword:

  $di->add('book', function($name) use ($di) {
    return new Book($di->getAuthor($name));
  });

Like the description above, the "Book" instance will be initialized with a new author instance.

The container has a storage to save created objects. This feature have to be enabled by calling the "getStored()" method before calling the closure code:

  $storedBook = $di->getStored()
                   ->getBook($name);

If no Book instance is stored, the closure execution saves the new instance in the storage.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-11-02