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
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2022-08-10