LsformRule: provide reference to LSformElement instead of copied value

This commit is contained in:
Benjamin Renard 2020-08-26 11:45:59 +02:00
parent 5975d36a1c
commit 699631b63c
26 changed files with 26 additions and 26 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -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}]+$/';

View file

@ -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(

View file

@ -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'));

View file

@ -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');

View file

@ -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

View file

@ -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),

View file

@ -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

View file

@ -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);

View file

@ -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'");

View file

@ -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');

View file

@ -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)");

View file

@ -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);

View file

@ -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'));

View file

@ -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);

View file

@ -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'));

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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)");

View file

@ -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'));

View file

@ -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)) {

View file

@ -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 != '');
}

View file

@ -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))

View file

@ -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);