Key Features • How To Use • Credits • Related • License
composer require nebalus/sanitizr
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
}
See the examples directory and API Reference for more details.
This project is licensed under the MIT License. See the LICENSE file for details.