PHP code example of simplemehanizm / pipeline
1. Go to this page and download the library: Download simplemehanizm/pipeline 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/ */
simplemehanizm / pipeline example snippets
use SimpleMehanizm\Pipeline;
class SetIDStage
{
public function handle(object $state): object
{
$state->id = 1; // change state, set the arbitrary ID value to 1
return $state;
}
}
class SetTitleStage
{
public function handle(object $state): object
{
$state->title = 'This is the title';
return $state;
}
}
$state = new class {
public function __construct(
public int $id = 0,
public string $title = ''
){}
}
$stages = [
SetIDStage::class,
SetTitleStage::class
];
$pipeline = new Pipeline();
$result = $pipeline->send($state)->through($stages)->then(function(object $state) {
return [
'id' => $stage->id,
'title' => $stage->title
]
});