定制 mead-steve/container 二次开发

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

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

mead-steve/container

Composer 安装命令:

composer require mead-steve/container

包简介

Simple Dependency Injection Container.

README 文档

README

Very basic dependency injection container.

Build status

branch status
master Build Status

Example Usage

Setup a resource in the container:

use \Meadsteve\Container\Container;
use \Meadsteve\Container\Singleton;

$MyContainer = new Container();

$MyContainer->DependancyOne = new Dependancy();
$MyContainer->MyObject = function(Container $Container) {
	return new MyObject($Container->DependancyOne);
};

Then when you need an instance of MyObject:

$InstanceOfMyObject = $MyContainer->MyObject;

For some heavy objects you may not want to run the construction logic each time. Then you may want to use the singleton pattern. This is possible with the provided class:

$MyContainer->DBUser = "DBGuy";
$MyContainer->Password = "SuperSecret10";
$MyContainer->DBBasedObject = new Singleton(function(Container $Container) {
	return new DBObject($Container->DBUser, $Container->Password);
});

Which is then retrieved in exactly the same way:

$DBInstance = $MyContainer->DBBasedObject

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-31