<?php
/*
*
*
* array // aka is_array()
* strict_array //alias of array
* bool // if string representation is "1" or "0" or "on" or "off" or "true" or "false"
* strict_bool //aka is_boolean()
* float //check if string representation can be losslessly converted to an float..
* strict_float // aka is_float()
* int // check if string representation can be losslessly converted to an int
* strict_int // aka is_int()
* string // check if variables can be converted to a string..
* strict_string //aka is_string()
* null //aka is_null()
* strict_null //alias of null
* numeric //aka is_numeric()
* strict_numeric // alias of numeric... maybe ill change this later
* object //aka is_object()
* strict_object //alias of object
* callable //aka is_callable()
* strict_callable //alias of callable
* resource //aka is_resource()
* strict_resource //alias of resource
* integer //alias of int
* strict_integer // alias of strict_int
* double //alis of float
* strict_double //alias of strict_float
* real //alias of float
* strict_real //alias of strict_float
* scalar //aka is_scalar()
* strict_scalar //alias of scalar
* long //alias of int
* strict_long //alias of strict_int
* * * */
function hhb_mustbe1() {
//throw new Exception("not implemented yet!! name reserved & function under development...");
//TODO: optimize this function, we have tons of useless variables and aliases that
//should never have been declared at all...
$argc = func_num_args();
if (!($argc>=2 && 0===($argc%2))) {
throw new BadFunctionCallException('$argc=' . $argc . ' , argc must be >=2 and mod2===0, anything else is an obvious error!');
};
$validators = array();
$validators['array']=$valiate_array = function($invar) {
return is_array($invar);
};
$validators['strict_array']=$validate_strict_array = $validate_array;
//alias.
$validators['bool']=$validate_bool = function($invar) {$res = filter_var($invar, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
return $res !== null;
};
$validators['strict_bool']=$validate_strict_bool = function($invar) {
return is_bool($invar);
};
$validators['float']=$validate_float = function($invar) {$res = filter_var($invar, FILTER_VALIDATE_FLOAT);
return $res !== false;
};
$validators['strict_float']=$validate_strict_float = function($invar) {
return is_float($invar);
};
$validators['int']=$validate_int = function($invar) {$res = filter_var($invar, FILTER_VALIDATE_INT);
return $res !== false;
};
$validators['strict_int']=$validate_strict_int = function($invar) {
return is_infinite($invar);
};
$validators['string']=$validate_string = function($invar) {
//PS: there is very few things in PHP that cannot be threated like a string in php.. object lacking __toString is 1
try {$invar = (string)$invar;
return true;
} catch(Exception $ex) {
return false;
};
};
$validators['strict_string']=$validate_strict_string = function($invar) {
return is_string($invar);
};
$validators['null']=$validate_null = function($invar) {
return is_null($invar);
};
$validators['strict_null']=$validate_strict_null = $validate_null;
//alias
$validators['numeric']=$validate_numeric = function($invar) {
return is_numeric($var);
};
$validators['strict_numeric']=$validate_strict_numeric = $validate_numeric;
//alias
$validators['object']=$validate_object = function($invar) {
return is_object($invar);
};
$validators['strict_object']=$validate_strict_object = $validate_object;
//alias
$validators['callable']=$validate_callable = function($invar) {
return is_callable($invar);
};
$validators['strict_callable']=$validate_strict_callable = $validate_callable;
//alias
$validators['resource']=$validate_resource = function($invar) {
return is_resource($invar);
};
$validators['strict_resource']=$validate_strict_resource = $validate_resource;
//alias
$validators['integer']=$validate_integer = $validate_int;
//alias
$validators['strict_integer']=$validate_strict_integer = $validate_strict_int;
//alias
$validators['double']=$validate_double = $validate_float;
//alias
$validators['strict_double']=$validate_strict_double = $validate_strict_float;
//alias
$validators['real']=$validate_real = $validate_float;
//alias
$validators['strict_real']=$validate_strict_real = $validate_strict_float;
//alias
$validators['scalar']=$validate_scalar = function($invar) {
return is_scalar($invar);
};
$validators['strict_scalar']=$validate_strict_scalar = $validate_scalar;
//alias
$validators['long']=$validate_long = $validate_int;
//alias
$validators['strict_long']=$validate_strict_long = $validate_strict_int;
//alias
$operators=array('and'=>1,'or'=>1,'not'=>'unimplemented!');
$parse_validators=function($invar) use($validators,$operators){
if(!is_string($invar) && !is_array($invar)){
throw new BadFunctionCallException('you\'re using hhb_musbe1 wrong! every list of validators must be string or array!');
};
if(is_array($invar)){
throw new Exception("sorry, array of validators is not supported/implemented YET..");
//
};
$rawlists=array($invar);
$list=array();
$tmparr=array();
$next_must_be='validator';//ps: after first iteration, "must be" means "assuming there IS a next, next must be"
foreach($rawlists as $rawlist){
$rawlist=preg_replace('/\s+/',' ',$rawlist);
$rawlist=strtolower($rawlist);
$tmparr=explode(" ",$rawlist);
$previous_tmpval=null;
foreach($tmparr as $tmpval){
if($next_must_be==='next_input'){//unreachable when used correctly!
throw new BadFunctionCallException($previous_tmpval.' must be followed by a new value in the array! there can be nothing after it in the string! yet, i found '.$tmpval.' after it! syntax error..');
} else
if($next_must_be==='validator'){
if(!array_key_exists($tmpval,$validators)){
throw BadFunctionCallException('"'.$rawvalidator.'" is not a recognized validator! recognized validator: "'.var_export(array_keys($validators),true).'""');
};
$list[]=array('validator',$tmpval);
//NOTE: tricky strlen n shit?
$next_must_be='operator';
$previous_tmpval=$tmpval;
continue;
} else
if($next_must_be==='operator'){
if(!array_key_exists($tmpval,$operators)){
throw BadFunctionCallException('"'.$rawvalidator.'" is not a recognized operator! recognized operators: "'.var_export(array_keys($operators),true).'"');
}
$list[]=array('operator',$tmpval);
$next_must_be='validator';
$previous_tmpval=$tmpval;
continue;
}//else
{/*ERROR! SHOULD BE UNREACHABLE!*/
throw new LogicException('error! unreachable code..reached; probably caused by invalid $next_must_be='.var_export($next_must_be,true).'');
}
}
}
};
};
function hhb_mustbe2(/*void*/) {
throw new Exception("not implemented yet!! name reserved...");
class validator_class {
public $invoke_counter = 0;
function __destruct() {
}
};
return new validator_class();
};