DeSmart / laravel-commandbus by DeSmart

DeSmart CommandBus for Laravel
3,395
0
5
Package Data
Maintainer Username: DeSmart
Maintainer Contact: gollum@desmart.com (Michał Golon)
Package Create Date: 2016-02-03
Package Last Update: 2020-11-02
Language: PHP
License: MIT
Last Refreshed: 2024-11-14 15:13:18
Package Statistics
Total Downloads: 3,395
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 0
Total Watchers: 5
Total Forks: 0
Total Open Issues: 0

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);
    }
}