phootwork/lang
phootwork/lang is a lightweight PHP library of language utilities and building blocks, offering common helpers and core abstractions to simplify everyday coding tasks. A small foundation package meant to complement your app or other phootwork components.
Start by requiring the package via Composer:
composer require phootwork/lang
No service provider or configuration is needed—it’s a pure PHP utility library with no framework dependencies. The entry point is typically the phootwork\lang namespace. A common first use is leveraging the Fn class for functional helpers like Fn::curry(), Fn::partial(), or Fn::compose() to reduce boilerplate in callbacks. For example:
use phootwork\lang\Fn;
$add = Fn::curry('plus', 2); // Curried addition
$add5 = $add(3); // Partially applied
echo $add5(2); // 7
Check the src/ folder structure for modules like lang/, functional/, collections/—but despite the modular design, most helpers are accessible through static methods on Fn, Str, or ArrayUtils.
Fn::compose() for right-to-left composition and Fn::pipe() for left-to-right (more intuitive for most):
$clean = Fn::pipe('trim', 'strtolower', 'strip_tags');
echo $clean(' <b>Hello</b> '); // "hello"
$formatDate = Fn::partial('date_format', 'Y-m-d');
echo $formatDate($someDateTime);
ArrayUtils::map(), filter(), reduce() for pure transformation pipelines—especially where array_map would obscure intent.Str class offers Str::of() (fluent string wrapper) with chainable methods like capitalize(), snakeCase(), between().Fn::pipe() or ArrayUtils::pluck() into service classes, Laravel Jobs, or custom helpers in app/helpers.php to reduce repetition.null safety by default: Helpers like Fn::pipe() will throw if a function returns null and the next callback expects a value (e.g., Fn::pipe('trim', 'substr', 0, 5) fails if trim() returns null). Use Fn::pipe(..., 'stringval') or guard with Fn::lift() for nullable inputs.Fn::apply()) will fail. Prefer Fn::call() for dynamic dispatch.Fn as a class name in your app—use namespace aliases if necessary:
use phootwork\lang\Fn as LangFn;
Fn::compose() chains on large datasets may lag behind native loops—profile before optimizing.MacroableStr) to avoid modifying vendor code.How can I help you explore Laravel packages today?