Valiation : The most awesome validation engine ever created for PHP

https://github.com/Respect/Validation

The past few weeks, you would find Validation at Github’s PHP Trending projects.

Validation is a very flexible, fully customizable, loaded with tone of validators, engine that you can use on your PHP projects right away.

Here is a great list why this library it’s actually awesome.

From Reddit:

  • The chain is not a simple chain (it is not just linear), it is a fluent builder for a composite structure. You can write almost any validation rule for any data structure and group it in a single object:v::key(“name”, v::string()->length(1, 32)) ->key(“birth”, v::date(‘Y-m-d’)->minimumAge(18)) ->assert($someArrayWithData);
  • You can nest as many validators as you want.
  • Each validator is an instance that you can reuse (even for composing new, more complex instances).
  • Three kinds of validation reports (validate() returns true/false, check() stops on first error, assert() collect all errors).
  • Nested reports implement RecursiveIteratorIterator AND RecursiveTreeIterator (that’s where the ASCII tree report came from!)
  • A selector API for finding messages in complex nested reports (findMessages([“user.address.street.length”])).
  • Reports are only generated when needed (true/false validation doesn’t even touch the reporting system).
  • Really easy to extend (most rules have a single method).
  • Really easy to make inline rules:v::callback(function ($input) { return $input == 42; });
  • Logic operations on any validator:v::allOf(v::numeric(), v::hexa(), v::min(1)); // numeric, hexadecimal and at least 1 v::oneOf(v::nullValue(), v::numeric()); // null or numeric
  • Integrates with ZF1, ZF2 and Symfony2 validators if needed. Dependency is optional.
  • A full concrete API (not relying on magic methods or chains) that can be built using dependency injection.
  • Straightforward to use on unit tests instead of the PHPUnit assertion library.

Here i wrote a simple User Model class where we can make our validation:

Validation will throw an exception when it fail and you can inform your users.

Advertisements

Leave a comment.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s