2017 © Pedro Peláez
 

library rock-validate

Flexible validator for PHP with I18N.

image

romeoz/rock-validate

Flexible validator for PHP with I18N.

  • Tuesday, October 18, 2016
  • by romeOz
  • Repository
  • 3 Watchers
  • 24 Stars
  • 1,549 Installations
  • PHP
  • 6 Dependents
  • 4 Suggesters
  • 1 Forks
  • 1 Open issues
  • 20 Versions
  • 0 % Grown

The README.md

Validator for PHP

Latest Stable Version Total Downloads Build Status HHVM Status Coverage Status License, (*1)

Features

  • Supports large many validation rules (string, number, ctype, file, network)
  • Validation of scalar variable and array (attributes())
  • Output the list of errors in an associative array
  • i18n support
  • Hot replacement of placeholders for messages ({{name}} must be valid), as well messages
  • Customization of validation rules
  • Module for Rock Framework

Bolded features are different from Respect/Validation., (*2)

Table of Contents

Installation

From the Command Line:, (*3)

composer require romeoz/rock-validate

In your composer.json:, (*4)

{
    "require": {
        "romeoz/rock-validate": "*"
    }
}

Quick Start

use rock\validate\Validate;

// Validation length from 10 to 20 characters inclusive + regexp pattern
$v = Validate::length(10, 20, true)->regex('/^[a-z]+$/i');
$v->validate('O’Reilly'); // output: false

$v->getErrors();
/*
output:

[
  'length' => 'value must have a length between 10 and 20',
  'regex' => 'value contains invalid characters'
]
*/

$v->getFirstError();
// output: value must have a length between 10 and 20

Replacement a placeholder

use rock\validate\Validate;

$v = Validate::length(10, 20, true)
            ->regex('/^[a-z]+$/i')
            ->setPlaceholders(['name' => 'username']);
$v->validate('O’Reilly'); // output: false

$v->getErrors();
/*
output:

[
  'length' => 'username must have a length between 10 and 20',
  'regex' => 'username contains invalid characters',
]
*/

i18n

use rock\validate\Validate;

$v = Validate::length(10, 20, true)->regex('/^[a-z]+$/i')->setLocale('ru');
$v->validate('O’Reilly'); // output: false

$v->getErrors();
/*
output:

[
  'length' => 'значение должно иметь длину в диапазоне от 10 до 20',
  'regex' => 'значение содержит неверные символы',
]
*/

As Array or Object

use rock\validate\Validate;

$input = [
    'username' => 'O’Reilly',
    'email' => 'o-reilly@site'
];
$attributes = [
  'username' => Validate::required()
      ->length(10, 20, true)
      ->regex('/^[a-z]+$/i')
      ->setPlaceholders(['name' => 'username']),

  'email' => Validate::required()->email()
];

$v = Validate::attributes($attributes);
$v->validate($input); // output false

$v->getErrors();
/*
output:

[
  'username' => [
    'length' => 'username must have a length between 10 and 20',
    'regex' => 'username contains invalid characters',
  ],
  'email' => [
    'email' => 'email must be valid email',
  ]
]
*/

$attribute = 'email';
$v->getFirstError($attribute);
// output: email must be valid

Documentation

Demo

Requirements

  • PHP 5.4+

License

The Rock Validate is open-sourced software licensed under the MIT license., (*5)

The Versions

18/10 2016

dev-master

9999999-dev

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

18/10 2016

0.12.1

0.12.1.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

07/11 2015

0.12.0

0.12.0.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

06/11 2015

0.11.0

0.11.0.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

18/10 2015

0.10.12

0.10.12.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

10/07 2015

0.10.11

0.10.11.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

10/07 2015

0.10.10

0.10.10.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

05/06 2015

0.10.9

0.10.9.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

28/05 2015

0.10.8

0.10.8.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

23/05 2015

0.10.7

0.10.7.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

20/05 2015

0.10.6

0.10.6.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

26/03 2015

0.10.5

0.10.5.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

23/03 2015

0.10.4

0.10.4.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

20/03 2015

0.10.3

0.10.3.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

20/03 2015

0.10.2

0.10.2.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

19/03 2015

0.10.1

0.10.1.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

16/02 2015

0.10.0

0.10.0.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

27/10 2014

0.9.2

0.9.2.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

26/10 2014

0.9.1

0.9.1.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate

26/10 2014

0.9.0

0.9.0.0

Flexible validator for PHP with I18N.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Ruslan

validator validation validate