Process Pipe Component in PHP
This free as in freedom component ease up creation of a pipe) for processes in php.
Indeed, it is a pseudo pipeline#Pseudo-pipelines) (process collection or process batch) since the php process is single threaded so far.
Currently, there is no plan to bloat the code base with an implementation of STDIN, STDOUT or STDERR.
Errors can be handled by the thrown exception. Input is defined by the ExecutableInterface, as well as the output (return value).
The build status of the current master branch is tracked by Travis CI:
The scrutinizer status are:
The versioneye status is:
Downloads:
It is also available at openhub.net.
Why?
-
separate complex operations into simpler
-
easy up unit testing for smaller processes
-
separate responsibility (data generator/transformer/validator/flow manipulator)
-
create process chains you can read in the code (separate integration code from operation code)
-
no dependencies (except you want to join the development team)
Examples
Install
By Hand
mkdir -p vendor/net_bazzline/php_component_process_pipe
cd vendor/net_bazzline/php_component_process_pipe
git clone https://github.com/bazzline/php_component_process_pipe
composer require net_bazzline/php_component_process_pipe:dev-master
Usage
By using the pipe method for multiple process
use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;
try {
$pipe = new Pipe();
$pipe->pipe(
new ProcessOne(),
new ProcessTwo()
);
$output = $pipe->execute($input);
} catch (ExecutableException) {
//handle process exception
} catch (InvalidArgumentException) {
//handle pipe exception
}
By using the pipe method once for each process
use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;
try {
$pipe = new Pipe();
$pipe->pipe(new ProcessOne());
$pipe->pipe(new ProcessTwo());
$output = $pipe->execute($input);
} catch (ExecutableException) {
//handle process exception
} catch (InvalidArgumentException) {
//handle pipe exception
}
By instantiation
use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;
try {
$pipe = new Pipe(
new ProcessOne(),
new ProcessTwo()
);
$output = $pipe->execute($input);
} catch (ExecutableException) {
//handle process exception
} catch (InvalidArgumentException) {
//handle pipe exception
}
By doing all
use Net\Bazzline\Component\ProcessPipe\ExecutableException;
use Net\Bazzline\Component\ProcessPipe\InvalidArgumentException;
use Net\Bazzline\Component\ProcessPipe\Pipe;
try {
$pipe = new Pipe(
new ProcessOne(),
new ProcessTwo()
);
$pipe->pipe(new ProcessThree());
$pipe->pipe(
new ProcessFour(),
new ProcessFive()
);
$output = $pipe->execute($input);
} catch (ExecutableException) {
//handle process exception
} catch (InvalidArgumentException) {
//handle pipe exception
}
API
API is available at bazzline.net.
History
-
upcomming
* @todo
* add support for lambdafunctions or move to __invoke() fully
* added example for tee)
* fixed invalid package names
-
1.1.1 - released at 29.07.2016
* fixed invalid example links
* removed local api
* updated dependency
-
1.1.0 - released at 06.03.2016
* added php 7.0 to travis ci
* fixed invalid version link
* moved to psr-4 autoloading
* updated dependency
-
1.0.5 - released at 11.12.2015
* updated dependency
-
1.0.4 - released at 18.11.2015
* updated dependency
-
1.0.3 - released at 28.08.2015
* updated dependency
-
1.0.2 - released at 04.07.2015
* removed depenendy to phpmd
* updated dependency
-
1.0.1 - released at 08.02.2015
* add "StopExecutionException"
* removed dependency to apigen
-
1.0.0 - released at 12.11.2014
* initial release
Links
thanks to
other pipe implementations
Final Words
Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if you use it. Donate something if you love it :-].