lfbn / json-resume-validator

验证您的 JSON 简历

0.0.5 2020-11-21 17:24 UTC

This package is not auto-updated.

Last update: 2024-09-22 10:55:42 UTC


README

这是一个验证简历是否为 JSON 简历格式的包。它还验证是否所有期望的属性都不为空。

它执行以下验证:

  • 符合 JSON 简历的 JSON Schema。
  • 填写了某些字段。这是可配置的。
  • 如果国家代码(basics.countryCode)处于 ISO-3166-1 ALPHA-2 格式。如果此字段为空,则不进行验证。

安装

composer require lfbn/json-resume-validator

使用方法

作为 CLI

只需克隆项目,然后运行。按照说明进行操作。

./bin/jr-validate

在您的项目中

首先,使用 composer 安装它

composer require lfbn/json-resume-validator

然后,创建一个实例,并调用 isValid() 方法。

$path = 'json_resume.json';

$validator = Lfbn\JsonResumeValidator\JsonResumeValidator::load($path);

echo 'Is valid? '.$validator->isValid();

将 isValid() 方法封装在 try/catch 中。如果文件有效,则此方法将返回 true;如果无效,则抛出异常。

异常的名称包含了错误的描述。

您的必填字段

您可以选择定义您想要必填的字段。

只需使用点表示法定义它们。

$config = [
    'mandatory_fields' => [
        'basics.name',
        'basics.email',
        'basics.phone',
        'basics.summary'
    ]
];

$path = 'json_resume.json';
$resume = Lfbn\JsonResumeValidator\JsonResumeValidator::load($path, $config);

// It returns true, or it throws an Exception, is it fails in any Validation.
$resume->isValid();

测试

此包包含使用多个 JSON 文件来测试行为是否符合预期的测试。

要执行它们,只需运行

composer tests