azjezz/psl
PSL is a modern PHP standard library (PHP 8.4+) inspired by HHVM/HSL. It provides consistent, well-typed APIs for async, collections, networking, I/O, crypto, terminal UI, and data validation—safer, predictable alternatives to PHP’s built-ins.
Vec, Dict, Str, and Async components directly address Laravel’s reliance on raw arrays, str_* functions, and callback-based async patterns (e.g., queues, jobs). This reduces boilerplate and improves maintainability.Async/Fiber integration could replace Laravel’s Illuminate\Bus or Laravel\Horizon for lightweight, structured concurrency (e.g., batch processing, real-time APIs).Vector/Map/Set could augment or replace Laravel Collections (Illuminate\Support\Collection) for stricter typing and functional operations.TCP/TLS/HTTP components could underpin Laravel’s HTTP client (Guzzle) or replace Symfony\Component\HttpClient for low-level control.Async or Type validation).Async\run) would require careful sequencing.Psalm/PHPStan plugins enable gradual adoption by surfacing type errors early, but Laravel’s built-in tools (e.g., php artisan make:model) may need updates.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Breaking changes | High | Start with non-critical paths (e.g., DTO validation). |
| Async complexity | High | Isolate PSL Async to specific services (e.g., workers). |
| Type system friction | Medium | Use PSL’s Type for input validation only. |
| Performance overhead | Low | Benchmark PSL vs. native PHP (e.g., Vec vs. array_map). |
| Vendor lock-in | Low | PSL’s MIT license and modularity reduce risk. |
Async, Type, Vec) offer the highest ROI?Async\run wrapping job execution)?Illuminate\Bus or coexist?non_empty_string vs. string)?TCP/HTTP components outperform Guzzle/Symfony HTTP clients?Psalm/PHPStan plugins with Laravel’s built-in tools?mago or phpstan-extension replace Laravel’s IDE helpers?Async/HTTP/Type for request validation and concurrent processing.Type for input validation (e.g., API payloads, form data).Vec/Dict for functional transformations (e.g., ETL, reporting).Closure-based Laravel events.Phase 1: Validation and DTOs (Low Risk)
Type (e.g., API request DTOs).use Psl\Type;
$userType = Type\shape([
'name' => Type\non_empty_string(),
'email' => Type\email_address(),
]);
$validated = $userType->coerce(request()->all());
Psalm plugin to catch type errors early.Phase 2: Collections (Medium Risk)
Illuminate\Support\Collection with PSL’s Vec/Dict for functional operations.use Psl\Vec;
$users = Vec\map($users, fn($user) => $user->name);
Collection macros may need PSL equivalents.Phase 3: Async/Concurrency (High Risk)
use Psl\Async;
Async\main(static function() {
$result = Async\concurrently([
fn() => processOrder(1),
fn() => sendNotification(2),
]);
});
Illuminate\Bus or Laravel\Horizon.Phase 4: Networking (High Risk)
HTTP/TCP for custom protocols.use Psl\HTTP;
$response = HTTP\request('GET', 'https://api.example.com');
| Laravel Component | PSL Equivalent | Compatibility Notes |
|---|---|---|
Illuminate\Support\Collection |
Psl\Vec, Psl\Dict |
Functional APIs overlap; macros may need migration. |
Illuminate\Bus |
Psl\Async |
Fibers vs. queues; may need adapter layer. |
Guzzle/Symfony HTTP |
Psl\HTTP |
PSL is lower-level; middleware support needed. |
| Eloquent Models | PSL Type (DTOs) |
Immutability conflicts; use PSL for validation only. |
| Blade Templates | PSL Str |
Limited impact; use for string manipulation. |
Type).Vec/Dict).Psalm/PHPStan plugins early to catch issues.mago for enhanced type inference during migration.Vec/Dict) eliminate manual array operations.Psalm/PHPStan for full benefits; may slow down CI.How can I help you explore Laravel packages today?