-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplugin_valid.php
More file actions
120 lines (103 loc) · 2.7 KB
/
plugin_valid.php
File metadata and controls
120 lines (103 loc) · 2.7 KB
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
<?php
/*
This file is part of Mkframework.
Mkframework is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License.
Mkframework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* plugin_check classe pour verifier un lot de valeurs (verification de formulaire par exemple)
* @author Mika
* @link http://mkf.mkdevs.com/
*/
class plugin_valid{
private $bCheck;
private $tPost;
private $tCheck;
private $oCheck;
/**
* constructeur
* @access public
* @param array tableau a verifier ($_POST,tableau de la row...)
*/
public function __construct($tPost){
$this->tPost=$tPost;
$sClass=_root::getConfigVar('check.class','plugin_check');
$this->oCheck=new $sClass;
$this->bCheck=true;
}
/**
* verifie si le champ existe dans le tableau en memoire
* @access public
* @param string $sName nom du champ
* @return bool retourne true/false selon
*/
public function exist($sName){
if(isset($this->tPost[$sName])){
return true;
}
$this->ko('exist',$sName);
return false;
}
/**
* retourne la valeur $sName du tableau en memoire
* @access public
* @param string $sName nom du champ
* @return undefined retourne la valeur du champ
*/
public function getValue($sName){
if(!isset($this->tPost[$sName])){
return null;
}
return $this->tPost[$sName];
}
/**
* appel magique d'une methode de l'objet utilise pour le check
* @access public
*/
public function __call($sMethod,$tParam=null){
$sField='';
if($tParam==null){
$bCheck=call_user_func(array($this->oCheck,$sMethod));
}else{
$sField=$tParam[0];
$tParam[0]=$this->getValue($tParam[0]);
$bCheck=call_user_func_array(array($this->oCheck,$sMethod),$tParam);
}
if($bCheck){
return $this->ok();
}
$sKoMessage=$this->oCheck->getLastErrorMsg();
return $this->ko($sKoMessage,$sField);
}
/**
* verifie si tout est ok
* @access public
* @return bool retourne true/false selon
*/
public function isValid(){
return $this->bCheck;
}
/**
* retourne le tableau d'erreur
* @access public
* @return array tableau d'erreur
*/
public function getListError(){
return $this->tCheck;
}
public function ko($sCheck,$sField=null){
$this->bCheck=false;
$this->tCheck[ $sField ][]= $sCheck;
return false;
}
private function ok(){
return true;
}
}