Skip to content
Attributes-PHPPublic

About

Type-hint validation library for PHP

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

97 Commits

Folders and files

Repository files navigation

Strictify

Latest Version Static Badge Software License


Strictify is a PHP library for validating data via type hints. Your model types are the schema: no configuration files, no YAML.

Prerequisites

  • PHP 8.2 or later

We aim to support versions that haven't reached their end-of-life.

How it works?

<?php

use function Attributes\Strictify\validate;
use Attributes\Strictify\BaseModel;

class User extends BaseModel
{
    public float|int $age;
    public ?DateTime $birthday;
}

$rawData = [
    'age' => 30,
    'birthday' => '1994-01-01T09:00:00+00:00',
];
$user = validate($rawData, new User());

var_dump($user->age);      // int(30)
var_dump($user->birthday); // object(DateTime) { ["date"] => string(26) "1994-01-01 09:00:00.000000", (...) }

Need to call a function?

<?php

use function Attributes\Strictify\call;

function myFunction(User $user) {
    var_dump($user->age);      // int(30)
    var_dump($user->birthday); // object(DateTime) { ["date"] => string(26) "1994-01-01 09:00:00.000000", (...) }
}

call("myFunction", $rawData);

Installation

composer require attributes-php/strictify

For maximum speed, install Strictify Extension instead — the native C extension flavor of the same library. It shares the same API, behavior and documentation, so no code changes are needed:

pie install attributes-php/strictify-ext

Documentation

Full documentation lives at strictify.attributes-php.com:

  • Quickstart — first model and first validation in under a minute
  • Guides — validating payloads, nested models, aliases, error messages, sensitive data, call(), toDict()
  • Reference — validate(), toDict(), call(), ModelConfigs, constraints, exceptions, API
  • FAQ and Changelog
  • For LLMs and agents: llms.txt indexes every page (each also served as Markdown), and llms-full.txt has the full docs in one file

Strictify Extension was created by André Gil and is open-sourced software licensed under the MIT license.

About

Type-hint validation library for PHP

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages