lbhurtado/tactician

Extending joselfonseca/laravel-tactician
1,325
Install
composer require lbhurtado/tactician
Latest Version:v2.2.0
PHP:~7.2||^8.0.1
License:MIT
Last Updated:Apr 16, 2022
Links: GitHub  ·  Packagist
Maintainer: lbhurtado

lbhurtado/tactician

Latest Version on Packagist Build Status Quality Score Total Downloads

This is just an extension of joselfonseca/laravel-tactician package implementing the ActionAbstract class.

Installation

You can install the package via composer:

composer require lbhurtado/tactician

Usage

use LBHurtado\Tactician\Classes\ActionAbstract;
use LBHurtado\Tactician\Contracts\ActionInterface;

class CreateSMSAction extends ActionAbstract implements ActionInterface
{
    protected $fields = ['from', 'to', 'message'];

    protected $command = CreateSMSCommand::class;

    protected $handler = CreateSMSHandler::class;

    protected $middlewares = [
        CreateSMSValidator::class,
        CreateSMSResponder::class,
    ];

    public function setup()
    {
        // TODO: Implement setup() method.
    }
}
use LBHurtado\Tactician\Contracts\CommandInterface;

class CreateSMSCommand implements CommandInterface
{
    public $from;

    public $to;

    public $message;

    public function __construct($from, $to, $message)
    {
        $this->from = $from;
        $this->to = $to;
        $this->message = $message;
    }

    public function getProperties():array
    {
        return [
            'from' => $this->from,
            'to' => $this->to,
            'message' => $this->message,
        ];
    }
}
use LBHurtado\Tactician\Contracts\CommandInterface;
use LBHurtado\Tactician\Contracts\HandlerInterface;

class CreateSMSHandler implements HandlerInterface
{
    protected $smss;

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

    public function handle(CommandInterface $command)
    {
        $this->smss->create([
            'from' => $command->from,
            'to' => $command->to,
            'message' => $command->message,
        ]);
    }
}
use League\Tactician\Middleware;

class CreateSMSResponder implements Middleware
{
    public function execute($command, callable $next)
    {
        $next($command);

        return (new CreateSMSResource($command))
            ->response()
            ->setStatusCode(200)
            ;
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email lester@hurtado.ph instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

Related Packages

xtrasmal/tactician-provider

Laravel ServiceProvider for the Tactician CommandBus library

6 0
gearhub/tactician-for-laravel

Laravel 5+ wrapper for Tactician

382 1
lbhurtado/common

This is a utility package for lbhurtado/{missive, sms, tactician, engagespark}.

9,189 0
lbhurtado/engagespark

This package makes it easy to send SMS notifications and topups via engageSPARK...

8,561 0