bezdomni/tactician-pimple
Composer 安装命令:
composer require bezdomni/tactician-pimple
包简介
Tactician command locator for the Pimple DI container
README 文档
README
Allows lazy loading of command handlers from a Pimple dependency injection container.
Install
Install via composer
composer require bezdomni/tactician-pimple
Usage
Presuming you have a couple of commands: UserAddCommand, UserDeleteCommand,
and corresponding handlers UserAddHandler, UserDeleteHandler.
use Bezdomni\Tactician\Pimple\PimpleLocator; use League\Tactician\CommandBus; use League\Tactician\Handler\CommandHandlerMiddleware; use League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor; use League\Tactician\Handler\MethodNameInflector\HandleInflector; use Pimple\Container; // Create a container and configure the handlers on it $container = new Container(); $container['handlers.user.add'] = function () { echo "Creating AddUserHandler\n"; return new AddUserHandler(); }; $container['handlers.user.delete'] = function () { echo "Creating DeleteUserHandler\n"; return new DeleteUserHandler(); }; // Map command class names to container keys holding corresponding handlers $locatorMap = [ AddUserCommand::class => 'handlers.user.add', DeleteUserCommand::class => 'handlers.user.delete', ]; // Create the locator $locator = new PimpleLocator($container, $locatorMap); // Create a command handler middleware using the pimple locator $middleware = new CommandHandlerMiddleware( new ClassNameExtractor(), $locator, new HandleInflector() ); // Create the command bus using the middleware, and you're ready to go $commandBus = new CommandBus([$middleware]); // Create and run commands on the command bus $addUserCommand = new AddUserCommand(); $deleteUserCommand = new DeleteUserCommand(); $commandBus->handle($addUserCommand); $commandBus->handle($deleteUserCommand);
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 21.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-23