gatherpackages / config
此软件包最新版本(1.3.1)没有可用的许可信息。
验证GatherContent的项目配置
1.3.1
2021-08-12 08:11 UTC
Requires
- php: >=7.3
- beberlei/assert: ^3.3
Requires (Dev)
- phpunit/phpunit: 9.*
- squizlabs/php_codesniffer: 1.*
This package is auto-updated.
Last update: 2024-09-12 14:47:42 UTC
README
确保配置遵循 规则。
需求
- PHP 7.3或更高版本
安装
在您的仓库内运行以下命令
$ composer require gatherpackages/config:1.*
用法
$json = 'your config in JSON format goes here!'; $configObject = Config::fromJson($json);
如果配置不遵循 规则,上述代码将抛出 ConfigValueException
。
规则
配置是一个标签数组。它必须至少有一个标签。
有效配置的示例
[ { "label": "Content", "name": "tab1", "hidden": false, "elements": [ { "type": "text", "name": "el1", "required": false, "label": "Blog post", "value": "<p>Hello world</p>", "microcopy": "", "limit_type": "words", "limit": "1000", "plain_text": false } ] } ]
标签结构
必须是对象。所有属性都是必需的。不允许有其他属性。
{ "label": "Content", // string, not empty "name": "tab1", // string, not empty, unique "hidden": false, // boolean "elements": [ /* tab elements */ ] // array }
元素结构
允许的元素类型
text
files
section
choice_radio
choice_checkbox
所有元素都必须是对象。所有属性都是必需的。不允许有其他属性。
类型 text
{ "type": "text", // string, must be "text" "name": "el1", // string, not empty, unique "required": false, // boolean "label": "Blog post", // string, not empty "value": "<p>Hello world</p>", // string "microcopy": "", // string "limit_type": "words", // string, either "words" or "chars" "limit": 1000, // integer, non-negative "plain_text": false // boolean }
类型 files
{ "type": "files", // string, must be "files" "name": "el2", // string, not empty, unique "required": false, // boolean "label": "Photos", // string, not empty "microcopy": "" // string }
类型 section
{ "type": "section", // string, must be "section" "name": "el3", // string, not empty, unique "title": "Title", // string, not empty "subtitle": "<p>How goes it?</p>" // string }
类型 choice_radio
{ "type": "choice_radio", // string, must be "choice_radio" "name": "el4", // string, not empty, unique "required": false, // boolean "label": "Label", // string, not empty "microcopy": "", // string "other_option": false, // boolean "options": [ /* element options */ ] // array, must have at least one option }
如果 other_option
为 true
,则至少需要两个选项。
类型 choice_checkbox
{ "type": "choice_checkbox", // string, must be "choice_checkbox" "name": "el4", // string, not empty, unique "required": false, // boolean "label": "Label", // string, not empty "microcopy": "", // string "options": [ /* element options */ ] // array, must have at least one option }
选项结构
所有选项都必须是对象。所有属性都是必需的。不允许有其他属性。
大多数选项将看起来像这样
{ "name": "op1", // string, not empty, unique "label": "Option 1", // string, not empty "selected": false // boolean }
唯一的例外是 choice_radio
元素的最后一个选项,如果 other_option
属性为 true
{ "name": "op1", // string, not empty, unique "label": "Other", // string, not empty "selected": true, // boolean "value": "Something" // string }
如果未选择选项,"other" 选项的 value
属性必须为空。
choice_radio
不应选择多个选项。
测试
运行单元测试
$ ./vendor/bin/phpunit
测试是否符合 PSR2编码风格指南
$ ./vendor/bin/phpcs --standard=PSR2 ./src