Loading Please wait...

validationCore Class Reference

validationCore class contains the Common methods and attributes of all types of validation related classes such as form validation upload validation etc. More...

Inheritance diagram for validationCore:

Inheritance graph
[legend]
Collaboration diagram for validationCore:

Collaboration graph
[legend]

Public Member Functions

 addCriteria ($field_name, $rules=null, $msg=null)
 Sets the Rules for form validation.
 removeCriteria ($field_name, $criteria=null)
 if a Criteria is specified Removes that specific Criteria else Removes all criterias for that Field Name Supplied
 parseCriteria ($map_file)
 Parses the validation map from an existing config file.
 validationStatus ()
 gets a (optional) form field name and returns true if its valid else returns either (if mode is Z_VLD_NUMERICAL) the index of the unmatched rule, or (Z_VLD_TEXTUAL) textuale name e.g.
 overrideErrorMsg ($field_name, $err, $err_txt)
 This method lets you overrite teh error message set for a certain form field for a certain error.
 isValid ($key=null)
 If no arguments given Returns true if all form fields in the form is valid else returns flase If a form field name is given as an arguments returns true if that form field is valid else returns false.
 errtext ($field_name)
 Returns teh error text set for a crtain field for the unmatched criteria.
 revalidate ()
 Revalidate everything.

Data Fields

 $rules = array()
 $res = array()
 $err
 $validated = false

Detailed Description

validationCore class contains the Common methods and attributes of all types of validation related classes such as form validation upload validation etc.

Definition at line 30 of file abstract/validation/core.php.


Member Function Documentation

validationCore::addCriteria ( field_name,
rules = null,
msg = null 
)

Sets the Rules for form validation.

Must have $this->method already set before using it provide the form field name as the forst argument and an array of rules as the second argument.

if $rules is given as string $msg must be a string if a third argument $msg is given as an array it would be assumed that the 2nd argument $rules is an array of rules. If a third argument $msg is given as an String or Intger It would be assumed that 2nd argument is also a string and it would fire Error if its not string if the third argument $msg is not given it would be assumed that $rules array contains the CRITERIA(s) as the key elements and teh error message(s) as the value(s) and if the criteria is not valid it would Fire Error if the $rules array is NUMARICALLY INDEXED It would Fire Error

Parameters:
$field_name string
$rules mixed
$msg mixed optional

{$msg is given

Definition at line 51 of file abstract/validation/core.php.

References $rules, and perror().

Referenced by parseCriteria().

00051                                                            {
00052     if(is_null($msg)){//Check wheaher the $msg is given or not
00053       //{$msg is not given
00054         foreach($rules as $rule => $err_msg){
00055           if(!isset($this->rules[$field_name])){$this->rules[$field_name] = array();}
00056           if(!is_array($this->rules[$field_name])){$this->rules[$field_name] = array();}
00057           array_push($this->rules[$field_name], $rule);
00058           $this->err[$field_name][$rule] = $err_msg;
00059           $this->err[$field_name][] = $err_msg;
00060         }
00061       //}
00062     }else{
00064         if(is_string($msg)){//$msg is string
00065           if(!is_string($rules)){
00066             perror('<code>zigmoyd.validation.core.addCriteria()</code><br />expects $rule to be a string as $msg is given as a string');
00067           }else{
00068             if(!isset($this->rules[$field_name])){$this->rules[$field_name] = array();}
00069             if(!is_array($this->rules[$field_name])){$this->rules[$field_name] = array();}
00070             array_push($this->rules[$field_name], $rules);
00071             $this->err[$field_name][$rules] = $msg;
00072             $this->err[$field_name][] = $msg;
00073           }
00074         }else{
00075           if(is_array($msg)){//$msg is an Array
00076             foreach($rules as $i => $rule){
00077               if(!isset($this->rules[$field_name])){$this->rules[$field_name] = array();}
00078               if(!is_array($this->rules[$field_name])){$this->rules[$field_name] = array();}
00079               array_push($this->rules[$field_name], $rule);
00080               $this->err[$field_name][$rule] = $msg[$i];
00081               $this->err[$field_name][$i] = $msg[$i];
00082             }
00083           }else{
00084             perror('<code>zigmoyd.validation.core.addCriteria()</code><br />Invalid Datatype of $msg');
00085           }
00086         }
00087       //}
00088     }
00089   }

Here is the call graph for this function:

validationCore::removeCriteria ( field_name,
criteria = null 
)

if a Criteria is specified Removes that specific Criteria else Removes all criterias for that Field Name Supplied

Parameters:
$field_name string
$criteria string optional

Definition at line 96 of file abstract/validation/core.php.

References perror().

00096                                                         {//If $criteria is null Remove all criteria for the Field
00097     if(!is_null($criteria)){//$criteria is not Null So remove teh Specific Criteria Specified
00098       foreach($this->rules[$field_name] as $i => $rule){
00099         //{ Remove the Crite from rules Array
00100         if(!is_numeric($criteria)){
00101           if($rule == $criteria){
00102             unset($this->rules[$field_name][$i]);
00103             $this->rules[$field_name] = array_values($this->rules[$field_name]);
00104             break;
00105           }
00106         }else{
00107           if($i == $criteria){
00108             unset($this->rules[$field_name][$i]);
00109             $this->rules[$field_name] = array_values($this->rules[$field_name]);
00110             break;
00111           }
00112         }
00113         //}
00114       }
00115       //{ Remove the Criteria from Error Message's Array
00116       //{ Grab the alternative index that assciates with it
00117       //{{ Grab the current Index
00118       $err_keys = array_keys($this->err[$field_name]);
00119       foreach($err_keys as $current_indx => $current_criteria){
00120         if(strcmp($current_criteria, $criteria) == 0){
00121           break;//$current_indx holds the current index
00122         }
00123       }
00124       //}}
00125       if(is_numeric($current_criteria)){//The Error Code that user has supplied is Numarical
00126         //{{ Grab the Previous Index
00127         $indx = $err_keys[$current_indx-1];
00128         //}}
00129       }else{//The error Code that the User has supplied is Textual
00130         //{{ Grab the Numarical Next Index
00131         $indx = $err_keys[$current_indx+1];
00132         //}}
00133       }
00134       //}
00135       if(!isset($this->err[$field_name][$indx])){
00136         perror('<code>zigmoyd.validation.core.removeCriteria()</code><br />Zigmoyd Internal debug level Error Plese Inform this to Zigmoyd Developers<br />Alternative Index not found<br />on File '.__FILE__.' Class validation near Line '.__LINE__);
00137       }
00138       unset($this->err[$field_name][$current_criteria]);
00139       unset($this->err[$field_name][$indx]);
00140       //}
00141     }else{//No Criteria is Specified So all Criterias are going to be removed
00142       foreach($this->rules[$field_name] as $i => $rule){
00143         unset($this->rules[$field_name][$i]);
00144       }
00145     }
00146   }

Here is the call graph for this function:

validationCore::parseCriteria ( map_file  ) 

Parses the validation map from an existing config file.

Parameters:
$map_file string

Definition at line 152 of file abstract/validation/core.php.

References addCriteria(), and vldMapParser::tokenize().

Referenced by zRom_upload::initValidator(), and zRom_form::initValidator().

00152                                    {
00153     foreach($this->tokenize($map_file) as $field_name => $criteria){
00154       $this->addCriteria($field_name, $criteria);
00155     }
00156   }

Here is the call graph for this function:

validationCore::validationStatus (  ) 

gets a (optional) form field name and returns true if its valid else returns either (if mode is Z_VLD_NUMERICAL) the index of the unmatched rule, or (Z_VLD_TEXTUAL) textuale name e.g.

required of the unmatched rule. if No form field is specified it walks through all the form fields and returns the Index or textual name of the first Unmatched form field depending upon the mode By default mode is set to Z_VLD_NUMERICA and form field name is specified to null.

Parameters:
$form_field_name string optional
$validation_mode boolean optional
Returns:
mixed

Definition at line 169 of file abstract/validation/core.php.

References $val, and perror().

Referenced by zRom_upload::initValidator(), zRom_form::initValidator(), isValid(), and revalidate().

00169                              {
00170     //{ Handle the arguments given
00171     if(func_num_args() > 0){
00172       if(func_num_args() > 2){
00173         perror('<code>zigmoyd.validation.core.validationStatus()</code><br /> doesn\'t accepts more than 2 arguments');
00174       }elseif(func_num_args() == 2){
00175         //Exact 2 arguments are given
00176         $key = func_get_arg(0);
00177         $mode = func_get_arg(1);
00178       }else{
00179         //1 arguments given
00180         if(is_string(func_get_arg(0))){
00181           $key = func_get_arg(0);
00182           $mode = Z_VLD_NUMERICAL;
00183         }elseif(is_bool(func_get_arg(0))){
00184           $key = null;
00185           $mode = func_get_arg(0);
00186         }else{
00187           perror('<code>zigmoyd.validation.core.validationStatus()</code><br />Failed understand the arguments given plsese see the manual first');
00188         }
00189       }
00190     }else{
00191       $key = null;
00192       $mode = Z_VLD_NUMERICAL;
00193     }
00194     //}
00195     if($this->validated != $mode){
00196       $this->validate($mode);
00197     }
00198     if(!is_null($key)){
00199       if(!isset($this->res[$key])){
00200         perror('Either No rules Applied on the field `'.$key.'` or '.__CLASS__.'::validationStatus() is being called without calling '.__CLASS__.'::add_criterias() before');
00201       }else{
00202         return $this->res[$key];
00203       }
00204     }else{
00205       foreach($this->res as $key => $val){
00206         if(!is_bool($val)){return $key;}
00207       }
00208       return true;
00209     }
00210   }

Here is the call graph for this function:

validationCore::overrideErrorMsg ( field_name,
err,
err_txt 
)

This method lets you overrite teh error message set for a certain form field for a certain error.

Parameters:
$field_name string
$err mixed
$err_txt string

Definition at line 218 of file abstract/validation/core.php.

References $err, and perror().

00218                                                         {
00219     if(!isset($this->rules[$field_name])){
00220       perror("<code>zigmoyd.validation.core.overrideErrorMsg()</code><br />no rule hs been set for The field name $field_name but being used in ");
00221     }else{
00222       $this->err[$field_name][$err] = $err_txt;
00223       //{ Grab the alternative that assciates with it
00224       //{{ Grab the current Index
00225       $err_keys = array_keys($this->err[$field_name]);
00226       foreach($err_keys as $current_indx => $current_criteria){
00227         if($current_criteria == $err){
00228           break;//$current_indx holds the current index
00229         }
00230       }
00231       //}}
00232       if(is_numeric($err)){//The Error Code that user has supplied is Numarical
00233         //{{ Grab the Previous Index
00234         $indx = $err_keys[$current_indx];
00235         //}}
00236       }else{//The error Code that the User has supplied is Textual
00237         //{{ Grab the Numarical Next Index
00238         $indx = $err_keys[$current_indx+1];
00239         //}}
00240       }
00241       //}
00242       if(!isset($this->err[$field_name][$indx])){
00243         perror('<code>zigmoyd.validation.core.overrideErrorMsg()</code><br />Zigmoyd Internal debug level Error Plese Inform this to Zigmoyd Developers<br />Alternative Index not found<br />on /usr/lib/module/ums/validation.php Class validation near Line '.__LINE__);
00244       }
00245       $this->err[$field_name][$indx] = $err_txt;
00246     }
00247   }

Here is the call graph for this function:

validationCore::isValid ( key = null  ) 

If no arguments given Returns true if all form fields in the form is valid else returns flase If a form field name is given as an arguments returns true if that form field is valid else returns false.

Parameters:
$key string
Returns:
bool

Definition at line 257 of file abstract/validation/core.php.

References validationStatus().

Referenced by zRom_upload::initValidator(), zRom_form::initValidator(), and revalidate().

00257                                {
00258     if($this->validated != Z_VLD_NUMERICAL)$this->validate();
00259     if($key == null){
00260       //Test wheather the form is totally valid or not
00261       $ret = true;
00262       foreach($this->res as $v){
00263         if(!is_bool($v)){$ret = false;break;}
00264       }
00265       return $ret;
00266     }else{
00267       //Check the given form field
00268       if(is_bool($this->validationStatus($key))){return true;}else{return false;}
00269     }
00270   }

Here is the call graph for this function:

validationCore::errtext ( field_name  ) 

Returns teh error text set for a crtain field for the unmatched criteria.

Parameters:
$field_name string
Returns:
string

Definition at line 277 of file abstract/validation/core.php.

References perror().

Referenced by zRom_upload::initValidator(), zRom_form::initValidator(), and revalidate().

00277                                {
00278     /*{{ If the form is already not validated first validate it
00279     if($this->validated != $mode){
00280       $this->validate($mode);
00281     }
00282     }}*/
00283     if(!isset($this->err[$field_name])){
00284       perror('<code>zigmoyd.validation.core.errtext()</code><br />No error message is set for Field '.$field_name);
00285     }else{
00286       if(!isset($this->rules[$field_name])){
00287         perror('<code>zigmoyd.validation.core.errtext()</code><br />No rule is set for Field '.$field_name.' but being used in ');
00288       }else{
00289         if(is_bool($this->res[$field_name]) && $this->res[$field_name]){
00290           return true;//Field is valid
00291         }else{
00292           if(!isset($this->err[$field_name][$this->res[$field_name]])){
00293             perror("<code>zigmoyd.validation.core.errtext()</code><br /> No Error Message has been set for Error Index ".$this->res[$field_name]." Error Name ".$this->rules[$this->res[$field_name]]);
00294           }
00295           return $this->err[$field_name][$this->res[$field_name]];//Return the Error Text
00296         }
00297       }
00298     }
00299   }

Here is the call graph for this function:

validationCore::revalidate (  ) 

Revalidate everything.

Definition at line 304 of file abstract/validation/core.php.

References $rules, errtext(), isValid(), and validationStatus().

00304                        {
00305     $this->validate();
00306     $this->isValid = $this->isValid();
00307     foreach($this->rules as $field_name => $rules){
00308       //{ Make the $this->${field_names} = OBJECTS
00309       $this->{$field_name} = new zRom_fields($this->items[$field_name], $this->errtext($field_name), $this->isValid($field_name), $this->validationStatus($field_name));
00310       //}
00311     }
00312   }

Here is the call graph for this function:


Field Documentation

validationCore::$rules = array()

validationCore::$res = array()

Definition at line 32 of file abstract/validation/core.php.

validationCore::$err

Definition at line 33 of file abstract/validation/core.php.

Referenced by overrideErrorMsg().

validationCore::$validated = false

Definition at line 34 of file abstract/validation/core.php.


The documentation for this class was generated from the following file:

Generated on Mon Oct 27 23:53:17 2008 for zigmoyd.kdevelop by doxygen 1.5.6