gpslab/middleware

TInfrastructure for use middleware in applications

v1.1.0 2017-07-17 12:00 UTC

This package is auto-updated.

Last update: 2024-12-15 19:49:46 UTC


README

Latest Stable Version Total Downloads Build Status Coverage Status Scrutinizer Code Quality SensioLabs Insight StyleCI License

Infrastructure for use middleware in applications

Request delegate pipeline

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