1. Go to this page and download the library: Download nhlm/pipechain library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nhlm / pipechain example snippets
declare(strict_types=1);
use PipeChain\{
PipeChain
};
$pipeline = new PipeChain();
$pipeline->pipe(
# the stage callback
function(string $inbound) {
return 'something';
},
# the fallback callback
function(int $inbound) {
return ++$inbound;
}
);
var_dump(
$pipeline->process(100) // int(3) => 101
);
declare(strict_types=1);
namespace Somewhat;
use PipeChain\{
PipeChain,
InvokerProcessorInterface as Processor,
PipeChainCollectionInterface as Container
};
class MyFirstPipeline extends PipeChain {
protected function boot(Container $container, Processor $processor = null): Processor
{
# pipe something. The signature of PipeChainCollectionInterface::attach() is equal
# to PipeChain::pipe(..).
$container->attach(
# stage callable
function() {
},
# fallback callable (optional)
function() {
}
);
# ...
# Don't forget to call the parent, the parent method ensures
# that a processor will be created when $processor is null.
return parent::boot($container, $processor);
}
}
# later ...
echo MyFirstPipeline::create()->process('I can get no satisfaction!');