2017 © Pedro Peláez
 

library validation

Validation library for PHP 5.6+ / HHVM inspired by Joi.

image

bartosz-maciaszek/validation

Validation library for PHP 5.6+ / HHVM inspired by Joi.

  • Thursday, June 16, 2016
  • by bartosz-maciaszek
  • Repository
  • 1 Watchers
  • 22 Stars
  • 166 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

About

Validation library for PHP 5.6+ / PHP 7 / HHVM inspired by Joi from Hapi., (*1)

Build Status Minimum PHP Version Coverage Status Dependency Status, (*2)

Installation

The recommended way to install the library is through Composer, (*3)

composer require bartosz-maciaszek/validation

Examples

Validation with the library is straightforward. You can validate primitives like this:, (*4)

<?php

use Validation\Validation as V;

V::validate('foobar', V::string(), function($err, $output) {
    if ($err) {
        echo 'Validation failed: ' . $err;
        exit;
    }

    echo $output; // 'foobar'
});

You can also chain other assertions:, (*5)

V::validate('user@example.com', V::string()->email(), function($err, $output) {
    // ...
});

The library also supports transformations:, (*6)

V::validate('FooBar', V::string()->lowercase(), function($err, $output) {
    // $output equals 'foobar'!
});

Wanna something more complex? Let's try to validate an array!, (*7)

$input = [
    'username' => 'foobar',
    'password' => 'secret123',
    'birthyear' => 1980,
    'email' => 'foobar@example.com',
    'sex' => 'male'
];

$schema = V::arr()->keys([
    'username' => V::string()->alphanum()->min(3)->max(30),
    'password' => V::string()->regex('/[a-z-A-Z0-9]{3,30}/'),
    'birthyear' => V::number()->integer()->min(1900)->max(2013),
    'email' => V::string()->email(),
    'sex' => V::string()->valid('male', 'female')
]);

V::validate($input, $schema, function ($err, $output) {
    // $err === null -> valid!
});

Documentation can be found here (please note it's not 100% completed :))., (*8)

Tests

To run the unit test, simply install the dependencies and invoke make test, (*9)

$ make deps
$ make test

Contributing

Contributions are welcome. If you want to help, please fork the repo and submit a pull request. To maintain the coding style, please make sure your code complies with PSR2 standard., (*10)

$ make cs

The Versions

16/06 2016

dev-master

9999999-dev

Validation library for PHP 5.6+ / HHVM inspired by Joi.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Bartosz Maciaszek

validation validate

16/06 2016

dev-develop

dev-develop

Validation library for PHP 5.6+ / HHVM inspired by Joi.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Bartosz Maciaszek

validation validate

25/11 2015

1.1.0

1.1.0.0

Validation library for PHP 5.6+ / HHVM inspired by Joi.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Bartosz Maciaszek

validation validate

06/10 2015

1.0.0

1.0.0.0

Validation library for PHP 5.6+ / HHVM inspired by Joi.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Bartosz Maciaszek

validation validate

04/10 2015

dev-feature/multiple_errors

dev-feature/multiple_errors

Validation library for PHP 5.4+ / HHVM inspired by Joi.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Bartosz Maciaszek

validation validate