Download the PHP package sassnowski/pipeline without Composer
On this page you can find all versions of the php package sassnowski/pipeline. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sassnowski/pipeline
More information about sassnowski/pipeline
Files in sassnowski/pipeline
Package pipeline
Short Description A simple pipeline implementation for PHP.
License MIT
Informations about the package pipeline
PHP Pipeline
A simple Pipeline implementation for PHP.
Summary
This package enables you to send a value through a sequence of steps. Each step operates on the return value of the previous step. Without a pipeline you would end up with deeply nested function calls like this.
Using a pipeline you can transform the above example to this:
This makes the order of steps executed a lot clearer and gets rid of the annoying and ugly nesting of function calls.
Usage
Building reusable pipelines
The through($fn)
method does not change the existing Pipeline, but instead returns a new Pipeline instance that includes
the next step. This enables you to reuse parts of a pipeline.
Since seeding the pipeline with an initial value goes against the idea of reusability, an additional method build()
is defined.
The build
method does not initialize the pipeline with value. In this case the value has to be provided when calling the run
method.
Class-based steps
It is possible to use classes as steps instead of function. All the class has to do is implement the magic __invoke
method.
This is useful if the execution of a step requires a lot of additional business logic that does not belong inside the object containing the Pipeline.
Exceptions
If a step is added to the pipeline that fails the is_callable
check an InvalidArgumentException
will be thrown.
If the build
method was used to create a pipeline, the initial value has to be passed to then run
method. Failing to do so
will result in a RuntimeException
.
Method aliases
In order to enable a more easily readable syntax when building a pipeline several method aliases for the through
method exist.
firstThrough()
andThen()
License
MIT