承接 juststeveking/laravel-business-process 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

juststeveking/laravel-business-process

最新稳定版本:0.0.1

Composer 安装命令:

composer require juststeveking/laravel-business-process

包简介

Laravel Business Process is a simple and clean way to run business process using a Laravel Pipeline, in a structured and type-safe way.

README 文档

README

Latest Version Software License Run Tests PHP Version Total Downloads

Laravel Business Process is a simple and clean way to run business process using a Laravel Pipeline, in a structured and type-safe way.

This package is inspired by the tutorial I wrote for Laravel News Going Past Actions in Laravel.

Installation

composer require juststeveking/laravel-business-process

Usage

To get started with this package, all you need to do is create a new process class:

use JustSteveKing\BusinessProcess\Process;

final class PurchaseProduct extends Process
{
    protected array $tasks = [
        CheckStockLevel::class,
        ProcessOrder::class,
        DecreaseStockLevel::class,
        NotifyWarehouse::class,
        EmailCustomer::class,
    ];
}

Our process class registers the tasks that need to be completed for this process to run, each task must implement the TaskContract interface that comes with this package.

use JustSteveKing\BusinessProcess\Contracts\TaskContract;

final class CheckStockLevel implements TaskContract
{
    public function __invoke(ProcessPayload $payload, Closure $next): mixed
    {
        // perform your logic here with the passed in payload.
        
        return $next($payload);
    }
}

Your tasks are standard classes that the Pipeline class from Laravel would expect.

The payload is a class that implements ProcessPayload interface, signalling that it is a payload for a process. They are simple plain old PHP classes with no requirements to add methods.

use JustSteveKing\BusinessProcess\Contracts\ProcessPayload;

final class PurchaseProductPayload implements ProcessPayload
{
    public function __construct(
        // add whatever public properties you need here
        public int $product,
        public int $user,
        public int $order,
    ) {}
}

Finally, we can call this process within our controller/job/cli wherever you need to.

final class PurchaseController
{
     public function __construct(
        private readonly PurchaseProduct $process,
     ) {}
     
     public function __invoke(PurchaseRequest $request, int $product): JsonResponse
     {
        try {
            $this->process->run(
                payload: $request->payload(),
            );
        } catch (Throwable $exception) {
            // Handle exception
        }
        
        // return response.
     }
}

Testing

To run the test:

composer run test

Credits

LICENSE

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

统计信息

  • 总下载量: 3.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 67
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 67
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-27