2017 © Pedro Peláez
 

library validate

A shrimp of a validation library

image

caridea/validate

A shrimp of a validation library

  • Sunday, January 28, 2018
  • by doublecompile
  • Repository
  • 1 Watchers
  • 0 Stars
  • 543 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 1 % Grown

The README.md

caridea-validate

Caridea is a miniscule PHP application library. This shrimpy fellow is what you'd use when you just want some helping hands and not a full-blown framework., (*1)

, (*2)

This is its validation library., (*3)

It supports LIVR rules with some exceptions. See the Compliance → LIVR section below., (*4)

Packagist Build Status Scrutinizer Code Quality Code Coverage Documentation Status, (*5)

Installation

You can install this library using Composer:, (*6)

$ composer require caridea/validate
  • The master branch (version 3.x) of this project requires PHP 7.1 and has no dependencies.
  • Version 2.x of this project requires PHP 7.0 and has no dependencies.
  • Version 1.x of this project requires PHP 5.5 and has no dependencies.

Documentation

Compliance

Releases of this library will conform to Semantic Versioning., (*7)

Our code is intended to comply with PSR-1, PSR-2, and PSR-4. If you find any issues related to standards compliance, please send a pull request!, (*8)

LIVR

We fully support the JSON rule format as defined by the LIVR spec. However, we do not support the v0.4 style declaration for the one_of and list_of rules., (*9)

For the most part, we support all rules and their return codes as defined by version 2.0 of the specification with some notable exceptions. We did not implement the following rules:, (*10)

  • trim – This is part of filtering, not validation.
  • to_lc – This is part of filtering, not validation.
  • to_uc – This is part of filtering, not validation.
  • remove – This is part of filtering, not validation.
  • leave_only – This is part of filtering, not validation.
  • default – This is part of filtering, not validation.
  • or – This is experimental.

We now support alias definitions!, (*11)

We did add an extra validator: timezone! It gives the error WRONG_TIMEZONE if the string provided isn't a valid timezone identifier., (*12)

Examples

To create a validator from a rule set, you can pass the definitions to the builder, or you can use the builder procedurally., (*13)

// rules.json
{
    "name": "required",
    "email": ["required", "email"],
    "drinks": { "one_of": [["coffee", "tea"]] },
    "phone": {"max_length": 10},
}

```php $registry = new \Caridea\Filter\Registry(); $builder = $registry->builder(); $ruleset = json_decode(file_get_contents('rules.json')); $validator = $builder->build($ruleset);, (*14)

```php
$registry = new \Caridea\Filter\Registry();
$builder = $registry->builder();
$validator = $builder->field('name', 'required')
    ->field('email', 'required', 'email')
    ->field('drinks', ['one_of' => [['coffee', 'tea']]])
    ->field('phone', ['max_length' => 10])
    ->build();

You can either inspect the validation results, or throw an exception containing any errors., (*15)

$input = [
    'foo' => 'bar',
    'abc' => '123',
];
$result = $validator->validate($input);
// or
$validator->assert($input);

You can register your own custom rules in the Registry., (*16)

$registry = new \Caridea\Validate\Registry();
$registry->register([
    'credit_card' => ['MyCustomRules', 'getCreditCard'], // a static method
]);

The Versions

28/01 2018

dev-master

9999999-dev http://github.com/libreworks/caridea-validate

A shrimp of a validation library

  Sources   Download

Apache-2.0

The Requires

  • php >=7.1.0

 

The Development Requires

validation validate livr

28/01 2018

3.0.0

3.0.0.0 http://github.com/libreworks/caridea-validate

A shrimp of a validation library

  Sources   Download

Apache-2.0

The Requires

  • php >=7.1.0

 

The Development Requires

validation validate livr

22/09 2016

2.1.0

2.1.0.0 http://github.com/libreworks/caridea-validate

A shrimp of a validation library

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0

 

The Development Requires

validation validate livr

22/09 2016

2.1.x-dev

2.1.9999999.9999999-dev http://github.com/libreworks/caridea-validate

A shrimp of a validation library

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0

 

The Development Requires

validation validate livr

28/03 2016

2.0.0

2.0.0.0 http://github.com/libreworks/caridea-validate

A shrimp of a validation library

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0

 

The Development Requires

validation validate livr

28/03 2016

2.0.x-dev

2.0.9999999.9999999-dev http://github.com/libreworks/caridea-validate

A shrimp of a validation library

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0.0

 

The Development Requires

validation validate livr

22/03 2016

1.x-dev

1.9999999.9999999.9999999-dev http://github.com/libreworks/caridea-validate

A shrimp of a validation library

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5.0

 

The Development Requires

validation validate livr

22/03 2016

1.0.0

1.0.0.0 http://github.com/libreworks/caridea-validate

A shrimp of a validation library

  Sources   Download

Apache-2.0

The Requires

  • php >=5.5.0

 

The Development Requires

validation validate livr