jddf/jddf
Composer 安装命令:
composer require jddf/jddf
包简介
JSON Data Definition Format validation for PHP
README 文档
README
This package is a PHP implementation of JSON Data Definition Format. You can use this package to:
- Validate input data against a schema,
- Get a list of validation errors from that input data, or
- Build your own tooling on top of JSON Data Definition Format
Installation
You can add this package as a dependency using Composer:
composer require jddf/jddf
Usage
Here's how you parse a schema, validate data against that schema, and see what validation errors came back:
<?php // For the purposes of demonstration, we're going to parse a schema from JSON. // You can also construct instances of Jddf\Schema yourself directly. $schemaJson = <<<'JSON' { "properties": { "name": { "type": "string" }, "age": { "type": "uint32" }, "phones": { "elements": { "type": "string" } } } } JSON; // Parse a schema from JSON using json_decode and Schema::fromJson. $schema = Jddf\Schema::fromJson(json_decode($schema)); // This input data is perfect. It satisfies all the schema requirements. $inputOk = json_decode(<<<'JSON' { "name": "John Doe", "age": 43, "phones": [ "+44 1234567", "+44 2345678", ], } JSON); // This input data has problems. "name" is missing, "age" has the wrong type, // and "phones[1]" has the wrong type. $inputBad = json_decode(<<<'JSON' { "age": "43", "phones": [ "+44 1234567", 442345678, ], } JSON); // To keep things simple, we'll ignore errors here. In this example, errors // are impossible. The docs explain in detail why an error might arise from // validation. $validator = new Jddf\Validator(); $resultOk = $validator->validate($schema, $inputOk); $resultBad = $validator->validate($schema, $inputBad); // Outputs an empty array. var_dump($resultOk); // [] ["properties", "name"] -- indicates that the root is missing "name" var_dump($resultBad[0]->instancePath, $resultBad[0]->schemaPath); // ["age"] ["properties", "age", "type"] -- indicates that "age" has the wrong // type var_dump($resultBad[1]->instancePath, $resultBad[1]->schemaPath); // ["phones", "1"] ["properties", "phones", "elements", "type"] -- indicates // that "phones[1]" has the wrong type var_dump($resultBad[2]->instancePath, $resultBad[2]->schemaPath);
jddf/jddf 适用场景与选型建议
jddf/jddf 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 12 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jddf/jddf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jddf/jddf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-28