Sanitizr


Sanitizr

A Zod inspired Validation and Filter Framework written in PHP.

Key FeaturesHow To UseCreditsRelatedLicense

Key Features

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

See the examples directory and API Reference for more details.

Credits

License

This project is licensed under the MIT License. See the LICENSE file for details.