承接 monotek/dependency-inject 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

monotek/dependency-inject

最新稳定版本:v1.0.1

Composer 安装命令:

composer require monotek/dependency-inject

包简介

Tried and tested minimal dependency injection for PHP

README 文档

README

Simply, this package consists of two classes. Class Dependency handles the definition of dependencies and resources. Class Inject handles auto injection of defined dependencies when instantiating objects.

Defining a dependency is as simple as:

Dependency::set("database", function($param = false) {
	return new Database();
});

Using a dependency is as simple as:

class UsesDatabase extends Inject
{
	public $inject = array("database");
	public function process()
	{
		$db = $this->getDatabase("param");
	}
}

The defined dependencies will create instances only when they are actually used. If the dependency is not used it will not be instantiated, keeping your overhead when executing PHP code as minimal as possible.

Passing arguments to the dependencies is enabled. This way you can have a utility dependency instantiator, which would return data depending on the arguments.

If you want to override a dependency in an instance:

$object->setDatabase($object_or_callback);

Every next call to getDatabase will return the result of the call or the value which was passed to setDatabase.

Please see the unit tests for more advanced examples of using this package.

2014 (c) Tit Petrič, Monotek d.o.o.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固