定制 baxtian/php-di 二次开发

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

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

baxtian/php-di

最新稳定版本:0.3.1

Composer 安装命令:

composer require baxtian/php-di

包简介

PHP Dependency injection

README 文档

README

This is a php trait for Direct Injection. Stable Release: 0.3.0

Usage:

<?php

// Dependencies to be used
class ClassA {
	function echo() {
		echo "A";
	};
}
class ClassB {
	function echo() {
		echo "B";
	};
}

class YourClass
{
	use Baxtian\DependencyInjectionTrait;

	// Create class constructor with a variable that will 
	// contain -if any- the list of arguments
	public function __construct($arguments = [])
	{
		// Array of attributes linked to the class
		$classes = [
			'class_a' => ClassA::class,
			'class_b' => ClassB::class,
		];

		$this->setDependencies($arguments, $classes);
	}

	// Function that uses an injected dependency
	public function foo() {
		$this->dependency('class_a')->echo();
		$this->dependency('class_b')->echo();
	}
}

To pass a specific instance (as a mock for testing)

$foo = new YourClass([
	'class_a' => new ClassA(), 
	'class_b' => new ClassB()
]);

Mantainers

Juan Sebastián Echeverry baxtian.echeverry@gmail.com

Changelog

0.3.1

  • In case of using this class in multiple providers, allow Composer to set which file to use by default.

0.3.0

  • First stable release

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2022-08-10