Menu


Commands


EventBus


Other Packages

Papertrail

Command Bus Middleware


Command Bus Middleware is a convenient way to manipulate or gather information of command before and after its processes by the command bus.

Interface


interface CommandBusMiddleware
{
    /**
     * @param Command $command
     * @param callable $next
     * @return mixed
     */
    public function execute(Command $command, callable $next);
}

Middleware Chain


The command bus builds a chain on middlware for execution. You pass in a array of CommandBusMiddleware when building the command bus.

If you build your own you need to always pass last the middleware that runs the handler CommandHandlerMiddleWare

Example Middleware


This basic example show you how to moniter and log commands before and after they run

     /**
     * @param $command
     * @param callable $next
     * @return mixed
     */
    public function execute(Command $command, callable $next)
    {
        logger('Command Running'  . get_class($command));
        $result = $next($command);
        logger('Command Finished'  . get_class($command));
        
        return $result
    }