nebalus/sanitizr
最新稳定版本:v1.0.2
Composer 安装命令:
composer require nebalus/sanitizr
包简介
README 文档
README
A Zod inspired Validation and Filter Framework written in PHP.
Key Features • How To Use • Credits • Related • License
Key Features
- Zod-inspired API: Familiar, fluent interface for schema definitions, validation, and filtering.
- Composable schemas: Build complex validators from primitives and custom rules.
- Extensible: Easily extend with your own filters and validation logic.
- Zero dependencies: Lightweight and easy to integrate.
How To Use
Installation
composer require nebalus/sanitizr
Basic Example
use Nebalus\Sanitizr\SanitizrStatic as S; // Define a schema $userSchema = S::object([ 'name' => S::string()->min(1), 'email' => S::string()->email(), 'age' => S::int()->min(0)->optional(), ]); // Define input $input = [ 'name' => 'Alex', 'email' => 'alex@example.com', ]; $result = $userSchema->safeParse($input); if ($result->isValid()) { $user = $result->getValue(); // Use sanitized data echo $user["name"]; // Outputs: Alex echo $user["email"]; // Outputs: alex@example.com } else { $errorMessage = $result->getErrorMessage(); // Handle validation errors }
Advanced Usage
- Custom filters:
Create your own filters and add them to schemas. - Nested objects & arrays:
Compose validators for deeply nested data.
See the examples directory and API Reference for more details.
Credits
- Inspired by Zod (TypeScript) and the wider PHP validation ecosystem.
- Created and maintained by Nebalus.
Related
License
This project is licensed under the MIT License. See the LICENSE file for details.
统计信息
- 总下载量: 258
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-15
