2017 © Pedro Peláez
 

library config-value-object

Validate item config for GatherContent

image

gathercontent/config-value-object

Validate item config for GatherContent

  • Monday, September 7, 2015
  • by acairns
  • Repository
  • 9 Watchers
  • 2 Stars
  • 16,705 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 8 Versions
  • 32 % Grown

The README.md

Config Value Object

Build Status, (*1)

Ensure the config adheres to the rules., (*2)

Requirements

  • PHP 5.3.0 or later (recommend at least PHP 7.1)

Installation

Run the following command inside your repository:, (*3)

$ composer require gathercontent/config-value-object:0.2.*

Usage

$json = 'your config in JSON format goes here!';

$configObject = Config::fromJson($json);

The code above will throw ConfigValueException if the config does not adhere to the rules., (*4)

The rules

The config is an array of tabs. It must have at least one tab., (*5)

An example of valid config:, (*6)

[
  {
    "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
      }
    ]
  }
]

Tab structure:

Must be an object. All attributes are required. No additional attributes are allowed., (*7)

{
  "label": "Content",                // string, not empty
  "name": "tab1",                    // string, not empty, unique
  "hidden": false,                   // boolean
  "elements": [ /* tab elements */ ] // array
}

Element structure

Allowed element types:, (*8)

  • text
  • files
  • section
  • choice_radio
  • choice_checkbox

All elements must be objects. All attributes are required. No additional attributes are allowed., (*9)

Type 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
}
Type files:
{
  "type": "files",   // string, must be "files"
  "name": "el2",     // string, not empty, unique
  "required": false, // boolean
  "label": "Photos", // string, not empty
  "microcopy": ""    // string
}
Type 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
}
Type 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
}

At least two options required if other_option is true., (*10)

Type 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
}

Option structure

All options must be objects. All attributes are required. No additional attributes are allowed., (*11)

Most options will look like this:, (*12)

{
  "name": "op1",       // string, not empty, unique
  "label": "Option 1", // string, not empty
  "selected": false    // boolean
}

The only exception is the last option for choice_radio element if the other_option attribute is true:, (*13)

{
  "name": "op1",       // string, not empty, unique
  "label": "Other",    // string, not empty
  "selected": true,    // boolean
  "value": "Something" // string
}

The value attribute for "other" option must be empty if the option is not selected., (*14)

choice_radio must not have more than one option selected., (*15)

Testing

Run unit tests:, (*16)

``` bash $ ./vendor/bin/phpunit, (*17)


Test compliance with [PSR2 coding style guide](http://www.php-fig.org/psr/psr-2/): ``` bash $ ./vendor/bin/phpcs --standard=PSR2 ./src

The Versions

07/09 2015

dev-master

9999999-dev

Validate item config for GatherContent

  Sources   Download

The Requires

 

The Development Requires

07/09 2015

0.2.3

0.2.3.0

Validate item config for GatherContent

  Sources   Download

The Requires

 

The Development Requires

07/09 2015

dev-develop

dev-develop

Validate item config for GatherContent

  Sources   Download

The Requires

 

The Development Requires

31/08 2015

0.2.2

0.2.2.0

Validate item config for GatherContent

  Sources   Download

The Requires

 

The Development Requires

28/08 2015

0.2.1

0.2.1.0

Validate item config for GatherContent

  Sources   Download

The Requires

 

The Development Requires

27/08 2015

0.2.0

0.2.0.0

Validate item config for GatherContent

  Sources   Download

The Requires

 

The Development Requires

25/08 2015

0.1.1

0.1.1.0

Validate item config for GatherContent

  Sources   Download

The Requires

 

The Development Requires

21/08 2015

0.1.0

0.1.0.0

Validate item config for GatherContent

  Sources   Download

The Requires

 

The Development Requires