PHP 标准库
# PSL - PHP 标准库 PHP 的一个标准库,灵感来自 [hhvm/hsl](https://github.com/hhvm/hsl)。PSL 提供了一组一致、集中、类型完善的 API,涵盖异步、集合、网络、I/O、加密、终端用户界面等内容,它用更安全、支持异步的替代方案来取代 PHP 的函数和原语,这些替代方案可以预测错误。 **[文档](https://php-standard-library.dev) · **[赞助商](https://github.com/sponsors/azjezz)** ## 安装 ```shell composer require php-standard-library/php-standard-library ``` 需要 PHP 8.4+。 ## 快速查看 ### 类型安全的数据验证 使用可组合的类型组合器 - 形状、联合、可选项 - 验证和强制不受信任的数据,且无反射开销。 ```php 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}
### 结构化并发暂无开放 Issues,或尚未同步最近议题。