/rings

Rings allows you to create and dispatch sequential, decorable, filterable and/or composable pipelines.

Primary LanguagePHPMIT LicenseMIT

Rings

Rings allows you to create and dispatch sequential, decorable, filterable and/or composable pipelines.

Table of Contents

Benefits

  • Be highly composable.
  • Be immutable.

Features

Rings are implemented as immutable chains. When you enqueue a new decorator, a new stage will be created with the added decorator.

You can enqueue decorators that add functionality to the pipeline. You can enqueue decorators that filter the operations to be done on data. You can enqueue decorators which add sub pipelines.

This makes pipelines easy to reuse, highly composable, and minimizes side-effects.

Prerequisites

  • PHP 7.2.0

Yes, that's the only hard requirement.

Installation

Use Composer

$ composer require guglielmopepe/rings

Usage

// create pipeline
$pipeline = new \Rings\Classes\Pipeline(new \SplQueue());

// add decorators: 
$pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 1 <br />';return $data;}));
$pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 2 <br />';return $data;}));
$pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 3 <br />';return $data;}));

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data([]));

Documentation

Create pipeline like macro

// create pipeline
$pipeline = new \Rings\Classes\Pipeline(new \SplQueue());

// add decorators: 
$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        return new \Rings\Classes\Data(['foo' => '***' . $data['foo'] . '***']);
    })
);

$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        return new \Rings\Classes\Data(['foo' => '___' . $data['foo'] . '___']);
    })
);

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => 'bar']));


// print ___***bar***___
echo $data['foo'];

Create pipeline with filter

// create pipeline
$pipeline = new \Rings\Classes\Pipeline(new \SplQueue());

// add decorators: 
$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        if (strpos($data['foo'], '***') !== FALSE)
        {
            return $data;
        }

        return new \Rings\Classes\Data(['foo' => '***' . $data['foo'] . '***']);
    })
);

$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        if (strpos($data['foo'], '___') !== FALSE)
        {
            return $data;
        }

        return new \Rings\Classes\Data(['foo' => '___' . $data['foo'] . '___']);
    })
);

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => 'bar']));


// print ___***bar***___
echo $data['foo'];

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => '***bar***']));


// print ***bar***
echo $data['foo'];

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => '___bar___']));


// print ***bar***
echo $data['foo'];

Support

If you have a request, please create a GitHub issue.

If you discover a security vulnerability, please send an email to Guglielmo Pepe at info@guglielmopepe.com. All security vulnerabilities will be promptly addressed.

Faq

To do

Contributing

If you want to say thank you and/or support the active development of Rings:

  1. Add a GitHub Star to the project.
  2. Share the project on social media.
  3. Write a review or tutorial on Medium, Dev.to or personal blog.

Contacts

If you need information please send an email to info@guglielmopepe.com.

Roadmap

See the list of open issues:

Change log

Please see Changelog file for more information on what has changed recently.

License

Distributed under the MIT License. Please see License File for more information.