PHP code example of aviator / pipe

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

    

aviator / pipe example snippets


$filter = function ($item) { return $item === 'SOME'; };

// Offputting one-liner
echo implode('.', array_filter(explode('-', strtoupper(trim('    some-value'))), $filter))

// Multiple assignments
$value = '    some-value';
$value = trim($value);
$value = strtoupper($value);
$value = explode('-', $value);
$value = array_filter($value, $filter);
echo implode('.', $value);

// Easy to read pipe
echo take('    some-value')
    ->trim()
    ->strtoupper()
    ->explode('-', '$$')
    ->array_filter($filter)
    ->implode('.', '$$')
    ->get();

// prints 'SOME'

$value = new Pipe('value');
$value = Pipe::take('value');
$value = take('value');

$value->pipe('strtoupper');

echo $value->get();

// prints 'VALUE'

echo Pipe::take('    value')
    ->pipe('trim')
    ->pipe('strtoupper')
    ->get();
    
// prints 'VALUE'

echo Pipe::take('    value')
    ->trim()
    ->strtoupper()
    ->get();
    
// prints 'VALUE'

echo Pipe::take('value')
    ->str_repeat(3)
    ->strtoupper()
    ->get();
    
// prints 'VALUEVALUEVALUE'

echo Pipe::take(['some', 'array'])
    ->implode('.', '$$')
    ->get();
    
// prints 'some.array'

$closure = function ($item) { return $item . '-postfixed'; };

echo Pipe::take('value')
    ->pipe($closure)
    ->get();

// prints 'value-postfixed'