A Zod inspired Validation and Filter Framework written in PHP.
Key Features • How To Use • Credits • Related • License
- 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.
composer require nebalus/sanitizruse 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
}- 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.
- Inspired by Zod (TypeScript) and the wider PHP validation ecosystem.
- Created and maintained by Nebalus.
This project is licensed under the MIT License. See the LICENSE file for details.
