Class et syntaxe & errmsg incompris !
Voilà mosieur...:mrgreen:
Code:
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
| class Stack extends Checkform
{ private $stackMsg = array(), $cntStack = 0 ;
function __construct()
{ $this->emptyStack() ; }
function __destruct()
{}
public function stackMessage($msg)
{ $this->stackMsg[] = $msg . "<br>\n" ;
$this->cntStack++ ;
print("Stacking[".$msg."] - cntStack[".$this->cntStack."]") ;
print_r($this->stackMsg);
}
public function getStackError()
{ $str = "" ;
print("getStackError[".self::cntStack."]") ;
for ($i = 0 ; $i < $this->cntStack ; $i++)
$str .= $this->stackMsg[$i] ;
return($str) ;
}
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(Stack::getStackError() ) ; }
public function stackMessage($msg)
{ print("stackMessageCF") ;
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
// ======================
} |
Class et syntaxe & errmsg incompris !
Par rapport à hier, quelque chose à changé car j'imprime bien le stack....
Code:
1 2 3 4 5 6 7 8 9 10
|
stackMessageCFStacking[Le champ[nom] doit avoir une longueur comprise entre 3 et 30] -
cntStack[4]
Array ( [0] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
[1] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
[2] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
[3] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
) |
Les msgs sont de l'ordre du debugging mais au moment de l'insertion du msg, le stack est correct !
classe et msg incompri....
Mais tu as les deux l'une en dessous de l'autre dans la même fenêtre :P
Class..... vous avez dit facile......
Dans chaque validation, je suis susceptible d'ajouter un msg dans le stack, tu as un appel d'ailleurs dans ChkRange un peu + bas dans la classe CF
Class et syntaxe & errmsg incompris !
Pige pas ton propos sur le "static" ....:calim2:
Class et syntaxe & errmsg incompris !
J'ai essayé comme ceci !
Code:
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
| 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) ;
} |
Le log me donne:
Code:
1 2
| [26-May-2010 16:23:21] PHP Notice: Validating TEXT[xs] in F:\WebSites\test\checkform.php on line 414
[26-May-2010 16:23:21] PHP Fatal error: Call to a member function stackMessage() on a non-object in F:\WebSites\test\checkform.php on line 550 |
Class..... vous avez dit facile......
Je crois que la raison est simple, la méthode getStackError est utilisée par la page HTML pour affichage.... et celle-ci se fout pas mal de tout le reste.... et ne tient pas à connaitre les autres classes...
Voila pkoi - peut être je me trompe - j'ai faut ce choix d'architecture....
Quel préténtion, et un coup de pied dans les chevilles :D
Class OOP vous avez dit facile ?
Voici le dernier test effectué, j'instancie Stack de la même façon que Message....
Code:
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
// ======================
} |
Et j'ai dans le log PHP
[26-May-2010 16:23:21] PHP Notice: Validating TEXT[xs] in F:\WebSites\test\checkform.php on line 414
[26-May-2010 16:23:21] PHP Fatal error: Call to a member function stackMessage() on a non-object in F:\WebSites\test\checkform.php on line 550
non-object ??????????????
Je ne compte pas y passer la soirée, je pense arrêter bientôt....
Demain jusque 15h cela ira pour moi.
@+ :roll:
Class..... vous avez dit facile......
Si tu trouves la solution, envoie un mail quand même mais moi je chipotte encore un peu mais je lève le pied.......
Class OOP vous avez dit facile ?
Je ne suis pas sur de bien te comprendre....
La fille est la classe qui valide et envoie un msg vers la mère en effet via la propriété stackMessage.
La mère fait de même vers sa mère, la grand mère de la fille pour affichage via le propriété getStackMessage
J'ai une piste, je vais creuser l'affaire.....:mouarf:
Class OOP vous avez dit facile ?
En gros je conclus d'après les displays:
Code:
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
|
Stacking
[Le champ[prenom] doit avoir une longueur comprise entre 3 et 30] - cntStack[1]
Array ( [0] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
)
Stacking
[Le champ[prenom] doit avoir une longueur comprise entre 3 et 30] - cntStack[2]
Array ( [0] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
[1] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
)
Stacking
[Le champ[nom] doit avoir une longueur comprise entre 3 et 30] - cntStack[1]
Array ( [0] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
)
Stacking
[Le champ[nom] doit avoir une longueur comprise entre 3 et 30] - cntStack[2]
Array ( [0] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
[1] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
)
Stacking
[Le champ[prenom] doit avoir une longueur comprise entre 3 et 30] - cntStack[3]
Array ( [0] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
[1] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
[2] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
)
Stacking
[Le champ[prenom] doit avoir une longueur comprise entre 3 et 30] - cntStack[4]
Array ( [0] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
[1] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
[2] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
[3] => Le champ[prenom] doit avoir une longueur comprise entre 3 et 30
)
Stacking
[Le champ[nom] doit avoir une longueur comprise entre 3 et 30] - cntStack[3]
Array ( [0] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
[1] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
[2] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
)
Stacking
[Le champ[nom] doit avoir une longueur comprise entre 3 et 30] - cntStack[4]
Array ( [0] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
[1] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
[2] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30
[3] => Le champ[nom] doit avoir une longueur comprise entre 3 et 30 |
En conclusion, il semblerait que j'insère plusieurs fois le même msg, je fais une remise à zero (raz) à chaque champ et surement à la fin puisque je n'ai plus rien à afficher.....
Je vais laisser cela murir....:calim2:
Class et syntaxe & errmsg incompris !
Madfrix
Je suis debout depuis 4 h.....
Je parsème mon code de user_error afin de voir où l'indice cntStack est raz.
Pour l'instant je cherche tjs.
Voici le log à cet instant:
Code:
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
| [27-May-2010 07:41:40] PHP Notice: Start of Constructor[] in F:\WebSites\test\checkform.php on line 559
[27-May-2010 07:41:40] PHP Notice: emptyStack[0] in F:\WebSites\test\checkform.php on line 610
[27-May-2010 07:41:40] PHP Notice: Start of Validate cntStack[0] in F:\WebSites\test\checkform.php on line 638
[27-May-2010 07:41:40] PHP Notice: Validating field[0] cntStack[0] in F:\WebSites\test\checkform.php on line 642
[27-May-2010 07:41:40] PHP Notice: Start of field validation cntStack[] in F:\WebSites\test\checkform.php on line 435
[27-May-2010 07:41:40] PHP Notice: TEXT Validating CHKRANGE[xx]-[3]-[30] in F:\WebSites\test\checkform.php on line 444
[27-May-2010 07:41:40] PHP Notice: Validating field[1] cntStack[0] in F:\WebSites\test\checkform.php on line 642
[27-May-2010 07:41:40] PHP Notice: Start of field validation cntStack[] in F:\WebSites\test\checkform.php on line 435
[27-May-2010 07:41:40] PHP Notice: TEXT Validating CHKRANGE[xx]-[3]-[30] in F:\WebSites\test\checkform.php on line 444
[27-May-2010 07:41:40] PHP Notice: End of Validate cntStack[0] in F:\WebSites\test\checkform.php on line 647
[27-May-2010 07:41:40] PHP Notice: End of Constructor[0] in F:\WebSites\test\checkform.php on line 579
[27-May-2010 07:41:40] PHP Notice: POST SUBMIT CATCHED in F:\WebSites\test\checkform.php on line 727
[27-May-2010 07:41:40] PHP Notice: Start of Validate cntStack[0] in F:\WebSites\test\checkform.php on line 638
[27-May-2010 07:41:40] PHP Notice: Validating field[0] cntStack[0] in F:\WebSites\test\checkform.php on line 642
[27-May-2010 07:41:40] PHP Notice: Start of field validation cntStack[1] in F:\WebSites\test\checkform.php on line 435
[27-May-2010 07:41:40] PHP Notice: TEXT Validating CHKRANGE[xx]-[3]-[30] in F:\WebSites\test\checkform.php on line 444
[27-May-2010 07:41:40] PHP Notice: Validating field[1] cntStack[0] in F:\WebSites\test\checkform.php on line 642
[27-May-2010 07:41:40] PHP Notice: Start of field validation cntStack[1] in F:\WebSites\test\checkform.php on line 435
[27-May-2010 07:41:40] PHP Notice: TEXT Validating CHKRANGE[xx]-[3]-[30] in F:\WebSites\test\checkform.php on line 444
[27-May-2010 07:41:40] PHP Notice: End of Validate cntStack[0] in F:\WebSites\test\checkform.php on line 647
[27-May-2010 07:41:40] PHP Notice: getStackError[0] in F:\WebSites\test\checkform.php on line 592 |
Comme tu vois, je sème bcp mais je n'ai pas encore récolté...
Si tu veux la source pour que nous travaillons sur la même base, je veux bien te la refiler.
J'attends un signe de vie de ta part...:D