2017 © Pedro Peláez
 

library pipeline-remix

Reinvented pipelines for PHP

image

alexmanno/pipeline-remix

Reinvented pipelines for PHP

  • Wednesday, December 13, 2017
  • by alexmanno
  • Repository
  • 1 Watchers
  • 2 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

pipeline-remix

Reinvented pipelines for PHP, (*1)

Latest Stable Version Latest Unstable Version GitHub license composer.lock available Scrutinizer Code Quality Code Coverage Build Status, (*2)

What's a Pipeline

A pipeline is a set of data processing elements connected in series, where the output of one element is the input of the next one., (*3)

Installation

From Composer

To use this package, use Composer:, (*4)

  • from CLI: composer require alexmanno/pipeline-remix
  • or, directly in your composer.json:
{
    "require": {
        "alexmanno/pipeline-remix": "dev-master"
    }
}

Architecture

Pipeline

A Pipeline is a simple SplQueue of Stage., (*5)

You can initialize it in this way: $pipeline = new AlexManno\Remix\Pipelines\Pipeline();, (*6)

You can add Stage to Pipeline using $pipeline->pipe($stage), (*7)

Stage

A Stage is an object that implements AlexManno\Remix\Pipelines\Interfaces\StageInterface and has an __invoke() method., (*8)

This object is the smallest part of the pipeline and it should be a single operation., (*9)

You can create a class that implements that interface., (*10)

Ex., (*11)

 class MyCoolStage implements AlexManno\Remix\Pipelines\Interfaces\StageInterface
 {
    /**
     * @param Payload $payload
     */
    public function __invoke(Payload $payload)
    {
        $payload->setData('Hello!');

        return $payload;
    }
}

Payload

Payload is an object that implements PayloadInterface and can store any kind of data. For example in a web application it can store Request and Response., (*12)

Ex., (*13)

class Payload implements AlexManno\Remix\Pipelines\Interfaces\PayloadInterface
{
    /** @var RequestInterface */
    public $request;
    /** @var ResponseInterface */
    public $response;
}

Compose and run your pipeline

If you have already initialized Payload object and Stages objects you can compose your pipeline., (*14)

Ex., (*15)

// -- Initialized objects: $payload, $pipeline, $stage1, $stage2 --

$pipeline
    ->pipe($stage1) // Add $stage1 to queue
    ->pipe($stage2); // Add $stage2 to queue

$pipeline($payload);  // Run pipeline: invoke $stage1 and then $stage2 with payload from $stage1

You can also compose two or more pipelines together using method add(), (*16)

Ex., (*17)

// -- Initialized objects: $payload, $pipeline1, $pipeline2, $stage1, $stage2 --

$pipeline1->pipe($stage1); // Add $stage1 to $pipeline1
$pipeline2->pipe($stage2); // Add $stage2 to $pipeline2

$pipeline1->add($pipeline2); // Add stages from $pipeline2

$payload = $pipeline1($payload); // Run pipeline: invoke $stage1 (from $pipeline1) and then $stage2 (from $pipeline2) with payload from $stage1

Examples

Conclusion

I hope you found useful this repo. Thanks for attention., (*18)

Made with :heart: by @alexmanno, (*19)

The Versions