定制 ice-cream/pipeline 二次开发

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

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

ice-cream/pipeline

Composer 安装命令:

composer require ice-cream/pipeline

包简介

ice-cream pipeline is used to pass something through a pipeline and have it processed and passed back out.

README 文档

README

Build Status Packagist Maintenance Made With Love

This is a basic implementation of the pipeline pattern, wherein something is passed through a series of classes and the end result is passed out.

  • Requires PHP 7.2
  • Is standalone

Purpose

I wanted to build this for the Ice cream framework, it would be useful in passing object in through a pipeline and manipulating them.

I also built this to learn the pipeline pattern and how it is used and how other frameworks use the pattern when manipulating objects.

Install

composer require ice-cream/pipeline

Documentation

You can see the full documentation for the project here

How to use?

class AddOne {

    public function customHandle(int $number) {
        return $number + 1;
    }

    public function handle(int $number) {
        return $number + 1;
    }
}

class TimesTwo {

    public function customHandle(int $number) {
        return $number * 2;
    }

    public function handle(int $number) {
        return $number * 2;
    }
}

$response = (new Pipeline())
    ->pass(10)
    ->through([
        new AddOne,
        new TimesTwo,
    ])
    ->withMethod('customHandle')
    ->process()
    ->getResponse();

var_dump($response); // => 22

What you will notice here is that we have a set of classes, the value 10 is passed through both of these and then returned in the getResponse(), the reason we do not do this, returning the response in process, is because you might want to call a new method: then() which takes a closure, as you will see in the examples below.

then(\Closure $func)

Building on the above example, lets assume you want to do something after you process the value, or object passed in:

(new Pipeline())
    ->pass(10)
    ->through([
        new AddOne,
        new TimesTwo,
    ])
    ->withMethod('customHandle')
    ->process()
    ->then(function($response) {
        $response *= 10;

        var_dump($response); // => 220
    });

You cannot call getResponse because this is a closure, and anonymous function.

What if I don't have a custom method?

(new Pipeline())
    ->pass(10)
    ->through([
        new AddOne,
        new TimesTwo,
    ])
    ->process()
    ->then(function($response) {
        $response *= 10;

        var_dump($response); // => 220
    });

Building on the above, we see that the classes, AddOne and TimesTwo implement a handle() method. If you do not define a withMethod(String $string) then we default to the handle method that must be implemented or you get an \Exception thrown telling you which class failed to implement the method in question.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固