gpslab / middleware
TInfrastructure for use middleware in applications
v1.1.0
2017-07-17 12:00 UTC
Requires
- php: >=5.5.0
Requires (Dev)
- gpslab/cqrs: ~1.0
- gpslab/domain-event: ~2.0
- phpunit/phpunit: ~4.8
- psr/container: ~1.0
- psr/log: ~1.0
- satooshi/php-coveralls: ^1.0
- scrutinizer/ocular: ~1.3
- symfony/dependency-injection: ~2.3|~3.0
- symfony/validator: ~2.3|~3.0
This package is auto-updated.
Last update: 2024-11-15 19:37:09 UTC
README
Infrastructure for use middleware in applications
Installation
Pretty simple with Composer, run:
composer require gpslab/middleware
Middleware chain
MiddlewareChain
contains a middlewares (Middleware
) and sequentially apply them to the message by chain.
There are 3 implementations of the chain, but you can make your own.
DirectBindingMiddlewareChain
- direct binding;ContainerMiddlewareChain
- PSR-11 container;SymfonyContainerMiddlewareChain
- Symfony container (Symfony 3.3 implements a PSR-11).
Handle command (CQRS)
Example usage middleware for handle Commands in CQRS.
// middleware chain $chain = new DirectBindingMiddlewareChain(); // add logger middleware $chain->append(new LoggerMiddleware($logger)); // add validator middleware $chain->append(new ValidatorMiddleware($validator)); // add middleware for handle command from origin command bus $chain->append(new CommandMiddleware($command_bus)); // configure command bus $bus = new MiddlewareCommandBus($chain); // handle command try { $bus->handle($my_command); } catch(InvalidMessageException $e) { // show validation errors var_dump($e->getMessages()); }
Handle query (CQRS)
Example usage middleware for handle Queries in CQRS.
// middleware chain $chain = new DirectBindingMiddlewareChain(); // add logger middleware $chain->append(new LoggerMiddleware($logger)); // add validator middleware $chain->append(new ValidatorMiddleware($validator)); // add middleware for handle query from origin query bus $chain->append(new QueryMiddleware($query_bus)); // configure query bus $bus = new MiddlewareQueryBus($chain); // handle query try { $bus->handle($my_query); } catch (InvalidMessageException $e) { // show validation errors var_dump($e->getMessages()); }
Handle Domain event
Example usage middleware for handle domain events.
// middleware chain $chain = new DirectBindingMiddlewareChain(); // add logger middleware $chain->append(new LoggerMiddleware($logger)); // add middleware for handle event from origin domain event bus $chain->append(new DomainEventMiddleware($domain_event_bus)); // configure domain event bus $bus = new MiddlewareDomainEventBus($chain); // publish domain event $bus->publish($my_event);
License
This bundle is under the MIT license. See the complete license in the file: LICENSE