1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| // ========================================================================================================================================================== //
// STACK
// ========================================================================================================================================================== //
class Stack
{ private $stackMsg = array(), $cntStack = 0 ;
function __construct()
{ $this->emptyStack() ; }
function __destruct()
{}
public function getStackError()
{ $str = "" ;
print("getStackError[".$this->cntStack."]") ;
for ($i = 0 ; $i < $this->cntStack ; $i++)
$str .= $this->stackMsg[$i] ;
return($str) ;
}
public function stackMessage($msg)
{ $this->stackMsg[] = $msg . "<br>\n" ;
$this->cntStack++ ;
print("Stacking[".$msg."] - cntStack[".$this->cntStack."]") ;
print_r($this->stackMsg);
}
private function emptyStack()
{ $this->cntStack = 0 ;
$this->stackMsg = array() ;
}
}
// ========================================================================================================================================================== //
// MAIN CLASS: =========>>>>>> CheckForm
// ========================================================================================================================================================== //
class Checkform
{ private $msg, $form, $cntField, $cntFilled, $valid, $stack ;
function __construct($form)
{ # On calcule le nombre d'entrée du tableau
$this->form = $form ;
$this->cntField = count($this->form);
$this->formValid = false ;
$this->stack = new Stack() ;
//
// Error Handler
// =============
try {
$this->Validate() ;
} catch (Exception $E)
{ $this->exception_handler($E) ; }
#
# Choix du message en fonction du nbre de champ remplit OUI || NON (qui sera délivré par getMessage)
# ==================================================================================================
$this->msg = new Message($this->cntFilled,$this->cntField) ;
}
private function getCountFields()
{ return($this->cntField) ; }
// ==================================
// All Error Stacking functions
// ==================================
public function getStackError()
{ print("getStackErrorCF") ;
return($this->stack->getStackError() ) ; }
public function stackMessage($msg)
{ print("stackMessageCF") ;
550 ==> $this->stack->stackMessage($msg) ;
}
// ==================================
// All Screen message area routines
// ==================================
public function getMessage()
{ return($this->msg->getMessage()) ; }
// ==================================
public function isFormValid()
{ return($this->formValid) ; }
protected function chkRange($name,$value,$minl,$maxl)
{ $len = strlen($value) ;
print("ChkRange[".$value."][".$len."][".$minl."][".$maxl."]") ;
if ( ( $len >= $minl && $len <= $maxl) )
return(true) ;
else
{ $msg = "Le champ[".$name."] doit avoir une longueur comprise entre ".$minl." et ".$maxl ;
$this->stackMessage($msg) ;
return(false) ;
}
}
public function Validate()
{ $this->cntFilled = 0 ;
for($i = 0 ; $i < $this->getCountFields() ; $i++)
{ if ($this->form[$i] instanceof Validator)
if ($this->form[$i]->Filled() )
{ $this->cntFilled++ ;
$this->form[$i]->Validate() ;
}
}
}
//
// Error Handler Processing
// ========================
function exception_handler($E)
{ $T = $E->getTrace() ;
// ======================================================================
print("FORM Validator error diagnostic" . "<br>\n") ;
print("=======================" . "<br>\n") ;
print("Message: " . $E->getMessage() . " - File: " . $E->getFile() . " - Line: " . $E->getLine() . "<br>\n") ;
print("<br>\n") ;
print("Trace: " . "<br>\n") ;
print("------ " . "<br>\n") ;
print( " => File : " . $T[0]["file"] . "<br>\n") ;
print( " => calling instruction: " . $T[0]["line"] . "<br>\n") ;
print( " => error class : " . $T[0]["class"] . "<br>\n") ;
print( " => error function : " . $T[0]["function"] . "<br>\n") ;
// ======================================================================
user_error("Connexion error in File: (" . $E->getFile() . ") - line: (" . $E->getLine() . ")" , E_USER_WARNING) ;
}
//
// End of class CheckForm
// ======================
} |
Partager