decodelabs/pandora
最新稳定版本:v0.4.1
Composer 安装命令:
composer require decodelabs/pandora
包简介
Potent PSR-11 depdency injection container
README 文档
README
PSR-11 dependency injection container
Pandora offers a simple, powerful and flexible dependency injection and instantiation system to used as the core of your application.
Installation
This package requires PHP 8.4 or higher.
Install via Composer:
composer require decodelabs/pandora
Usage
Instantiate a new Container to keep your important objects organised:
use DecodeLabs\Pandora\Container; $container = new Container();
Bind instances or classes to interfaces and retrieve them when you need them:
use My\Library\CoolInterface; use My\Library\CoolImplementation; // Implements CoolInterface // Instance $container->bind(CoolInterface::class, new CoolImplementation()); $imp = $container->get(CoolInterface::class); // Will only bind if CoolInterface has not been bound before $container->tryBind(CoolInterface::class, new OtherImplementation()); // Will not bind $imp = $container->get(CoolInterface::class); // Bind a factory $container->bind(CoolInterface::class, fn() => new CoolImplementation());
Retrieval
Parameters can be passed to constructors of implementation classes:
$imp = $container->getWith(CoolInterface::class, ['list', 'of', 'params']); // Or inject parameters for later: $container->inject(CoolInterface::class, 'paramName', 'paramValue'); $imp = $container->get(CoolInterface::class);
Access the binding controllers:
$binding = $container->getBinding(CoolInterface::class);
Licensing
Pandora is licensed under the MIT License. See LICENSE for the full license text.
统计信息
- 总下载量: 20.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-10