mohmann / hexagonal
Provides utilities to build application using hexagonal architecture
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-12-22 06:11:03 UTC
README
This package provides the building blocks to build PHP applications using Hexagonal Architecture (a.k.a. Ports-and-Adapters).
Installation
Via composer:
composer require mohmann/hexagonal
Usage example
<?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); }
Check the examples subdirectory for more usage examples.
Development / Testing
Refer to the Makefile
for helpful commands, e.g.:
make stan
make test
make inf
License
hexagonal is released under the MIT License. See the bundled LICENSE file for details.