定制 beebmx/pipeline 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

beebmx/pipeline

最新稳定版本:1.0.0

Composer 安装命令:

composer require beebmx/pipeline

包简介

Pipeline your code

README 文档

README

Build Status Total Downloads Latest Stable Version License

Pipeline

Package inspired by Laravel Pipeline, but without Laravel Container

Installation

Install using composer:

composer require beebmx/pipeline

Usage

The basic use of pipeline is:

use Beebmx\Pipeline\Pipeline;

$string = (new Pipeline)
    ->send('say')
    ->through([
        function($string, $next) {
            $string = $string.' hello';

            return $next($string);
        },
        function($string, $next) {
            $string = $string.' world';

            return $next($string);
        }
    ])->execute();

//$string will be 'say hello world'

Important

You should always call the $next callback with the pipe variable as argument for the next pipe or final result.

You can use a class insted of a Closure if that more your need:

use Beebmx\Pipeline\Pipeline;

class MyOwnPipe
{
    public function handle($myPipeObject, Closure $next)
    {
        $myPipeObject->process();
 
        return $next($myPipeObject);
    }
}

$result = (new Pipeline)
    ->send($someObject)
    ->through([
        MyOwnPipe::class,
        OtherPipe::class,
    ])->execute();

Note

By default Pipeline will triger the handle method.

If you need to change the default handle method in your pipe classes, you can do it like:

use Beebmx\Pipeline\Pipeline;

$result = (new Pipeline)
    ->send($someObject)
    ->via('myOwnMethod')
    ->through([
        MyOwnPipe::class,
        OtherPipe::class,
    ])->execute();

At the end of the pipe's flow, you can finish with the processing like:

use Beebmx\Pipeline\Pipeline;

$string = (new Pipeline)
    ->send('say')
    ->through(function($string, $next) {
        $string = $string.' hello';

        return $next($string);
    })->then(function($string) {
        $string = $string.' world';

        return $string;
    });

//$string will be 'say hello world'

You and add more pipes to the pipeline flow:

use Beebmx\Pipeline\Pipeline;

use Beebmx\Pipeline\Pipeline;

$string = (new Pipeline)
    ->send('say')
    ->through(function($string, $next) {
        $string = $string.' hello';

        return $next($string);
    })->pipe(function($string) {
        $string = $string.' world';

        return $string;
    })->execute();

//$string will be 'say hello world'

Testing

composer test

Credits

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-19