PHP code example of transprime-research / piper

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

    

transprime-research / piper example snippets


piper(['name' => 'ade', 'hobby' => 'coding'])
    ->to('array_flip')
    ->to('array_keys')
    ->to('array_map', fn($val) => strtoupper($val))
    ->to('array_intersect', [0 => 'ADE'])(); //returns ['ADE']

piper("Hello World")
    ->ln(
        htmlentities(...),
        str_split(...),
        [array_map(...), fn(string $part) => strtoupper($part)],
    );

ducter(
    "Hello World",
    htmlentities(...),
    str_split(...),
    [array_map(...), fn(string $part) => strtoupper($part)],
)

_p("Hello World")
    [htmlentities(...)]
    [str_split(...)]
    [[array_map(...), strtoupper(...)]]()

_p("Hello World")
    (htmlentities(...))
    (strtoupper(...))
    (str_split(...))
    (array_map(...), strtoupper(...))()

_p("Hello World")
    ->_(htmlentities(...))
    ->_(str_split(...))
    ->_(array_map(...), strtoupper(...)));

_p("Hello World")
    ->p(htmlentities(...))
    ->p(str_split(...))
    ->p(array_map(...), strtoupper(...))()

_p("Hello World")
    ->fn(htmlentities(...))
    ->fn(str_split(...))
    ->fn(array_map(...), strtoupper())
    ->fn()

_p("Hello World")
    ->htmlentities()
    ->str_split()
    ->array_map(strtoupper(...))()

array_intersect(
    array_map(
        fn($val) => strtoupper($val),
        array_keys(
            array_flip(['name' => 'ade', 'hobby' => 'coding'])
        )
    ),
    [0 => 'ADE']
); //returns ['ADE']

$arr = array_flip(['name' => 'ade', 'hobby' => 'coding']); // or array_values
$arr = array_keys($arr);
$arr = array_map(fn($val) => strtoupper($val), $arr);
$arr = array_intersect($arr, [0 => 'ADE']);

//$arr is ['ADE']

use Transprime\Piper\Piper;

// Normal
$piper = new Piper();
$piper->pipe(['AA'])->to('implode')->up();

// Better
$piper->on(['AA'])->to('implode')();


// Nifty
piper('AA')->to('strtolower')();

// Good
Piper::on('AA')->to('strtolower')->up();

//Better
Piper::on('AA')->to('strtolower')();

// test global method
piper('NAME', 'strtolower') // NAME becomes name
    ->to(fn($name) => ucfirst($name))
    ->up();

class StrManipulator
{
    public function __invoke(string $value)
    {
        return $this->strToLower($value);
    }

    public static function strToLower(string $value)
    {
        return strtolower($value);
    }
}

// test class method
piper('NAME', StrManipulator::class . '::strToLower')
    ->to(fn($name) => ucfirst($name))
    ->up();

// test array class and method
piper('NAME', [StrManipulator::class, 'strToLower'])
    ->to(fn($name) => ucfirst($name))
    ->up();

// test class object
piper('NAME', new StrManipulator()) // A class that implements __invoke
    ->to(fn($name) => ucfirst($name))
    ->up();

piper('array_intersect', [0 => 'ADE'])
    ->fro('array_map', fn($val) => strtoupper($val))
    ->fro('array_keys')
    ->fro('array_flip')
    ->fro(['name' => 'ade', 'age' => 5])();