Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lang Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Functional Composition: Chain operations in a declarative style. Use 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"
    
  • Partial Application: Avoid repeating arguments in repeated calls. Ideal for config-driven transformations or factory patterns:
    $formatDate = Fn::partial('date_format', 'Y-m-d');
    echo $formatDate($someDateTime);
    
  • Array & Collection Utilities: Use ArrayUtils::map(), filter(), reduce() for pure transformation pipelines—especially where array_map would obscure intent.
  • String Helpers: The Str class offers Str::of() (fluent string wrapper) with chainable methods like capitalize(), snakeCase(), between().
  • Library Integration: Because it’s dependency-free, drop Fn::pipe() or ArrayUtils::pluck() into service classes, Laravel Jobs, or custom helpers in app/helpers.php to reduce repetition.

Gotchas and Tips

  • No 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.
  • Strict type expectations: Many internal utilities use type hints—mixing scalar types (e.g., passing an object to Fn::apply()) will fail. Prefer Fn::call() for dynamic dispatch.
  • No polyfills: Unlike Symfony’s Polyfill, this library doesn’t backfill functions—it assumes PHP ≥8.1. Don’t expect it to help on legacy projects.
  • Naming conflicts: Avoid importing Fn as a class name in your app—use namespace aliases if necessary:
    use phootwork\lang\Fn as LangFn;
    
  • Test-first usage: Since helpers are often used in “silent” pipelines, write unit tests around critical compositions (e.g., a data transformation pipeline) to catch subtle edge-case failures.
  • Performance note: While lightweight, deeply nested Fn::compose() chains on large datasets may lag behind native loops—profile before optimizing.
  • Extensibility: The package encourages extending via traits or standalone helpers. For Laravel apps, wrap its utilities in custom macroable classes (e.g., MacroableStr) to avoid modifying vendor code.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests