2017 © Pedro Peláez
 

library pipeline

Simple library to send data through a chain of tasks

image

gnumast/pipeline

Simple library to send data through a chain of tasks

  • Tuesday, November 10, 2015
  • by gnumast
  • Repository
  • 0 Watchers
  • 5 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Pipeline

Build Status, (*1)

Pipeline allows to easily chain operations / tasks on the fly or create a reusable chain of commands. Complete documentation is available., (*2)

Installation

composer require gnumast/pipeline

Basic usage

Here's a trivial example., (*3)

class MakeAllCaps implements TaskInterface {
    public function run($data) {
        return mb_strtoupper($data);
    }
}

class RemoveAllSpaces implements TaskInterface {
    public function run($data) {
        return str_replace(' ', '', $data);
    }
}

$pipeline = new Pipeline(
    new MakeAllCaps(),
    new RemoveAllSpaces()
);
$pipeline->execute("Hello, my name is Steve"); // HELLO,MYNAMEISSTEVE

For simple chains where defining a brand new class isn't really worth it, or if you quickly want to chain things together, the CallablePipe class wraps anonymous functions to be passed as pipes., (*4)

$pipeline = new Pipeline(
    new CallablePipe(function($data) {
return $data * 10;
    }),
    new CallablePipe(function($data) {
return $data + 50;
    })
);

$result = $pipeline->execute(10); // 150

You don't have to pass all of your tasks at initialisation time. Pipeline provides an add method to add steps to an existing object:, (*5)

$pipeline = new Pipeline(new MakeAllCaps());
$pipeline->add(new RemoveAllSpaces());
$pipeline->execute("Hello, world!"); // HELLO,WORLD!

The Versions

10/11 2015

dev-master

9999999-dev

Simple library to send data through a chain of tasks

  Sources   Download

GPL-2.0

The Requires

  • php >=5.6

 

by Alex Marcotte