spatie/piper
Pipe-operator-first PHP utility library for array and string manipulation. Piper ports many Laravel Collection and Str helpers to standalone functions that work with primitives, so you can compose readable pipelines for filtering, mapping, joining, and more.
|>) aligns with modern PHP’s functional programming trends (e.g., PHP 8.1+ named arguments, arrow functions) and Laravel’s fluent APIs. Reduces boilerplate for common operations like filtering, mapping, or string manipulation.collect()/Str::* is trivial. Example:
// Laravel
$result = Str::of($str)->upper()->replace(['foo' => 'bar']);
// Piper (equivalent)
$result = $str |> upper() |> replace(['foo' => 'bar']);
map accepts any callable, risking type errors). Mitigate with strict typing in calling code.|>) over method chaining (Str::of()->...)? If not, Piper may not justify the learning curve.microtime(true).null inputs, Unicode strings).functools.reduce, JavaScript’s Array.prototype.reduce).collect()->filter()->map() with $array |> filter() |> map().Str::of($str)->upper()->slug() with $str |> upper() |> slug().App\Pipes\*).Str/Arr facades.$result = $str
|> Str::of() // Laravel helper
|> lower() // Piper function
|> replace(['foo' => 'bar']);
Str::* chains with Piper’s string functions.collect()->* with Piper’s array functions.App\Pipes\Domain\formatUserData()).collect() with Piper").tap() (if added in future versions) or dd() for inspection:
$result = $data
|> filter(fn ($item) => $item['active'])
|> tap(fn ($filtered) => dd($filtered)) // Debug here
|> map(...);
array_chunk() before piping).parallel package).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Pipe Syntax Errors | Runtime errors if pipe order is wrong. | Use type hints and IDE autocomplete. |
| Invalid Inputs | Functions may return unexpected results (e.g., null handling |
How can I help you explore Laravel packages today?