mohmann / hexagonal
提供构建使用六边形架构的应用程序的实用工具
v0.2.0
2018-10-21 15:33 UTC
Requires
- php: ^7.1
- psr/container: ^1.0
- psr/log: ^1.0
- symfony/event-dispatcher: ^4.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.12
- infection/infection: ^0.10.5
- phake/phake: ^3.1
- phpbench/phpbench: ^0.14.0
- phpmetrics/phpmetrics: ^2.4
- phpstan/phpstan: ^0.10.1
- phpunit/phpunit: ^6.0
- spatie/phpunit-watcher: ^1.5
- symfony/dependency-injection: ^4.1
This package is auto-updated.
Last update: 2024-09-22 05:35:30 UTC
README
此包提供了构建使用六边形架构(又名端口和适配器)的PHP应用程序的基本构件。
安装
通过composer
composer require mohmann/hexagonal
使用示例
<?php use mohmann\Hexagonal\Command\AbstractCommand; use mohmann\Hexagonal\Command\Bus\SimpleCommandBus; use mohmann\Hexagonal\CommandInterface; use mohmann\Hexagonal\Exception\HexagonalException; use mohmann\Hexagonal\Handler\Resolver\HandlerResolver; use mohmann\Hexagonal\HandlerInterface; require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php'; class FooCommand extends AbstractCommand { public $payload; public function __construct(string $payload) { $this->payload = $payload; } } class FooHandler implements HandlerInterface { /** * {@inheritDoc} */ public function handle(CommandInterface $command) { return \sprintf('%s baz', $command->payload); } } $handlerResolver = new HandlerResolver([ FooCommand::class => new FooHandler(), ]); $commandBus = new SimpleCommandBus($handlerResolver); try { $command = new FooCommand('bar'); $result = $commandBus->execute($command); var_dump($result); } catch (HexagonalException $e) { var_dump($e); }
查看examples子目录以获取更多使用示例。
开发和测试
参考Makefile
以获取有用的命令,例如。
make stan
make test
make inf
许可证
hexagonal在MIT许可证下发布。有关详细信息,请参阅捆绑的LICENSE文件。