schematicon / validator
Schemation 验证器是各种数据结构的强大验证器。
v1.2.0
2019-03-20 09:59 UTC
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-09-20 22:07:51 UTC
README
验证器 是 Schematicon Schema 验证器。Schematicon schema 是一种创新性的声明性语言,用于数据结构描述。它是编程语言无关的;这意味着您可以使用 NEON、YAML 或本地 PHP 数组来定义模式。
示例
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
以下输入可以与定义的方案进行验证
$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(); // []
安装
使用 composer
$ composer require schematicon/validator
许可证
MIT。查看完整的 许可证。
开发由 Sygic Travel 赞助。