loomsoftware/dependency-injection-component
最新稳定版本:1.0.5
Composer 安装命令:
composer require loomsoftware/dependency-injection-component
包简介
A PSR compliant dependency injection library for PHP.
README 文档
README
A PHP package for managing dependencies and dependency injection.
Installation
You can install this package via Composer:
composer require loomsoftware/dependency-injection-component
Usage
DependencyContainer
The DependencyContainer class provides a simple way to manage and retrieve dependencies. You can add and retrieve
dependencies as follows:
use Loom\DependencyInjectionComponent\DependencyContainer;
// Create a container
$container = new DependencyContainer();
// Add a dependency
$container->add(MyDependency::class, new MyDependency());
// Retrieve a dependency
$dependency = $container->get(MyDependency::class);
DependencyManager
The DependencyManager class allows you to load dependencies from a YAML configuration file and register them in a
DependencyContainer. Here's an example of how to use it:
use Loom\DependencyInjectionComponent\DependencyContainer;
use Loom\DependencyInjectionComponent\DependencyManager;
// Create a container
$container = new DependencyContainer();
// Create a manager and load dependencies from a YAML file
$manager = new DependencyManager($container);
$manager->loadDependenciesFromFile('path/to/dependencies.yaml');
In your YAML configuration file (dependencies.yaml), you can define services and their arguments for injection.
Setting Up Your Services/Dependencies Definitions
Here's an example of a dependencies.yaml file that demonstrates how to define services and their arguments for injection:
services:
myService:
class: 'Namespace\MyService'
arguments:
- 'argument1'
- 'argument2'
- '@anotherService' # Inject another service
Here's a breakdown of the elements in the dependencies.yaml file:
services: This section defines the services and their configurations.alias: Your chosen alias for the service -myService.class: The fully qualified class name of the service class.arguments: An array of constructor arguments. Use "@" to reference other services.
Once you've set up your dependencies.yaml file with the desired services and configurations, you can load and manage
these dependencies using the Dependency Injection Package.
License
This package is open-source software licensed under the GNU General Public License, version 3.0 (GPL-3.0).
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-05-21