loomlabs/dependency-injection-component 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

loomlabs/dependency-injection-component

最新稳定版本:1.0.4

Composer 安装命令:

composer require loomlabs/dependency-injection-component

包简介

A PSR compliant dependency injection library for PHP.

README 文档

README

Version 1.0.4 PHP%20Coverage 92.98% License%20GPL-3.0-or-later

A PHP package for managing dependencies and dependency injection.

Installation

You can install this package via Composer:

composer require loomlabs/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).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-05-05