sangroya/yii2-json-schema-validator

一个提供JSON Schema验证验证器类的Yii2扩展。

0.1 2021-04-09 07:56 UTC

This package is auto-updated.

Last update: 2024-09-14 13:08:14 UTC


README

一个提供封装JSON Schema for PHP验证类的Yii 2扩展。

安装

$ composer require sangroya/yii2-json-schema-validator

使用方法

模型类示例

<?php

namespace app\models;

use sangroya\jsonschema\JsonSchemaValidator;
use Yii;
use yii\base\Model;

class MyModel extends Model
{
    public $json;

    public function rules()
    {
        return [
            [
                'json',
                JsonSchemaValidator::className(),
                'schema' => 'file://' . Yii::getAlias('@app/path/to/schema.json'),
                /* or URL
                'schema' => 'https://test-example.com/path/to/schema.json',
                */
            ],
        ];
    }
}

有关如何描述JSON schema的详细信息,请参阅 json-schema