dev-master
9999999-dev https://github.com/spiechu/PHP-Static-ValidatorClass designed to check if given variable or array of variables meet certain conditions
MIT
The Requires
- php >=5.3.0
type checking validaton
Class designed to check if given variable or array of variables meet certain conditions
Class primarily created to find some useful purpose for __callStatic
function new in PHP 5.3.0. With PHP StaticValidator You can chain multiple conditions and checked value is being tested one by one., (*1)
Since Validator uses namespaces, it is required to use class autoloader, for example SplClassLoader.php
more info here. You have to register Validator classes:, (*3)
<?php require_once('SplClassLoader.php'); $classLoader = new SplClassLoader('Spiechu\StaticValidator' , 'library'); $classLoader->register();
No external libraries required., (*4)
Static Validator's class is designed to check if given variable or array of variables meet certain conditions., (*5)
Basically every check method starts with check
word, and then You can use separator _
and type next condition which tested variable is supposed to meet., (*6)
For exaple Validator::check_notNull_isInt_gt5($testedVariable);
we can translate to !is_null($testedVariable) && is_int($testedVariable) && ($testedVariable > 5)
You can see we gain some concise and some flexibility (gt5
)., (*7)
We can distinguish three main components in PHP Static Validator:, (*8)
Highly recommended way of constructing magic method name is from broadest test condition to narrowest. For eg. notNull
is broader condition than isInt
, which is broader than gt5
., (*9)
When variable is not set, the only way to avoid E_NOTICE
is to pass variable to check by reference instead of pass by value. Passing by reference cannot be performed in __callStatic's $arg
table so You have to either suppress E_NOTICE
warnings or avoid using isSet
or notSet
., (*10)
Class designed to check if given variable or array of variables meet certain conditions
MIT
type checking validaton