sparhandy/pipeandfilter

Pipe and Filter Architecture

1.0.1.1 2018-01-08 12:11 UTC

This package is not auto-updated.

Last update: 2024-05-22 07:35:41 UTC


README

Build Status Github Releases Release Packagist

PipeAndFilter

This repository contains all necessary files to use the Pipe & Filter Architecture in PHP.

Installation with composer

composer require "sparhandy/pipeandfilter"

Usage

PipeFactory

<?php 
// Implements \Sparhandy\PipeAndFilter\FilterInterface
$exampleFilterFoo = new Acme\Filter\Foo(); 
$exampleFilterBar = new Acme\Filter\Bar(); 
$exampleFilterBaz = new Acme\Filter\Baz(); 

$filters = [
  $exampleFilterFoo,  
  $exampleFilterBar,  
  $exampleFilterBaz,  
];

$factory = new \Sparhandy\PipeAndFilter\PipeFactory();
$pipe = $factory->build($filters);

// The variable, to be processed by the $filters
$context = [];

// The context, to be processed by the $filters
$someParameter = [
    'foo' => 'bar',
];

$pipe->run($context, $someParameter);

// $context is now modified by your filters.
?>

Filter

<?php 

class FooFilter implements Sparhandy\PipeAndFilter\FilterInterface
{
    /**
     * @param mixed   $context
     * @param mixed[] $someParameter
     *
     * @return void
     */
    public function execute(&$context, array $someParameter)
    {
        if (isset($context['foo']))
        {
            $context['bar'] = $someParameter['baz'];
        }
    }
}
?>

How to contribute

If you want to contribute to the standard here is how it works.

  • Create a fork of Sparhandy/PipeAndFilter.
  • Create your branch from master and commit your changes.
  • Push your branch to your fork.
  • Create a pull request on GitHub.
  • Discuss your pull request with us.
  • Our devs will then merge or close the pull request.