PHP code example of philiprehberger / php-pipeline
1. Go to this page and download the library: Download philiprehberger/php-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/ */
use PhilipRehberger\Pipeline\Pipeline;
$result = Pipeline::send('hello')
->pipe(UpperCaseStage::class)
->pipe(AppendSuffixStage::class)
->processWithProfile();
$result->value(); // "HELLO_suffix"
$result->stages(); // [{name, duration_ms, memory_delta}, ...]
$result->totalDuration(); // Total ms across all stages
$result->slowestStage(); // Name of the slowest stage
use PhilipRehberger\Pipeline\Pipeline;
Pipeline::register('text-cleanup', function (PendingPipeline $p) {
$p->pipe(TrimStage::class)
->pipe(UpperCaseStage::class);
});
$result = Pipeline::fromTemplate('text-cleanup')
->send(' hello ')
->thenReturn();
// "HELLO"
$result = Pipeline::send($data)
->through([RiskyStage::class])
->catchException(ValidationException::class, function (\Throwable $e, mixed $passable) {
return $passable; // Recover from validation errors only
})
->thenReturn();
// Non-matching exceptions propagate normally
$result = Pipeline::send($data)
->through([RiskyStage::class])
->onFailure(function (\Throwable $e, mixed $passable) {
return $passable; // Return original data on failure
})
->process();
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.