- What is spatie/piper and what does it actually do?
- spatie/piper is a standalone PHP utility library that ports Laravel's collection and string helper methods into plain functions you can chain with the |> pipe operator. Each function takes a primitive (an array or a string) and returns a closure tuned for piping, so you can build multi-step transformations without wrapping values in Collection or Stringable objects. It ships two namespaces, Spatie\Piper\Arr and Spatie\Piper\Str, plus a small number of primitives such as join, values, prefix, and suffix. It adds no new capability beyond collect() and Str::, only a different, pipe-oriented syntax.
- What PHP version does spatie/piper require?
- spatie/piper requires PHP 8.5, because the |> pipe operator it is built around only exists from that version onward. Below PHP 8.5 the package is not merely risky, it is unusable, so adoption is really a downstream consequence of your PHP 8.5 migration. If that upgrade is not funded and scheduled, treat this package as deferred rather than evaluated. Check the composer.json constraint before planning any pilot.
- How do I install spatie/piper?
- Install it with composer require spatie/piper. There is no service provider, config file, publish step, migration, or middleware, so nothing else is required after Composer resolves the package. That zero-setup footprint also means uninstalling is a single composer remove command with no leftover registration to clean up.
- Does spatie/piper work outside of Laravel?
- Yes, and that is arguably its strongest use case. The package is framework-agnostic and depends only on PHP 8.5, so it fits shared internal packages, standalone queue workers, CLI tooling, and libraries consumed by both Laravel and non-Laravel services. Inside a typical Laravel application you already have collect() and Str::of(), so the value proposition there is mostly stylistic consistency rather than new functionality.
- How do I import the Arr and Str pipe functions in PHP?
- Import functions individually or grouped, for example use function Spatie\Piper\Arr\{filter, map, values}; and use function Spatie\Piper\Str\{lower, replace};. Grouped function imports keep the top of the file readable when a pipeline uses several helpers. Because these are namespaced functions rather than static methods, verify that your code style fixer orders and groups them the way your team expects.
- Can I mix array and string helpers in the same pipeline?
- Yes, that is an explicit design goal. Because every function takes and returns primitives, you can filter and map an array, collapse it to a string with join, then continue with Str helpers such as prefix and replace. This interleaving is where pipes read best, since Laravel's fluent APIs keep arrays and strings in separate object worlds. Just make sure each stage's type is obvious to the next reader.
- Does spatie/piper work with PHPStan, Psalm, and IDE autocompletion?
- Namespaced function imports can interact awkwardly with static analysis rules, IDE resolution, and style fixers, so this is the real integration work rather than the Composer install. Run a short spike against your existing PHPStan or Psalm baseline and check whether the imports resolve without suppression annotations. If you need baseline entries or ignore comments to make it pass, that is a signal to revisit the decision before adoption spreads.
- Is spatie/piper stable enough for production use?
- Treat it as a young 1.x package: it has modest adoption, a small dependent count, and only a couple of minor releases so far. Version 1.1.0 already changed sortByMany semantics by adding callable support, so pre-2.0 API churn is a realistic concern. Pin the version, pilot in a non-critical area, and read changelogs before upgrades. The MIT license and test suite derived from Laravel source mean a fork or selective inline of the functions is cheap if the package stalls.
- How does spatie/piper perform compared to Laravel collections?
- Pipelines are eager and run one closure call per element per stage, much like chained collection methods, so expect similar overhead rather than a speedup. There are no lazy variants, so every stage allocates a new array or string before the next one runs. Benchmark against your real data sizes before using pipes in high-throughput paths, and avoid them in critical-path domain logic where allocation churn matters. For typical request-level transformations the difference is negligible.
- Should I use spatie/piper instead of collect() and Str::of()?
- Decide on house style first, because running three idioms in one codebase is a net readability loss. A common rule is pipes for three-or-more-step primitive chains, loops for hot paths, and existing fluent chains left untouched in code you are not otherwise editing. If you only intend to permit pipes rather than standardize on them, that is usually the worst outcome. Alternatives include plain collect() and Str::of() inside Laravel, or small local helper functions if you only need a couple of the primitives.