<?php
/*
* List of available rules:
*
* min (int value) -> Checks for minimum input value
* max (int value) -> Checks for maximum input value
* unique (string table, string column) -> Check for column with value in table valid if not found
* same (string field) -> Compares current and given field values
* required -> Checks for field existance and true value
* exists (string table, string column) -> Same as UNIQUE but its valid if it is found
* may-not-exists -> Its valid if field is not present
* email -> Validates mail
*
* Usage:
* rule:param1,param2|rule2|rule3:param.......
*/
use InputValidator\InputValidator;
$files = scandir(__DIR__ . '/Rules');
foreach ($files as $file) {
if (0 === strpos($file, '.')) {
continue;
}
require_once __DIR__ . "/Rules/{$file}";
}
require_once __DIR__ . '/InputValidator.php';
$input = filter_input_array(INPUT_GET) ?: [];
$validator = new InputValidator($input);
$rules = [
'username' => 'required|min:3|max:24',
'first-name' => 'max:12',
'last-name' => 'max:12',
'email' => 'required|email',
'password' => 'required|min:6',
're-password' => 'same:password'
];
$valid = $validator->validate($rules);
var_dump($valid, $validator->getErrors());
|