jamielsharief / pipeline

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pipeline

license build coverage status

My implementation of the Pipeline pattern based upon this article.

In my case, I needed to download data from an API, run it through a Service Object, then run through another Service Object. It is mainly used to execute code through a series of stages and then yeild a final value but it can also be used to make complex code more readable.

Installation

$ composer require jamielsharief/pipeline

Creating a Handler

Create a Handler for each stage in the pipeline

class DownloadData implements HandlerInterface
{
    /**
     * Handler code
     */
    public function handle($payload = null)
    {
        
    }
}

Creating the Pipeline

Create the pipeline

$pipeline = (new Pipeline(new DownloadData()))
    ->add(new CleanUpData())
    ->add(new ConvertToJson())
    ->add(new AddToDatabase());

When you want to execute it call the dispatch method and pass any payload.

$pipeline->dispatch('8a967e35-f818-43e9-931a-f7f5b6760793');

About

License:MIT License


Languages

Language:PHP 100.0%