nebalus / sanitizr
Installs: 258
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 0
Forks: 0
Open Issues: 0
Type:libary
pkg:composer/nebalus/sanitizr
Requires
- php: >=8.3
Requires (Dev)
- phpmd/phpmd: ^2.15
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.9
This package is not auto-updated.
Last update: 2026-01-12 02:02:09 UTC
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.
