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 (PHP Standard Library) offers a consistent, well-typed set of safer, async-ready APIs to replace PHP primitives. Covers async, collections, networking, I/O, cryptography, terminal UI, and type-safe data validation with predictable errors.

View on GitHub
Deep Wiki
Context7

PHP Standard Library

Frequently asked questions about Psl
Can I use PSL’s collections (Vec, Dict) to replace Laravel’s Collection class?
Yes, but with caution. PSL’s collections are immutable and type-safe, offering stricter guarantees than Laravel’s mutable Collection. You’ll need to refactor existing methods like `push()` or alias them (e.g., `map` instead of `pluck`). Start with new services or DTOs to test compatibility before full migration.
Will PSL work with Laravel 10 (PHP 8.2) or older versions?
No, PSL requires PHP 8.4+. For Laravel 10 or older, consider a compatibility layer like `azjezz/psl-laravel` or focus on PSL’s async/networking components (e.g., HTTP clients) where it doesn’t depend on newer PHP features. Benchmark performance trade-offs carefully.
How does PSL’s async/Promise system integrate with Laravel’s queue jobs?
PSL’s Async and Promise APIs can wrap Laravel’s Bus/Jobs for I/O-bound tasks (e.g., API calls in background jobs). Use a custom dispatcher like `PslJobDispatcher` to bridge PSL’s fibers with Laravel’s queue system. Avoid mixing with existing Promise libraries (e.g., `spatie/promise`) to prevent conflicts.
Is PSL’s type validation better than Laravel’s Validator for runtime checks?
PSL’s Type system excels for strict, composable validation (e.g., shapes, unions) with zero reflection overhead, while Laravel’s Validator offers built-in rules (e.g., `email`, `date`). Use PSL for DTOs or API inputs where type safety is critical, and extend Laravel’s Validator with PSL rules for hybrid workflows.
What’s the performance impact of using PSL’s immutable collections vs. Laravel’s?
PSL’s immutability and type safety add runtime checks, which may slow bulk operations (e.g., `where()`, `pluck()`) compared to Laravel’s optimized Collections. Benchmark critical paths—PSL shines in correctness but trade-offs exist for high-throughput tasks. Consider hybrid usage for performance-sensitive code.
How do I migrate from Laravel’s Collection to PSL without breaking existing code?
Start incrementally: Replace `Collection` with PSL’s `Vec`/`Dict` in new classes, then alias methods (e.g., `pluck` → `map`) via a config file. Use a facade or trait to wrap PSL types for backward compatibility. Test thoroughly—immutability will catch bugs in mutable-dependent logic.
Does PSL support Laravel’s async middleware or event listeners?
PSL’s Async API works with Laravel’s async middleware (experimental in Laravel 11+) or event listeners via fibers. Wrap middleware logic in `Async un()` or use PSL’s `Promise` for async responses. Ensure your server (e.g., Swoole, RoadRunner) supports fibers for full concurrency.
Are there alternatives to PSL for type-safe collections in Laravel?
Yes: `spatie/array` for lightweight collections, `symfony/collection` for mutable alternatives, or `league/collection` for immutable patterns. PSL stands out for its async-first design and deep integration with PHP 8.4+ features (e.g., enums, attributes), but may overkill for simple use cases.
How does PSL handle mixed codebases with both Laravel and PSL types?
Use a phased migration: Isolate PSL types in new modules (e.g., DTOs, services) and gradually replace Laravel utilities. For shared code, create adapters (e.g., `LaravelCollection::toPslVec()`). PSL’s strict typing may require IDE plugins (e.g., PHPStorm) to avoid false positives in mixed contexts.
Can PSL’s networking tools (HTTP, TCP) replace Laravel’s HTTP client or Guzzle?
PSL’s `Http` and `Socket` APIs offer type-safe, async alternatives to Guzzle or Laravel’s HTTP client, ideal for high-concurrency scenarios (e.g., scraping, microservices). They lack Guzzle’s middleware ecosystem but integrate seamlessly with PSL’s Async. Test error handling—PSL throws exceptions predictably, unlike Guzzle’s callbacks.
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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope