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
   |    	class Checkform
		{	protected $stackMsg = array();
			protected $cntStack = 0 ;
			private $msg, $form, $cntField, $cntFilled, $valid ;
 
			function __construct($form)
			{	
user_error("Start of Constructor[".$this->getCntStack()."]" , E_USER_NOTICE) ;
 
				$this->initForm($form) ;
 
//
//              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->getCntFilled(),$this->getCntField(),$this->isFormValid()) ;
user_error("End of Constructor[".$this->getCntStack()."]" , E_USER_NOTICE) ;	 
			}
 
//          ==================================	
//          All Stack routines			
//          ==================================	
//          ==================================	
//          All Error Stacking functions			
//          ==================================	
			function getCntStack()
			{	return($this->cntStack) ; }	
 
			public function getStackError() 				// Public car function appelée fu formulaire...
			{	
user_error("getStackError[".$this->cntStack."]" , E_USER_NOTICE) ;	 
				$str = "" ; 
print("getStackError ==>[".$this->cntStack."]") ;
//				print_r($this->stackMsg); 
				for ($i = 0 ; $i < $this->cntStack ; $i++)
					$str .= $this->stackMsg[$i] ;
				return($str) ; 
			}
 
			public function stackMessage($msg)
			{	$this->stackMsg[] = $msg . "<br>\n" ; 
				$this->cntStack++ ; 
user_error("+++++++ Stacking msg[".$this->cntStack."][".$msg."]" , E_USER_NOTICE) ;	 
print("Stacking[".$msg."] - cntStack[".$this->cntStack."]") ;
//				print_r($this->stackMsg); 
			}
 
			public function emptyStack()
			{	$this->cntStack = 0 ;
user_error("emptyStack[".$this->cntStack."]" , E_USER_NOTICE) ;	 
				$this->stackMsg = array() ;	 
			}
 
			public function printStack()
			{	
user_error("printStack[".$this->cntStack."]" , E_USER_NOTICE) ;
				for ($i = 0 ; $i < $this->cntStack ; $i++)
					user_error ("stack[".$this->cntStack."] - " . $this->stackMsg[$i] , E_USER_NOTICE) ;
			}
 
//          ==================================	
//          All Screen message area routines			
//          ==================================	
			public function getMessage()                   // Public car function appelée fu formulaire...
			{	return($this->msg->getMessage()) ;  	}
 
			public function isFormValid()
			{	return($this->formValid) ; }
//          ==================================	
 
			private function getCntField()
			{ 	return($this->cntField) ;	}
 
			private function getCntFilled()
			{ 	return($this->cntFilled) ;	}
 
			private function initForm($form)
			{   $this->form  	  = $form ;
				$this->cntField   = count($this->form);
				$this->formValid  = false ;
				$this->emptyStack() ;
			}
 
			function Validate()
			{	$this->cntFilled = 0 ;
user_error("Start of Validation ==> cntStack[".$this->getCntStack()."]" , E_USER_NOTICE) ;	 
				for($i = 0 ; $i < $this->getCntField() ; $i++) 
				{	if ($this->form[$i] instanceof Validator)
//						if ($this->form[$i]->Filled() )
							{	
user_error("Start Validating field[".$i."]  cntStack[".$this->getCntStack()."]" , E_USER_NOTICE) ;
								$this->cntFilled++ ;
								$this->form[$i]->Validate() ; 				
								$this->printStack() ;
user_error("End   Validating field[".$i."]  cntStack[".$this->getCntStack()."]" , E_USER_NOTICE) ;
							}
				}
//user_error("End of Validate ==> cntStack[".Stack::getCntStack()."]" , E_USER_NOTICE) ;	 
			}
//
//          Error Handler Processing
//			========================	
			private 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