Download the PHP package yuloh/pipeline without Composer
On this page you can find all versions of the php package yuloh/pipeline. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yuloh/pipeline
More information about yuloh/pipeline
Files in yuloh/pipeline
Package pipeline
Short Description A simple functional pipeline
License MIT
Homepage https://github.com/yuloh/pipeline
Informations about the package pipeline
Pipeline
Introduction
yuloh/pipeline is a simple functional pipeline. You can easily chain functions together to process a payload. It's a lot easier to read, and there are less temporary variables than doing it the old fashioned way.
Goals
This package aims to expose the simplest API possible.
The programming language elixir has a pipe operator (|>
) which lets you easily chain functions:
I really liked that syntax, and I wanted to write a pipeline package where I didn't have to write pipe
or add
over and over, hence this package.
Why PHP 7 Only?
PHP 7 introduced the Uniform Variable Syntax, which means we can do this:
Instead of something like this:
Install
Via Composer
Usage
To create a new pipeline, invoke the Yuloh\Pipeline\pipe
function with your payload.
Once it's created you can keep chaining stages by invoking the pipeline. The stage must be a valid PHP callable.
If you invoke the pipeline without a stage, the pipeline will be processed and the processed payload is returned.
All together, it looks like this:
Passing Arguments
When adding a stage, any additional arguments will be passed to the stage after the payload. For instance, if you were processing a JSON payload the pipeline might look like this:
In the previous example, json_decode
would be invoked as json_decode($payload, true)
to return an array.
Alternative Method Call Usage
You can also add stages as method calls instead of function arguments. It's a little more readable for pipelines that are only using standard functions.
Testing
License
The MIT License (MIT). Please see License File for more information.