simplemehanizm/pipeline 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

simplemehanizm/pipeline

最新稳定版本:v1.0.0

Composer 安装命令:

composer require simplemehanizm/pipeline

包简介

Define pipelines using array of stages

README 文档

README

Pipeline is series of steps where output of previous is input of next step. Pipeline pattern is useful for breaking down complex logic by encapsulating each step as a stage, or the minimum work that needs to be done by a function. Each stage operates on common input known as state. Essentially, a state object is mutated by a series of stage objects. The end result, the end state, is the outcome.

Pipelines are easy to test since it's sufficient to mutate the state and adjust it before passing it to the stage.

Installation

composer require simplemehanizm/pipeline

How to use

use SimpleMehanizm\Pipeline;

class SetIDStage
{
    public function handle(object $state): object
    {
        $state->id = 1; // change state, set the arbitrary ID value to 1
    
        return $state;
    }    
}

class SetTitleStage
{
    public function handle(object $state): object
    {
        $state->title = 'This is the title';
        
        return $state;
    }
}

$state = new class {
    public function __construct(
        public int $id = 0,
        public string $title = ''
    ){}
}

$stages = [
    SetIDStage::class,
    SetTitleStage::class
];

$pipeline = new Pipeline();

$result = $pipeline->send($state)->through($stages)->then(function(object $state) {
    return [
        'id' => $stage->id,
        'title' => $stage->title 
    ]
});

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-12-15