2017 © Pedro Peláez
 

library php-structure-check

Structural check of arrays for PHP 5.6+

image

1blankz7/php-structure-check

Structural check of arrays for PHP 5.6+

  • Thursday, August 10, 2017
  • by 1blankz7
  • Repository
  • 1 Watchers
  • 2 Stars
  • 4,131 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 10 Versions
  • 12 % Grown

The README.md

PHP Structure Check

Build Status License, (*1)

This library can check a complex array structure against a given requirement. The purpose of this library is to create a better experience when testing a result set from an api or something similar., (*2)

Installation

composer require cubicl/php-structure-check

Usage

Create a requirement:, (*3)

$requirement = new ListType(
    new ObjectType([
        'foo' => new StringType(),
        'bar' => new IntType(),
        'buzz' => new AnyType(),
        'foobar' => new NullableType(new StringType()),
        'nested' => new ObjectType([
            'foobar' => new StringType(),
        ]),
    ])
);

Have some sort of external data you want to check., (*4)

$data = [
    [
        'foo' => 'foe',
        'bar' => 'baz',
        'buzz' => 'foe',
        'foobar' => null,
        'nested' => [
            'foobar' => 'buzz',
        ],
    ], [
        'foo' => 'foe',
        'bar' => 7,
        'buzz' => 'foe',
        'foobar' => 'baz',
        'nested' => [
            'foobar' => 'bozz',
        ],
    ], [
        'foo' => [],
        'bar' => 9.1,
        'foobar' => 'baz',
        'nested' => [
            'foobar' => 'bazz',
        ],
    ],
];

Check the data against the requirement., (*5)

$result = Checker::fulfills($data, $requirement);

The returned object holds information about the analysis. You can check the result by calling isValid() on the result object. To fetch the errors, simply call getErrors., (*6)

Supported Types

Currently the following types are supported:, (*7)

  • Any
  • Nullable
  • Bool
  • Numeric
  • Float
  • Int
  • String
  • Object
  • List
  • Datetime
  • Regex
  • Optional
  • Enum

There are some open issues with ideas for more types. Feel free to send pull requests., (*8)

Additionally you can implement the TypeInterface and use your own type implementations., (*9)

Checks

Checks are special types which can be used to add more rules to a field. So you can check the length of a string, the count of elements in an array or determine if a numeric value is in a given range., (*10)

The Versions

10/08 2017

dev-master

9999999-dev https://github.com/1blankz7/php-structure-check

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types

28/05 2017

0.1.7

0.1.7.0 https://github.com/1blankz7/php-structure-check

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types

28/05 2017

dev-16-optional-type

dev-16-optional-type https://github.com/1blankz7/php-structure-check

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types

21/01 2017

0.1.6

0.1.6.0 https://github.com/1blankz7/php-structure-check

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types

15/01 2017

0.1.5

0.1.5.0 https://github.com/1blankz7/php-structure-check

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types

10/01 2017

0.1.4

0.1.4.0 https://github.com/1blankz7/php-structure-check

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types

09/01 2017

0.1.3

0.1.3.0 https://github.com/1blankz7/php-structure-check

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types

08/01 2017

0.1.2

0.1.2.0 https://github.com/1blankz7/php-structure-check

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types

07/01 2017

0.1.1

0.1.1.0 http://phpspec.net/

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types

07/01 2017

0.1.0

0.1.0.0 http://phpspec.net/

Structural check of arrays for PHP 5.6+

  Sources   Download

MIT

The Development Requires

array structure types