luri / tactician-container-auto
为任何实现 PSR-11 并具有自动查找处理器的容器集成的 Tactician 集成(基于 tactician-container)
v1.0
2021-02-20 14:51 UTC
Requires
- php: >=5.5
- league/tactician-container: ^2.0
- psr/container: ^1.0
README
此插件允许从 PSR-11
容器中懒加载 CommandHandlers。
此插件为 league/tactician-container 插件添加了自动查找功能。它需要 league/tactician-container
此功能非常有用,可以在不更改您的总线配置的情况下添加更多命令。
安装
通过 Composer
$ composer require luri/tactician-container-auto
使用方法
此插件基于 league/tactician-container。tactician-container 的文档可在 官方网站 上找到。
要使自动查找处理器功能工作,您必须遵循以下命名约定:处理器类必须命名为:{CommandClassName}Handler。并且此类必须为您的 PSR11 容器所知。
例如:命令:AddTrampoline,处理器:AddTrampolineHandler
设置可能比 tactician-container 简单一些:(此示例改编自官方示例)(http://tactician.thephpleague.com/plugins/container/)
// Create a new Tactician ContainerLocator, passing a fully configured container instance.
use Luri\Tactician\ContainerLocatorWithAutofind;
$containerLocator = new ContainerLocatorWithAutofind($container);
// Finally, we pass the ContainerLocator into the CommandHandlerMiddleware that
// we use in almost every CommandBus.
$commandHandlerMiddleware = new CommandHandlerMiddleware(
new ClassNameExtractor(),
$containerLocator,
new HandleInflector()
)
// And that's it! Drop it in our command bus and away you go.
$commandBus = new CommandBus(
[
// your other middlewares...
$commandHandlerMiddleware,
]
);
测试
目前没有测试。待续...
致谢
安全
披露信息可在 Tactician 主存储库 上找到。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。