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

Psl Laravel Package

azjezz/psl

PSL is a modern, well-typed standard library for PHP 8.4+, inspired by HHVM’s HSL. It offers safer, predictable APIs for async, collections, networking, I/O, crypto, terminal UI, and robust data validation—replacing brittle built-ins with consistent alternatives.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

PSL (PHP Standard Library) introduces a modern, composable, and type-safe alternative to PHP's native primitives, aligning well with Laravel's evolving architecture. Key fits:

  • Async-first design: Leverages fibers (PHP 8.4+) for structured concurrency, complementing Laravel's growing async support (e.g., Swoole, ReactPHP).
  • Immutable data structures: Reduces side effects in Laravel's service layer, improving testability and predictability.
  • Type safety: Integrates with Laravel's PHP 8.1+ typing, enabling stricter validation (e.g., Type\shape() for request DTOs).
  • Functional collections: Replaces ad-hoc array operations with composable methods (e.g., Vec\map() for Eloquent collections).

Misalignment:

  • Laravel’s event-driven and queue-based systems (e.g., Illuminate\Queue) may conflict with PSL’s structured concurrency model (e.g., Async\main). Requires careful abstraction.
  • Legacy PHP extensions (e.g., PDO, cURL) lack PSL wrappers, necessitating hybrid code paths.

Integration Feasibility

Component Feasibility Notes
Type Validation High Replace Request::validate() with Type\shape() for DTOs.
Collections High Replace Collection facade with Vec, Dict, or Map for purity.
Async Medium Requires fiber-compatible Laravel extensions (e.g., laravel-fiber).
Networking Low PSL’s TCP, HTTP are low-level; prefer Laravel’s HttpClient.
Graph/Tree Low Niche use cases (e.g., dependency resolution); not core Laravel needs.

Critical Path:

  1. Adopt incrementally: Start with Type and Vec in domain layers.
  2. Async migration: Wrap PSL async in Laravel’s Bus or Jobs for compatibility.
  3. Hybrid patterns: Use PSL for new features; coexist with legacy code.

Technical Risk

Risk Impact Mitigation
Fiber compatibility High Test with laravel-fiber; avoid mixing fibers with Laravel’s event loop.
Performance overhead Medium Benchmark Vec vs. native arrays; PSL’s immutability may add memory usage.
Learning curve Medium Requires training on functional patterns (e.g., map, filter).
Dependency bloat Low PSL is ~10MB; minimal compared to Laravel’s ecosystem.
Tooling gaps Low Missing Laravel-specific IDE support (e.g., psalm-plugin needs configuration).

Blockers:

  • No Laravel plugins: PSL lacks official integrations (e.g., psl-eloquent).
  • Async ecosystem lock-in: PSL’s fibers may conflict with Swoole/ReactPHP in Laravel.

Key Questions

  1. Async Strategy:

    • Will we use PSL’s Async or Laravel’s Bus/Jobs for async workflows?
    • How will fibers interact with Laravel’s event loop (e.g., Illuminate\Events)?
  2. Type Safety Trade-offs:

    • Should we enforce PSL’s Type system globally, or use it only for DTOs?
    • How will we handle legacy codebases with weak typing?
  3. Performance:

    • Are PSL’s immutable collections acceptable for high-throughput APIs?
    • What’s the cost of Vec vs. native arrays in bulk operations?
  4. Tooling:

    • Can we configure Psalm/PHPStan to treat PSL types as first-class citizens?
    • Are there plans for Laravel-specific PSL extensions (e.g., psl-eloquent)?
  5. Migration Path:

    • Should we rewrite core services (e.g., ServiceProvider) to use PSL, or adopt gradually?
    • How will we handle PSL’s lack of support for Laravel’s Cache, Filesystem, etc.?

Integration Approach

Stack Fit

PSL aligns with Laravel’s modern PHP stack but requires selective adoption:

  • Core Fit:
    • Type System: Replace Request validation, FormRequest, and DTOs with Type\shape().
    • Collections: Use Vec/Dict in domain layers (e.g., repository patterns).
    • Async: Pilot in background jobs (e.g., Async\concurrently for batch processing).
  • Peripheral Fit:
    • Networking: Avoid PSL’s TCP/HTTP; use Laravel’s HttpClient/Queue.
    • Graph/Tree: Use for niche cases (e.g., ACLs, dependency graphs).

Stack Conflicts:

  • Event Loop: PSL’s fibers may clash with Laravel’s Swoole/ReactPHP integrations.
  • Legacy Extensions: PSL lacks wrappers for PDO, Redis, etc.; require adapters.

Migration Path

Phase Components Effort Risks
Pilot Type + Vec in DTOs Low Minimal; isolated to new features.
Domain Layer Replace Collection facade Medium Breaking changes to service logic.
Async Wrap Async in Job classes High Fiber compatibility issues.
Core Rewrite ServiceProvider High Risk of regressions; requires testing.

Recommended Order:

  1. Type Safety: Replace Request validation with Type\shape().
  2. Collections: Adopt Vec/Dict in repositories and services.
  3. Async: Pilot in background jobs; avoid mixing with event loop.
  4. Tooling: Configure Psalm/PHPStan for PSL types.

Compatibility

Laravel Component PSL Compatibility Workaround
Illuminate\Support\Collection Medium (functional overlap) Use Vec::fromArray() for conversion.
Illuminate\Http\Request High (type validation) Replace validate() with Type\shape()->coerce().
Illuminate\Queue Low (async model conflict) Wrap PSL async in Job classes.
Illuminate\Database\Eloquent Low (no ORM integration) Use PSL for query results (e.g., Vec from get()).
Illuminate/Events Low (fiber vs. event loop) Avoid mixing; use PSL async only in jobs.

Sequencing

  1. Isolate PSL Usage:
    • Start in new features or greenfield modules.
    • Avoid mixing PSL and native PHP in the same class.
  2. Hybrid Adapters:
    • Create facades to bridge PSL and Laravel (e.g., PslCollection::fromLaravel()).
  3. Async Boundaries:
    • Use PSL async only in background jobs, not in HTTP requests.
  4. Gradual Replacement:
    • Replace Collection facade with Vec in repositories.
    • Replace Request validation with Type in controllers.

Operational Impact

Maintenance

Aspect Impact Notes
Codebase Complexity Increased Functional patterns (e.g., map, filter) require discipline.
Debugging Medium Immutable data structures reduce side effects but may complicate state tracking.
Testing Improved Pure functions and immutability simplify unit tests.
Dependency Updates Low PSL is actively maintained; Laravel compatibility is a concern.

Key Tasks:

  • Document hybrid patterns: Clearly mark where PSL and native PHP coexist.
  • Standardize type usage: Enforce Type\shape() for all DTOs.
  • Monitor fiber leaks: Ensure async code doesn’t block Laravel’s event loop.

Support

Area Impact Mitigation
Developer Onboarding High Requires training on functional programming and fibers.
Legacy Code Medium Hybrid adapters (e.g., PslCollection) ease transition
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
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
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