schematicon / validator
Schemation Validator is powerful validator of various data structures.
Installs: 57 408
Dependents: 2
Suggesters: 0
Security: 0
Stars: 20
Watchers: 5
Forks: 2
Open Issues: 5
Requires
- php: >=7.0
Requires (Dev)
- nette/neon: ~2.4
- nette/tester: ~1.7
- tracy/tracy: ~2.4
This package is auto-updated.
Last update: 2024-10-20 22:25:38 UTC
README
Validator is Schematicon Schema validator. Schemeaticon schema is innovative declarative language for data structure description. It is programming-language independent; that means you can define the schema using NEON, YAML or native PHP arrays.
Example
my_family.neon
:
type: map properties: name: string surname: string sex: enum: [male, female] age: int|null # property may be a null ?height: float # property may not exist at all; if exist, it has to be a float siblings: type: array item: type: string
The following inputs may be validated againts the defined schema:
$normalizer = new Schematicon\Validator\Normalizer(); $schema = Neon\Neon::decode(file_get_contents('./my_family.neon')); $schema = $normalizer->normalize($schema); $validator = new Schematicon\Validator\Validator($schema); $result = $validator->validate([ 'name' => 'jon', 'surname' => 'snow', 'sex' => 'male', 'age' => 18, 'height' => 180.00, 'siblings' => ['Arya'], ]); $result->isValid(); // true $result->getErrors(); // []
Installation
Use composer:
$ composer require schematicon/validator
License
MIT. See full license.
The development was sponsored by Sygic Travel.