azjezz/psl
Composer 安装命令:
composer require azjezz/psl
包简介
PHP Standard Library
README 文档
README
PSL - PHP Standard Library
A standard library for PHP, inspired by hhvm/hsl. PSL provides a consistent, centralized, well-typed set of APIs covering async, collections, networking, I/O, cryptography, terminal UI, and more - replacing PHP functions and primitives with safer, async-ready alternatives that error predictably.
Installation
composer require php-standard-library/php-standard-library
Requires PHP 8.4+.
Quick Look
Type-safe data validation
Validate and coerce untrusted data with composable type combinators - shapes, unions, optionals - all with zero reflection overhead.
use Psl\Type; $userType = Type\shape([ 'name' => Type\non_empty_string(), 'age' => Type\positive_int(), 'tags' => Type\vec(Type\string()), ]); $user = $userType->coerce($untrustedInput); // array{name: non-empty-string, age: positive-int, tags: list<string>}
Structured concurrency
Run concurrent operations with a single function call. Structured concurrency built on fibers - no promises, no callbacks.
use Psl\Async; use Psl\TCP; use Psl\IO; Async\main(static function(): int { [$a, $b] = Async\concurrently([ static fn() => TCP\connect('api.example.com', 443), static fn() => TCP\connect('db.example.com', 5432), ]); IO\write_error_line('Both connections ready'); return 0; });
Functional collections
Map, filter, sort, and reshape arrays with pure functions. Separate return types for lists and dicts - no more array key confusion.
use Psl\Vec; use Psl\Dict; use Psl\Str; $names = ['alice', 'bob', 'charlie']; Vec\map($names, Str\uppercase(...)); // ['ALICE', 'BOB', 'CHARLIE'] Vec\filter($names, fn($n) => Str\length($n) > 3); // ['alice', 'charlie'] Dict\pull($names, Str\uppercase(...), fn($n) => $n); // {alice: 'ALICE', bob: 'BOB', charlie: 'CHARLIE'}
TCP server in 10 lines
Production-ready networking primitives. TCP, TLS, UDP, Unix sockets - all async, all composable.
use Psl\Async; use Psl\TCP; use Psl\IO; Async\main(static function(): int { $server = TCP\listen('127.0.0.1', 8080); IO\write_error_line('Listening on :8080'); while (true) { $conn = $server->accept(); Async\run(static function() use ($conn) { $conn->writeAll("Hello!\n"); $conn->close(); })->ignore(); } });
Tooling
| Tool | Description |
|---|---|
| Mago | Enhanced type inference for Mago |
| Psalm Plugin | Enhanced type inference for Psalm |
| PHPStan Extension | Enhanced type inference for PHPStan |
Contributing
See CONTRIBUTING.md.
License
MIT - see LICENSE.
azjezz/psl 适用场景与选型建议
azjezz/psl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.34M 次下载、GitHub Stars 达 1.54k, 最近一次更新时间为 2019 年 12 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 azjezz/psl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 azjezz/psl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12.34M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1546
- 点击次数: 15
- 依赖项目数: 54
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-24
