weew/config-schema
Composer 安装命令:
composer require weew/config-schema
包简介
Schema builder for the weew/config package.
README 文档
README
Table of contents
Installation
composer require weew/config-schema
Introduction
This package allows easy config validation and is used in combination with the weew/config package.
Usage
You can describe your config schema like this:
$config = new Config([ 'some' => 'value', 'items' => ['foo', 'bar'], 'name' => 'John Doe', ]); $schema = new ConfigSchema($config); $schema ->hasValue('some') ->hasArray('items')->allowed(['foo', 'baz']) ->hasString('name')->min(3)->max(10) ;
After you've described your schema, you can either validate it, which will return you an instance of IValidationResult, or assert it, which will throw an exception.
$result = $schema->check(); foreach ($result->getErrors() as $error) { echo $error->getSubject() . ' ' . $error->getMessage(); } // or try { $schema->assert(); } catch (ConfigValidationException $ex) { $result = $ex->getValidationResult(); }
统计信息
- 总下载量: 112
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-17