PHP code example of samueldavis / php-pipeline

1. Go to this page and download the library: Download samueldavis/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/ */

    

samueldavis / php-pipeline example snippets


class Remover
{
    public static function pop(array $arr = [])
    {
        return array_pop($arr);
    }
}

$stringHelper = new class
{
    public function concat(string $initial, string $addition): string
    {
        return $initial . $addition;
    }
};

$explodeCurry = function (string $string) {
    return explode(' ', $string);
};

$explodingPipeline = (new Pipe)
    ->into('strtoupper')
    ->into($explodeCurry);

$getResult = (new Pipe('foo bar'))
    ->into($explodingPipeline)
    ->into([Remover::class, 'pop'])
    ->into([$stringHelper, 'concat'], 'fiz');

var_dump($getResult());
echo "========\n" . json_encode($getResult, JSON_PRETTY_PRINT);

~/code/pipe/example.php:33:
string(6) "BARfiz"
========
{
    "0": "foo bar",
    "1": [
        {
            "0": null,
            "1": [
                "strtoupper"
            ],
            "2": [
                {}
            ]
        }
    ],
    "2": [
        [
            "Remover",
            "pop"
        ]
    ],
    "3": [
        [
            {},
            "concat"
        ],
        "fiz"
    ]
}