emeraldinspirations / lib-helper-pipe
A PHP implementation of the Shell Pipe (|) concept
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/emeraldinspirations/lib-helper-pipe
This package is not auto-updated.
Last update: 2025-10-23 13:48:04 UTC
README
lib-helper-pipe
A helper in emeraldinspiration's library.
A PHP implementation of the Shell Pipe | concept
Inspired by:
- PHP RFC: Pipe Operator
- Shell's Pipe
|Operator - Javascript's
Promise API
PHP does not yet have a syntax for piping the output of one function into the input of another function without nesting the call:
<?php
return new \ArrayObject(
[
implode(
'',
array_reverse(
str_split(
strtoupper(
'test string'
)
)
)
)
]
);
This is messy, and hard to read. Plus it puts the functions in reverse order.
This class provides an alternate option. It allows using the this function to crate a cleaner looking pipe from one function to another:
<?php
use emeraldinspirations\library\helper\pipe\Pipe;
return (new Pipe('test string'))
->to('strtoupper')
->thenTo('str_split')
->thenTo('array_reverse')
->thenTo(
Pipe::delegateWithParamMask('implode', ['', Pipe::here()])
)
->thenTo(
function ($Param) {
return [$Param];
}
)
->thenTo(
Pipe::delegateConstructor(\ArrayObject::class)
)
->return();
Installing / Getting started
This project has no dependencies, so can simply be required with composer
composer require emeraldinspirations/lib-helper-pipe
Future Features
In the example above there is the need to prepend a parameter to the implode
function. A future feature may include some way to add additional parameters
to thenTo calls.
<?php
// Example with (callable $Function, array $Prepend = [], array $Append = [])
// ...
->thenTo('implode', [''], [])
// ...
// Example with (callable $Function, array $ParameterMask = [self::Here])
// ...
->thenTo('implode', ['', Pipe::Here])
// ...
Licensing
The code in this project is licensed under MIT license.