a9korn/formio-validator
最新稳定版本:v1.0.3
Composer 安装命令:
composer require a9korn/formio-validator
包简介
Formio JSON schema validator for PHP
README 文档
README
⚡ Quick setup
Install library
composer require a9korn/formio-validator
Script for test:
- copy data-example/schema.json - to your-project directory
- create file [script_name].php
<?php
use A9korn\FormioValidator\FormioBuilderValidator;
require __DIR__ . '/vendor/autoload.php';
$schema = file_get_contents(__DIR__ . '/data-example/schema-test.json');
$schema_array = json_decode($schema, true);
try {
$validator = new FormioBuilderValidator($schema_array['components']);
$errors = $validator->validateSchema();
print_r($errors);
} catch (Exception $e) {
print_r($e);
}
How to Create Custom Validator
Create custom class implements IFormValidator
<?php namespace App; use A9korn\FormioValidator\BaseValidator; use A9korn\FormioValidator\IFormValidator; class ButtonValidator extends BaseValidator implements IFormValidator { protected array $requiredFields = ['key', 'type', 'input']; public function validate(array $component): array { $errors = parent::validate($component); return array_merge( $errors, $this->myValidator($component) ); } public function myValidator(array $component): array { $errors = []; // TODO - validation logic return $errors; } }
add custom validators array as argument
$myValidators = [ 'button' => \App\ButtonValidator::class ]; $validator = new FormioBuilderValidator($schema_array['components'], $myValidators); $errors = $validator->validateSchema();
or register custom validator
$validator = new FormioBuilderValidator($schema_array['components']); $validator->registerValidator('button',\App\ButtonValidator::class);
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-29