2017 © Pedro Peláez
 

library valid8r_php

Validation library supporting multiple programming languages

image

valid8r/valid8r_php

Validation library supporting multiple programming languages

  • Saturday, December 28, 2013
  • by thomporter
  • Repository
  • 1 Watchers
  • 1 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

REPO ARCHIVED

This is quite old, no one should be using it., (*1)

Valid8r - Validation for multiple programming languages., (*2)

Valid8r for PHP

Valid8r is a validation library for multiple programming languages using a common JSON configuration file. Learn more about Valid8r and the configuration file at:, (*3)

https://github.com/thomporter/valid8r, (*4)

Installation

Valid8r for PHP really only has one file you need. If you don't care about testing, examples, etc, you can simply grab the Valid8r.php file from the lib/Valid8r folder:, (*5)

https://raw.github.com/thomporter/valid8r_php/master/lib/Valid8r/Valid8r.php, (*6)

Alternatively, you can clone this rep and get examples & tests., (*7)

You can also install via Composer:, (*8)

{
  "require": {
    "valid8r/valid8r_php": ">=v0.0.3"
  }
}

Examples

Get the Examples folder running on an PHP enabled web server and you can check out the Kitchen Sink examples., (*9)

Here's a quick idea of how it works in PHP:, (*10)

<?php
$validator = new Valid8r(Array(
    'rules_file' => '/path/to/your/rules.json',
    'data' => $_POST // assumed to be slash-free
));
$errors = $validator->validateAll();
// errors is now an associative array, where the keys are fields with 
// errors, and values are the errors themselves.  
// Fields with no errors are not in the array.

if (!empty($errors)) {
    // there was at least one error in the form...
}

if (@$errors['field_name']) {
    // field_name has an error, the error string is in $errors['field_name']
}

Custom Validators

For general information about Custom Validators, see the main Valid8r docs, (*11)

Valid8r for PHP supports custom validators via any of the following:, (*12)

  • Standard Functions
  • Static Methods of Classes
  • Instance Methods of Classes

No matter which you use, your function must accept 2 arguments ($field & $value) and must either return a string to use as the error, or a blank string if no error., (*13)

Custom Validators using Standard Functions

Just use the function name as the value for the func property of your custom rule and Valid8r will access it directly., (*14)

Custom Validators using Static Methods

You can add a php_static_class to your custom rule and Valid8r will combine that with the func property to build the call:, (*15)

$php_static_class::$func($field, $value)

You can also add a php_namespace which will cause Valid8r to make the call like so:, (*16)

$php_namespace\$php_static_class::$func($field, $value)

Custom Validators using Instance Methods

If you need Valid8r to initialize a class, and then call a method on it, this is the options for you. Add a php_class property, and Valid8r will make the call like so:, (*17)

$validator = new $php_class
$validator->$func($field, $value)

Tests

PHPUnit tests are available if you clone/download the repo. Once you have PHPUnit installed, you can run the tests with:, (*18)

`run-tests`

The Versions

28/12 2013

dev-master

9999999-dev http://thomporter.com/valid8r

Validation library supporting multiple programming languages

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

validation validate form validation

28/12 2013

v0.1.0

0.1.0.0 http://thomporter.com/valid8r

Validation library supporting multiple programming languages

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

validation validate form validation

26/12 2013

v0.0.6

0.0.6.0 http://thomporter.com/valid8r

Validation library supporting multiple programming languages

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

validation validate form validation

23/12 2013

v0.0.5

0.0.5.0 http://thomporter.com/valid8r

Validation library supporting multiple programming languages

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

validation validate form validation

23/12 2013

v0.0.4

0.0.4.0 http://thomporter.com/valid8r

Validation library supporting multiple programming languages

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

validation validate form validation

20/12 2013

v0.0.3

0.0.3.0 http://thomporter.com/valid8r

Validation library supporting multiple programming languages

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

validation

19/12 2013

v0.0.2

0.0.2.0 http://thomporter.com/valid8r

Validation library supporting multiple programming languages

  Sources   Download

MIT

validation