lbhurtado/tactician

Extending joselfonseca/laravel-tactician

v2.2.0 2022-04-16 11:59 UTC

This package is auto-updated.

Last update: 2024-10-16 17:37:30 UTC


README

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.