From 699631b63caf4717d3e12d6fab25e5640ad61f99 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 26 Aug 2020 11:45:59 +0200 Subject: [PATCH] LsformRule: provide reference to LSformElement instead of copied value --- src/includes/class/class.LSformRule.php | 2 +- .../class/class.LSformRule_LSformElement_select_validValue.php | 2 +- src/includes/class/class.LSformRule_alphanumeric.php | 2 +- src/includes/class/class.LSformRule_callable.php | 2 +- src/includes/class/class.LSformRule_compare.php | 2 +- src/includes/class/class.LSformRule_date.php | 2 +- src/includes/class/class.LSformRule_differentPassword.php | 2 +- src/includes/class/class.LSformRule_email.php | 2 +- src/includes/class/class.LSformRule_filesize.php | 2 +- src/includes/class/class.LSformRule_imagefile.php | 2 +- src/includes/class/class.LSformRule_imagesize.php | 2 +- src/includes/class/class.LSformRule_inarray.php | 2 +- src/includes/class/class.LSformRule_integer.php | 2 +- src/includes/class/class.LSformRule_lettersonly.php | 2 +- src/includes/class/class.LSformRule_maxlength.php | 2 +- src/includes/class/class.LSformRule_mimetype.php | 2 +- src/includes/class/class.LSformRule_minlength.php | 2 +- src/includes/class/class.LSformRule_nonzero.php | 2 +- src/includes/class/class.LSformRule_nopunctuation.php | 2 +- src/includes/class/class.LSformRule_numeric.php | 2 +- src/includes/class/class.LSformRule_password.php | 2 +- src/includes/class/class.LSformRule_rangelength.php | 2 +- src/includes/class/class.LSformRule_regex.php | 2 +- src/includes/class/class.LSformRule_required.php | 2 +- src/includes/class/class.LSformRule_ssh_pub_key.php | 2 +- src/includes/class/class.LSformRule_telephonenumber.php | 2 +- 26 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/includes/class/class.LSformRule.php b/src/includes/class/class.LSformRule.php index a091578a..4d09fa8c 100644 --- a/src/includes/class/class.LSformRule.php +++ b/src/includes/class/class.LSformRule.php @@ -38,7 +38,7 @@ class LSformRule extends LSlog_staticLoggerClass { * * @return boolean True si les données sont valide, False sinon. */ - public static function validate($value,$options=NULL,$formElement) { + public static function validate($value, $options=array(), &$formElement) { return true; } diff --git a/src/includes/class/class.LSformRule_LSformElement_select_validValue.php b/src/includes/class/class.LSformRule_LSformElement_select_validValue.php index 8b1c8a25..16063b10 100644 --- a/src/includes/class/class.LSformRule_LSformElement_select_validValue.php +++ b/src/includes/class/class.LSformRule_LSformElement_select_validValue.php @@ -36,7 +36,7 @@ class LSformRule_LSformElement_select_validValue extends LSformRule { * * @return boolean true if the value is valide, false if not */ - public static function validate($value,$option,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $ret = $formElement -> isValidValue($value); if ($ret===False) return False; return True; diff --git a/src/includes/class/class.LSformRule_alphanumeric.php b/src/includes/class/class.LSformRule_alphanumeric.php index d4d318b6..e7d68e99 100644 --- a/src/includes/class/class.LSformRule_alphanumeric.php +++ b/src/includes/class/class.LSformRule_alphanumeric.php @@ -37,7 +37,7 @@ class LSformRule_alphanumeric extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { if (LSconfig :: get('params.withAccents', false, 'bool', $options)) { $regex = '/(*UTF8)^[0-9\p{L}]+$/'; diff --git a/src/includes/class/class.LSformRule_callable.php b/src/includes/class/class.LSformRule_callable.php index e37dd6b3..b7a676cd 100644 --- a/src/includes/class/class.LSformRule_callable.php +++ b/src/includes/class/class.LSformRule_callable.php @@ -41,7 +41,7 @@ class LSformRule_callable extends LSformRule { * * @return boolean true if the value is valid, false otherwise */ - public static function validate($value,$options,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $callable = LSconfig :: get('params.callable', null, null, $options); if (is_callable($callable)) return call_user_func_array( diff --git a/src/includes/class/class.LSformRule_compare.php b/src/includes/class/class.LSformRule_compare.php index 80d11036..135aeb42 100644 --- a/src/includes/class/class.LSformRule_compare.php +++ b/src/includes/class/class.LSformRule_compare.php @@ -67,7 +67,7 @@ class LSformRule_compare extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($values,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { $operator = LSconfig :: get('params.operator', null, 'string', $options); if (!$operator) { LSerror :: addErrorCode('LSformRule_01',array('type' => 'compare', 'param' => 'operator')); diff --git a/src/includes/class/class.LSformRule_date.php b/src/includes/class/class.LSformRule_date.php index 4caa1463..5ec8f0a3 100644 --- a/src/includes/class/class.LSformRule_date.php +++ b/src/includes/class/class.LSformRule_date.php @@ -37,7 +37,7 @@ class LSformRule_date extends LSformRule { * * @return boolean True si les données sont valide, False sinon. */ - public static function validate($value,$options=NULL,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $format = LSconfig :: get('params.format', null, 'string', $options); if (is_null($format)) { LSerror :: addErrorCode('LSformRule_date_01'); diff --git a/src/includes/class/class.LSformRule_differentPassword.php b/src/includes/class/class.LSformRule_differentPassword.php index 37ec05b9..c7f5e891 100644 --- a/src/includes/class/class.LSformRule_differentPassword.php +++ b/src/includes/class/class.LSformRule_differentPassword.php @@ -37,7 +37,7 @@ class LSformRule_differentPassword extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate($value, $options, $formElement) { + public static function validate($value, $options=array(), &$formElement) { $otherPasswordAttributes = LSconfig :: get('params.otherPasswordAttributes', null, null, $options); if (!is_null($otherPasswordAttributes)) { // Make sure otherPasswordAttributes is an array diff --git a/src/includes/class/class.LSformRule_email.php b/src/includes/class/class.LSformRule_email.php index 2607fc0e..fe9fd1fb 100644 --- a/src/includes/class/class.LSformRule_email.php +++ b/src/includes/class/class.LSformRule_email.php @@ -37,7 +37,7 @@ class LSformRule_email extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate($value,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { return checkEmail( $value, LSconfig :: get('params.domain', null, null, $options), diff --git a/src/includes/class/class.LSformRule_filesize.php b/src/includes/class/class.LSformRule_filesize.php index cdcce2cb..cdac9cc2 100644 --- a/src/includes/class/class.LSformRule_filesize.php +++ b/src/includes/class/class.LSformRule_filesize.php @@ -38,7 +38,7 @@ class LSformRule_filesize extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options,$formElement) { + public static function validate($value, $options=array(), &$formElement) { // According to PHP doc, strlen() returns the number of bytes rather // than the number of characters in a string. // See: https://www.php.net/manual/en/function.strlen.php diff --git a/src/includes/class/class.LSformRule_imagefile.php b/src/includes/class/class.LSformRule_imagefile.php index 10b1055a..15ae3a1f 100644 --- a/src/includes/class/class.LSformRule_imagefile.php +++ b/src/includes/class/class.LSformRule_imagefile.php @@ -40,7 +40,7 @@ class LSformRule_imagefile extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $file = LSsession :: getTmpFile($value); $mimetype = mime_content_type($file); diff --git a/src/includes/class/class.LSformRule_imagesize.php b/src/includes/class/class.LSformRule_imagesize.php index f22404e3..5d0c21a1 100644 --- a/src/includes/class/class.LSformRule_imagesize.php +++ b/src/includes/class/class.LSformRule_imagesize.php @@ -40,7 +40,7 @@ class LSformRule_imagesize extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $file = LSsession :: getTmpFile($value); list($width, $height, $type, $attr) = getimagesize($file); LSdebug("LSformRule_imagesize :: validate() : image size is $width x $height, type=$type, attr='$attr'"); diff --git a/src/includes/class/class.LSformRule_inarray.php b/src/includes/class/class.LSformRule_inarray.php index d249a968..3a70def1 100644 --- a/src/includes/class/class.LSformRule_inarray.php +++ b/src/includes/class/class.LSformRule_inarray.php @@ -37,7 +37,7 @@ class LSformRule_inarray extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate($value,$option,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $possible_values = LSconfig :: get('params.possible_values', null, null, $options); if (!is_array($possible_values)) { LSerror :: addErrorCode('LSformRule_inarray_01'); diff --git a/src/includes/class/class.LSformRule_integer.php b/src/includes/class/class.LSformRule_integer.php index e6e442db..dcd6cd0f 100644 --- a/src/includes/class/class.LSformRule_integer.php +++ b/src/includes/class/class.LSformRule_integer.php @@ -40,7 +40,7 @@ class LSformRule_integer extends LSformRule{ * * @return boolean true if the value is valided, false otherwise */ - public static function validate ($value,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { $max = LSconfig :: get('params.max', null, 'int', $options); if(is_int($max) && $max != 0 && $value > $max) { self :: log_debug("value is too higth ($value > $max)"); diff --git a/src/includes/class/class.LSformRule_lettersonly.php b/src/includes/class/class.LSformRule_lettersonly.php index 06b959de..43c46498 100644 --- a/src/includes/class/class.LSformRule_lettersonly.php +++ b/src/includes/class/class.LSformRule_lettersonly.php @@ -36,7 +36,7 @@ class LSformRule_lettersonly extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { $regex = '/^[a-zA-Z]+$/'; LSsession :: loadLSclass('LSformRule_regex'); return LSformRule_regex :: validate($value,$regex,$formElement); diff --git a/src/includes/class/class.LSformRule_maxlength.php b/src/includes/class/class.LSformRule_maxlength.php index c5764d3d..07ef2f10 100644 --- a/src/includes/class/class.LSformRule_maxlength.php +++ b/src/includes/class/class.LSformRule_maxlength.php @@ -37,7 +37,7 @@ class LSformRule_maxlength extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $limit = LSconfig :: get('params.limit', null, 'int', $options); if(is_null($limit)) { LSerror :: addErrorCode('LSformRule_01',array('type' => 'maxlength', 'param' => 'limit')); diff --git a/src/includes/class/class.LSformRule_mimetype.php b/src/includes/class/class.LSformRule_mimetype.php index 8acdf784..855682e3 100644 --- a/src/includes/class/class.LSformRule_mimetype.php +++ b/src/includes/class/class.LSformRule_mimetype.php @@ -38,7 +38,7 @@ class LSformRule_mimetype extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $file = LSsession :: getTmpFile($value); $real_mimetype = mime_content_type($file); diff --git a/src/includes/class/class.LSformRule_minlength.php b/src/includes/class/class.LSformRule_minlength.php index 1096b776..90191985 100644 --- a/src/includes/class/class.LSformRule_minlength.php +++ b/src/includes/class/class.LSformRule_minlength.php @@ -37,7 +37,7 @@ class LSformRule_minlength extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $limit = LSconfig :: get('params.limit', null, 'int', $options); if(is_null($limit)) { LSerror :: addErrorCode('LSformRule_01',array('type' => 'minlength', 'param' => 'limit')); diff --git a/src/includes/class/class.LSformRule_nonzero.php b/src/includes/class/class.LSformRule_nonzero.php index aabbcc42..590440a5 100644 --- a/src/includes/class/class.LSformRule_nonzero.php +++ b/src/includes/class/class.LSformRule_nonzero.php @@ -36,7 +36,7 @@ class LSformRule_nonzero extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options,$formElement) { + public static function validate($value, $options=array(), &$formElement) { $regex = '/^-?[1-9][0-9]*/'; LSsession :: loadLSclass('LSformRule_regex'); return LSformRule_regex :: validate($value,$regex,$formElement); diff --git a/src/includes/class/class.LSformRule_nopunctuation.php b/src/includes/class/class.LSformRule_nopunctuation.php index 5f4bf365..d107865d 100644 --- a/src/includes/class/class.LSformRule_nopunctuation.php +++ b/src/includes/class/class.LSformRule_nopunctuation.php @@ -36,7 +36,7 @@ class LSformRule_nopunctuation extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { $regex = '/^[^().\/\*\^\?#!@$%+=,\"\'><~\[\]{}]+$/'; LSsession :: loadLSclass('LSformRule_regex'); return LSformRule_regex :: validate($value,$regex,$formElement); diff --git a/src/includes/class/class.LSformRule_numeric.php b/src/includes/class/class.LSformRule_numeric.php index c81c270d..e8cf51aa 100644 --- a/src/includes/class/class.LSformRule_numeric.php +++ b/src/includes/class/class.LSformRule_numeric.php @@ -36,7 +36,7 @@ class LSformRule_numeric extends LSformRule{ * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { $regex = '/(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/'; LSsession :: loadLSclass('LSformRule_regex'); return LSformRule_regex :: validate($value,$regex,$formElement); diff --git a/src/includes/class/class.LSformRule_password.php b/src/includes/class/class.LSformRule_password.php index e4b925cf..eacf8082 100644 --- a/src/includes/class/class.LSformRule_password.php +++ b/src/includes/class/class.LSformRule_password.php @@ -43,7 +43,7 @@ class LSformRule_password extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { $maxLength = LSconfig :: get('params.maxLength', null, 'int', $options); if(!is_null($maxLength) && $maxLength != 0 && strlen($value) > $maxLength) { self :: log_debug("password is too long (".strlen($value)." > $maxLength)"); diff --git a/src/includes/class/class.LSformRule_rangelength.php b/src/includes/class/class.LSformRule_rangelength.php index fe67b007..052ad201 100644 --- a/src/includes/class/class.LSformRule_rangelength.php +++ b/src/includes/class/class.LSformRule_rangelength.php @@ -38,7 +38,7 @@ class LSformRule_rangelength extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { $limits = LSconfig :: get('params.limits', null, null, $options); if(!is_array($limits) || count($limits) != 2) { LSerror :: addErrorCode('LSformRule_01',array('type' => 'rangelength', 'param' => 'limits')); diff --git a/src/includes/class/class.LSformRule_regex.php b/src/includes/class/class.LSformRule_regex.php index 31431714..7c8508a1 100644 --- a/src/includes/class/class.LSformRule_regex.php +++ b/src/includes/class/class.LSformRule_regex.php @@ -37,7 +37,7 @@ class LSformRule_regex extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate($value, $options, $formElement) { + public static function validate($value, $options=array(), &$formElement) { if (is_array($options)) { $regex = LSconfig :: get('params.regex', null, 'string', $options); if (!is_string($regex)) { diff --git a/src/includes/class/class.LSformRule_required.php b/src/includes/class/class.LSformRule_required.php index 2799cac0..b335f446 100644 --- a/src/includes/class/class.LSformRule_required.php +++ b/src/includes/class/class.LSformRule_required.php @@ -36,7 +36,7 @@ class LSformRule_required extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate ($value,$options=NULL,$formElement) { + public static function validate($value, $options=array(), &$formElement) { return ((string)$value != ''); } diff --git a/src/includes/class/class.LSformRule_ssh_pub_key.php b/src/includes/class/class.LSformRule_ssh_pub_key.php index fd1bc3a5..d822e1f1 100644 --- a/src/includes/class/class.LSformRule_ssh_pub_key.php +++ b/src/includes/class/class.LSformRule_ssh_pub_key.php @@ -36,7 +36,7 @@ class LSformRule_ssh_pub_key extends LSformRule { * * @return boolean true if the value is valide, false if not */ - public static function validate($value,$options,$formElement) { + public static function validate($value, $options=array(), &$formElement) { if (preg_match('/^(ssh-[a-z0-9]+) +([^ ]+) +(.*)$/', $value, $m)) { $data=@base64_decode($m[2]); if (is_string($data)) diff --git a/src/includes/class/class.LSformRule_telephonenumber.php b/src/includes/class/class.LSformRule_telephonenumber.php index e91935b9..b7832b5b 100644 --- a/src/includes/class/class.LSformRule_telephonenumber.php +++ b/src/includes/class/class.LSformRule_telephonenumber.php @@ -36,7 +36,7 @@ class LSformRule_telephonenumber extends LSformRule { * * @return boolean true si la valeur est valide, false sinon */ - public static function validate($value,$options=array(),$formElement) { + public static function validate($value, $options=array(), &$formElement) { $regex = '/^(01|02|03|04|05|06|08|09)[0-9]{8}$/'; LSsession :: loadLSclass('LSformRule_regex'); return LSformRule_regex :: validate($value,$regex,$formElement);