entire-studio/dependency-injection
最新稳定版本:v1.2.1
Composer 安装命令:
composer require entire-studio/dependency-injection
包简介
PSR-11 compatible dependency injection container
README 文档
README
PSR-11 compatible dependency injection container
Installation
Install the latest version with
$ composer require entire-studio/dependency-injection
Basic Usage
<?php declare(strict_types=1); require_once __DIR__ . '/../vendor/autoload.php'; use EntireStudio\DependencyInjection\Container; // Create a DI container $di = new Container(); // Two concrete implementations with a common interface interface Wall {} class WoodenWall implements Wall {} class ConcreteWall implements Wall {} // A class with two properties, one of which is concrete and the other one is an interface readonly class House { public function __construct( private Wall $mainWall, private ConcreteWall $otherWalls, ) {} public function getWallClass(): string { return sprintf( '%s: %s' . PHP_EOL . '%s: %s' . PHP_EOL, 'Main wall', get_class($this->mainWall), 'Other walls', get_class($this->otherWalls), ); } } // Map the Wall interface to WoodenWall $di->set(Wall::class, WoodenWall::class); // Without this we wouldn't know whether to use Wooden or Concrete wall in place of the Wall interface // $di->set(House::class, House::class); // No need to register House as with interface mapped - we can reflect other params // Get the instance $house = $di->get(House::class); // Call the class method echo $house->getWallClass(); /* * Main wall: WoodenWall * Other walls: ConcreteWall */
$ php examples/basic.php
Other examples
See examples/ for more examples.
Commands
Development
composer test- runs test suite.composer sat- runs static analysis.composer style- checks codebase against PSR-12 coding style.composer style:fix- fixes basic coding style issues.
统计信息
- 总下载量: 65
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-03