entrepeneur4lyf/laravel-psl
Composer 安装命令:
composer require entrepeneur4lyf/laravel-psl
包简介
Laravel-first package that makes the PHP Standard Library feel natural inside Laravel applications.
README 文档
README
Laravel-first package that makes the PHP Standard Library (PSL) feel natural inside Laravel applications.
Status
Current v1 implementation includes:
- explicit bridge utilities for vec, dict, and Collection conversion
- opt-in list-safe Collection macros
- helper-driven typed coercion built on
Psl\Type - Laravel-friendly coercion exception wrapping
- PHPUnit and Testbench coverage
Requirements
- PHP 8.4+
- Laravel 13.x
- PSL 6.x
Installation
composer require entrepeneur4lyf/laravel-psl
Laravel package discovery registers the service provider automatically.
Configuration
Publish the config if you want to change runtime behavior:
php artisan vendor:publish --tag=laravel-psl-config
Current config:
return [ 'features' => [ 'collection_macros' => true, ], ];
Bridge Utilities
Use LaravelPsl\Support\PslBridge when you want explicit conversions between Laravel Collections and PSL-style array semantics.
use LaravelPsl\Support\PslBridge; $collection = collect([ 'name' => 'Taylor', 2 => 'Laravel', ]); $vec = PslBridge::toVec($collection); // ['Taylor', 'Laravel'] $dict = PslBridge::toDict($collection); // ['name' => 'Taylor', 2 => 'Laravel'] $backToCollection = PslBridge::toCollection($dict); // Collection(['name' => 'Taylor', 2 => 'Laravel'])
Bridge semantics:
toVec()intentionally reindexes values.toDict()intentionally preserves runtime keys.- Mixed
array-keydictionaries are supported as PHP represents them at runtime.
Collection Macros
When features.collection_macros is enabled, these macros are registered on Illuminate\Support\Collection:
pmappfilterpreducepchunkpsortptoVecptoDict
Example:
$users = collect($payload['users']) ->pfilter(fn (array $user): bool => $user['active'] ?? false) ->pmap(fn (array $user): array => [ 'email' => strtolower($user['email']), 'name' => trim($user['name']), ]);
Macro semantics:
pmap,pfilter,pchunk, andpsortare list-safe operations.- List-safe operations reindex values by design.
preduceis terminal and returns the final accumulator.preducealways requires an explicit initial value.psortreturns a reindexed Collection sorted by values.ptoVec()returns a plain list.ptoDict()returns a plain key-preserving array.
Examples:
$sum = collect(['a' => 1, 'b' => 2, 'c' => 3]) ->preduce(fn (int $carry, int $value): int => $carry + $value, 0); // 6 $sorted = collect(['c' => 3, 'a' => 1, 'b' => 2])->psort(); // Collection([1, 2, 3]) $vec = collect(['name' => 'Taylor', 2 => 'Laravel'])->ptoVec(); // ['Taylor', 'Laravel'] $dict = collect(['name' => 'Taylor', 2 => 'Laravel'])->ptoDict(); // ['name' => 'Taylor', 2 => 'Laravel']
Typed Coercion
Use LaravelPsl\Type\Coerce as a thin wrapper around Psl\Type.
use LaravelPsl\Type\Coerce; use Psl\Type; $user = Coerce::value( Type\shape([ 'name' => Type\non_empty_string(), 'roles' => Type\vec(Type\string()), ]), $payload, );
On failure, the package throws LaravelPsl\Exceptions\CoercionException and preserves the original Psl\Type\Exception\CoercionException as previous.
Usage Examples
Controller
use LaravelPsl\Type\Coerce; use Psl\Type; $input = Coerce::value( Type\shape([ 'email' => Type\non_empty_string(), 'roles' => Type\vec(Type\string()), ]), $request->all(), ['source' => 'request', 'field' => 'user'], );
Service
use LaravelPsl\Support\PslBridge; $emails = PslBridge::toVec($users->pluck('email'));
Job
use LaravelPsl\Type\Coerce; use Psl\Type; $payload = Coerce::value( Type\shape([ 'user_id' => Type\positive_int(), 'tags' => Type\vec(Type\string()), ]), $this->payload, ['source' => 'job', 'job' => static::class], );
Command
$names = collect($this->argument('names')) ->pfilter() ->psort() ->ptoVec();
Disabled-Feature Behavior
If features.collection_macros is false:
- Collection macros are not registered.
PslBridgeremains available.Coerceremains available.
Out of Scope for V1
- dict-aware transform macros
- Form Request integration for coercion
- string adapters
- runtime-aware concurrency integration
Development
composer install vendor/bin/phpunit
Auto-discovery smoke test:
composer test:discovery:install composer test:discovery
See prd.md for the product definition and implementation-plan.md for the execution checklist.
entrepeneur4lyf/laravel-psl 适用场景与选型建议
entrepeneur4lyf/laravel-psl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「PSL」 「php-standard-library」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 entrepeneur4lyf/laravel-psl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 entrepeneur4lyf/laravel-psl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 entrepeneur4lyf/laravel-psl 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Public Suffix List and IANA Root Zone Database based Domain parsing implemented in PHP.
Database abstraction for Public Suffix List
A robust domain parser for PHP, using the Mozilla Public Suffix List to determine the registrable domain and validate cookie domains per RFC 6265.
A fast & memory-efficient interface to the Mozilla Public Suffix List.
A high-performance PHP library for validating and parsing domain names using the Public Suffix List.
Alfabank REST API integration
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-19