Download the PHP package andydune/pipeline without Composer
On this page you can find all versions of the php package andydune/pipeline. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andydune/pipeline
More information about andydune/pipeline
Files in andydune/pipeline
Package pipeline
Short Description Provides a pipeline pattern. Based on middleware approach.
License MIT
Homepage https://github.com/AndyDune/Pipeline
Informations about the package pipeline
AndyDune\Pipeline
This package provides a pipeline pattern implementation. It is based on middleware approach.
Requirements
PHP version >= 7.1
For php 5.6 use version 1:
Installation
Installation using composer:
Or if composer was not installed globally:
Or edit your composer.json
:
And execute command:
Usage
Operations in pipeline stages, can be anything that satisfies the callable
type-hint. So closures and anything that's invokable is good.
Types of stages
Basically each stage can be Closure
:
It can be an instance of class with callable interface:
It can be an instance of class with any method:
It can be a class name with method __invoke
or any method you describe:
It can be a class name with any method you describe:
Use object for stage without middleware interface
You can use methods which don't execute $next function. It gets some data and return results. There is special method: 'pipeForContainer'
Example class.
Container provider (service provider)
String can de passed as pipeline stage. By default it is a class name.
It's make possible by using default provider: AndyDune\Pipeline\PipeIsClassName
You can set your own provider, with injections you need. Your class must implements interface: Interop\Container\ContainerInterface
If was not found stage with your provider system will try to use default provider. There is stack of providers.
Use your provider as parameter for pipeline constructor:
Additional parameters for stage
Sometimes you need to pass any number of additional parameters to pipe stage during description. It needs for test and it very good for more flexibility of stage. It increases reuse of class.
Lets look at the example. It is very simple example.
Here is example class for stage:
Lets use it:
Dependency injection
You can use default pipeline stage creator with injection into stage objects services or any objects from outside.
There is injection with interfaces.
This use method addInitializer
which receive callable parameter.
Exceptions
Package has not integrated exception catch support. It is simple for you to include exception try-catch block into one of pipeline stages.
There is a class you may use as stage for your pipeline for catch exception in this package.
Examples
Caching
You have service for retrieve data. And you don't need to change its code. Just use it as a stage in the pipeline.
Usage within Zend FW 3
By default string as stage for pipeline means name of class.
If you create pipeline object without parameters service container implements AndyDune\Pipeline\PipeIsClassName
. It only creates instance of given class and return it.
If this package is used as part of of Zend FW 3 you can use Zend's services for retrieve instances.
First you must install package with composer.
Then copy file vendor/andydune/pipeline/config/pipeline.global.php
to config/autoload/pipeline.global.php
Description fot your pipeline in factory:
If you don't work with Zend services use pipeline directly.
Analogues
Laravel pipeline - it do very the same I wanted, but I need more tools for testing purpose. And I don't like laraver service manager. it has not common interface. My pipeline may use service managers based on container-interop with PSR-11 interfaces.
League\Pipeline - it has good documentation. But has bad feature - poor workflow control. To stop execution it need to use exception.