kbondurant/attribute-container
最新稳定版本:1.0.0
Composer 安装命令:
composer require kbondurant/attribute-container
包简介
An attribute based container for league/container
README 文档
README
An attribute based container for league/container.
Installation
Via Composer
composer require kbondurant/attribute-container
Requirements
The following versions of PHP are supported by this version.
- PHP 8.0
- PHP 8.1
Usage
This container allows you to bind an interface to its implementation using PHP Attributes
Add AttributeContainer as a delegate container to your league/container
<?php declare(strict_types=1); $container = new League\Container\Container(); $delegate = new Kbondurant\AttributeContainer\AttributeContainer(); $container->delegate($delegate);
Regular binding
<?php declare(strict_types=1); namespace Tests\Fixtures; use Kbondurant\AttributeContainer\BindTo; #[BindTo(Bar::class)] interface Foo { // }
Singleton binding
<?php declare(strict_types=1); namespace Tests\Fixtures; use Kbondurant\AttributeContainer\BindTo; #[BindTo(Bar::class, true)] interface Foo { // }
Custom binding attribute
If you do not want to rely on the provided BindTo attribute you can create your own attribute class that implements BindingAttribute interface
#[Attribute] class MyBindingAttribute implements Kbondurant\AttributeContainer\BindingAttribute { /** * @param class-string $class */ public function __construct( private string $class, ) { } public function getClass(): string { return $this->class; } public function isShared(): bool { return false; } } #[MyBindingAttribute(Bar::class)] interface Foo { // }
Testing
Testing includes PHPUnit and PHPStan (Level 9).
$ composer test
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
统计信息
- 总下载量: 16.35k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-24