Review LSformRules parameters usage and doc

This commit is contained in:
Benjamin Renard 2017-08-22 15:39:38 +02:00
parent e0641191b7
commit 02eb2557aa
22 changed files with 24 additions and 57 deletions

View file

@ -31,7 +31,8 @@ class LSformRule_alphanumeric extends LSformRule {
* Vérification de la valeur. * Vérification de la valeur.
* *
* @param string $value Value à vérifier * @param string $value Value à vérifier
* @param array $options Options de validation (inutile ici) * @param array $options Options de validation :
* - $options['params']['withAccents'] : set if accents is allowed
* @param object $formElement L'objet formElement attaché * @param object $formElement L'objet formElement attaché
* *
* @return boolean true si la valeur est valide, false sinon * @return boolean true si la valeur est valide, false sinon
@ -51,5 +52,3 @@ class LSformRule_alphanumeric extends LSformRule {
} }
} }
?>

View file

@ -32,7 +32,7 @@ class LSformRule_callable extends LSformRule {
* *
* @param mixed $value The value to check * @param mixed $value The value to check
* @param array $options Validation option * @param array $options Validation option
* - callable : the function use to check the value * - $options['params']['callable'] : the function use to check the value
* *
* The callable object will be run to check the value. The given parameters are the * The callable object will be run to check the value. The given parameters are the
* same of this method. * same of this method.
@ -41,9 +41,9 @@ class LSformRule_callable extends LSformRule {
* *
* @return boolean true if the value is valid, false otherwise * @return boolean true if the value is valid, false otherwise
*/ */
function validate($value,$option,$formElement) { function validate($value,$options,$formElement) {
if (is_callable($option['callable'])) { if (is_callable($options['params']['callable'])) {
return call_user_func_array($option['callable'],array($value,$option,&$formElement)); return call_user_func_array($options['params']['callable'],array($value,$options['params'],&$formElement));
} }
else { else {
LSerror :: addErrorCode('LSformRule_callable_01'); LSerror :: addErrorCode('LSformRule_callable_01');
@ -59,5 +59,3 @@ class LSformRule_callable extends LSformRule {
LSerror :: defineError('LSformRule_callable_01', LSerror :: defineError('LSformRule_callable_01',
_("LSformRule_callable : The given callable option is not callable") _("LSformRule_callable : The given callable option is not callable")
); );
?>

View file

@ -83,5 +83,3 @@ class LSformRule_compare extends LSformRule {
} }
} }
?>

View file

@ -32,16 +32,16 @@ class LSformRule_date extends LSformRule {
* *
* @param mixed $value Données à valider * @param mixed $value Données à valider
* @param array $options Options de validation * @param array $options Options de validation
* format: le format de la date * $options['params']['format']: le format de la date
* @param object $formElement L'objet formElement attaché * @param object $formElement L'objet formElement attaché
* *
* @return boolean True si les données sont valide, False sinon. * @return boolean True si les données sont valide, False sinon.
*/ */
function validate($value,$options=NULL,$formElement) { function validate($value,$options=NULL,$formElement) {
if (!isset($options['format'])) { if (!isset($options['params']['format'])) {
return; return;
} }
$date = strptime($value,$options['format']); $date = strptime($value,$options['params']['format']);
if(is_array($date)) { if(is_array($date)) {
$res = mktime($date['tm_hour'],$date['tm_min'],$date['tm_sec'],$date['tm_mon']+1,$date['tm_mday'],$date['tm_year']+1900); $res = mktime($date['tm_hour'],$date['tm_min'],$date['tm_sec'],$date['tm_mon']+1,$date['tm_mday'],$date['tm_year']+1900);
if ((is_int($res)) && ($res != -1) && ($res !== False)) { if ((is_int($res)) && ($res != -1) && ($res !== False)) {
@ -51,5 +51,3 @@ class LSformRule_date extends LSformRule {
return; return;
} }
} }
?>

View file

@ -32,15 +32,13 @@ class LSformRule_email extends LSformRule {
* *
* @param string $value Valeur à vérifier * @param string $value Valeur à vérifier
* @param array $options Options de validation : * @param array $options Options de validation :
* - Check domain : $option['params']['checkDomain'] * - Check domain : $options['params']['checkDomain']
* @param object $formElement L'objet formElement attaché * @param object $formElement L'objet formElement attaché
* *
* @return boolean true si la valeur est valide, false sinon * @return boolean true si la valeur est valide, false sinon
*/ */
function validate($value,$option=array(),$formElement) { function validate($value,$options=array(),$formElement) {
return checkEmail($value,$option['params']['domain'],$option['params']['checkDomain']); return checkEmail($value,$options['params']['domain'],$options['params']['checkDomain']);
} }
} }
?>

View file

@ -60,4 +60,3 @@ class LSformRule_filesize extends LSformRule {
} }
?>

View file

@ -58,4 +58,3 @@ class LSformRule_imagefile extends LSformRule {
} }
?>

View file

@ -70,4 +70,3 @@ class LSformRule_imagesize extends LSformRule {
} }
?>

View file

@ -56,4 +56,3 @@ LSerror :: defineError('LSformRule_inarray_01',
_("LSformRule_inarray : Possible values has not been configured to validate data.") _("LSformRule_inarray : Possible values has not been configured to validate data.")
); );
?>

View file

@ -32,6 +32,10 @@ class LSformRule_integer extends LSformRule{
* *
* @param string $values The value * @param string $values The value
* @param array $options Validation options * @param array $options Validation options
* - Maximum value : $options['params']['max']
* - Minimum value : $options['params']['min']
* - Allow only negative value : $options['params']['negative']
* - Allow only positive value : $options['params']['positive']
* @param object $formElement The formElement object * @param object $formElement The formElement object
* *
* @return boolean true if the value is valided, false otherwise * @return boolean true if the value is valided, false otherwise
@ -58,4 +62,3 @@ class LSformRule_integer extends LSformRule{
} }
?>

View file

@ -43,5 +43,3 @@ class LSformRule_lettersonly extends LSformRule {
} }
} }
?>

View file

@ -46,5 +46,3 @@ class LSformRule_maxlength extends LSformRule {
} }
} }
?>

View file

@ -66,5 +66,3 @@ class LSformRule_mimetype extends LSformRule {
} }
} }
?>

View file

@ -46,5 +46,3 @@ class LSformRule_minlength extends LSformRule {
} }
} }
?>

View file

@ -43,5 +43,3 @@ class LSformRule_nonzero extends LSformRule {
} }
} }
?>

View file

@ -43,5 +43,3 @@ class LSformRule_nopunctuation extends LSformRule {
} }
} }
?>

View file

@ -43,5 +43,3 @@ class LSformRule_numeric extends LSformRule{
} }
} }
?>

View file

@ -97,4 +97,3 @@ class LSformRule_password extends LSformRule {
LSerror :: defineError('LSformRule_password_01', LSerror :: defineError('LSformRule_password_01',
_("LSformRule_password : Invalid regex configured : %{regex}. You must use PCRE (begining by '/' caracter).") _("LSformRule_password : Invalid regex configured : %{regex}. You must use PCRE (begining by '/' caracter).")
); );
?>

View file

@ -48,5 +48,3 @@ class LSformRule_rangelength extends LSformRule {
} }
} }
?>

View file

@ -32,15 +32,15 @@ class LSformRule_regex extends LSformRule {
* *
* @param string $values Valeur à vérifier * @param string $values Valeur à vérifier
* @param array $options Options de validation : * @param array $options Options de validation :
* - Regex : $option['params']['regex'] ou $option * - Regex : $options['params']['regex'] ou $options
* @param object $formElement L'objet formElement attaché * @param object $formElement L'objet formElement attaché
* *
* @return boolean true si la valeur est valide, false sinon * @return boolean true si la valeur est valide, false sinon
*/ */
function validate($value,$option,$formElement) { function validate($value,$options,$formElement) {
if (is_array($option)) { if (is_array($options)) {
if (isset($option['params']['regex'])) { if (isset($options['params']['regex'])) {
$regex=$option['params']['regex']; $regex=$options['params']['regex'];
} }
else { else {
LSerror :: addErrorCode('LSformRule_regex_01'); LSerror :: addErrorCode('LSformRule_regex_01');
@ -48,7 +48,7 @@ class LSformRule_regex extends LSformRule {
} }
} }
else { else {
$regex=$option; $regex=$options;
} }
if (!preg_match($regex, $value)) { if (!preg_match($regex, $value)) {
return false; return false;
@ -64,5 +64,3 @@ class LSformRule_regex extends LSformRule {
LSerror :: defineError('LSformRule_regex_01', LSerror :: defineError('LSformRule_regex_01',
_("LSformRule_regex : Regex has not been configured to validate data.") _("LSformRule_regex : Regex has not been configured to validate data.")
); );
?>

View file

@ -36,10 +36,8 @@ class LSformRule_required extends LSformRule {
* *
* @return boolean true si la valeur est valide, false sinon * @return boolean true si la valeur est valide, false sinon
*/ */
function validate ($value,$option=NULL,$formElement) { function validate ($value,$options=NULL,$formElement) {
return ((string)$value != ''); return ((string)$value != '');
} }
} }
?>

View file

@ -36,12 +36,10 @@ class LSformRule_telephonenumber extends LSformRule {
* *
* @return boolean true si la valeur est valide, false sinon * @return boolean true si la valeur est valide, false sinon
*/ */
function validate($value,$option=array(),$formElement) { function validate($value,$options=array(),$formElement) {
$regex = '/^(01|02|03|04|05|06|08|09)[0-9]{8}$/'; $regex = '/^(01|02|03|04|05|06|08|09)[0-9]{8}$/';
LSsession :: loadLSclass('LSformRule_regex'); LSsession :: loadLSclass('LSformRule_regex');
return LSformRule_regex :: validate($value,$regex,$formElement); return LSformRule_regex :: validate($value,$regex,$formElement);
} }
} }
?>