desmart/laravel-commandbus

DeSmart CommandBus for Laravel
3,395
Install
composer require desmart/laravel-commandbus
Latest Version:1.1.1
PHP:>=5.6.0
Laravel:5
License:MIT
Last Updated:Nov 2, 2020
Links: GitHub  ·  Packagist
Maintainer: DeSmart

Laravel CommandBus

A small, pluggable command bus.

Instalation

  1. $ composer require desmart/laravel-commandbus
  2. Add DeSmart\CommandBus\ServiceProvider to app.php

Example usage:

Command Class

class RegisterUserCommand
{
    protected $email;

    public function __construct($email)
    {
        $this->email = $email;
    }

    public function getEmail()
    {
        return $this->email;
    }
}

CommandValidator Class

class RegisterUserCommandValidator
{
    public function validate(RegisterUserCommand $command)
    {
        // it will be called before handler
    }
}

CommandHandler Class

class RegisterUserCommandHandler
{
    public function handle(RegisterUserCommand $command)
    {
        // it will be called if validator won't throw any exception
    }
}

Execute the command:

class Controller
{
    /**
     * @var \DeSmart\CommandBus\Contracts\CommandBus
     */
    protected $commandBus;

    public function __construct(\DeSmart\CommandBus\Contracts\CommandBus $commandBus)
    {
        $this->commandBus = $commandBus;
    }

    public function index()
    {
        $command = new RegisterUserCommand("foo@bar.net");
        $this->commandBus->handle($command);
    }
}

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

598,760,099 34,966
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

403,217,078 4,664

Version History

Version Released PHP Laravel License
1.1.1 >=5.6.0 5.1.* | ~5.2 MIT
1.1.0 >=5.6.0 ~5.2 MIT
1.0.1 >=5.6.0 ~5.1 MIT
1.0.0 >=5.6.0 ~5.1 MIT