2007-11-15 19:07:24 +01:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2020-05-08 15:50:07 +02:00
|
|
|
LSsession :: loadLSclass('LSlog_staticLoggerClass');
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Base d'une règle de validation de données
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
2020-05-08 15:50:07 +02:00
|
|
|
class LSformRule extends LSlog_staticLoggerClass {
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2020-12-21 14:53:36 +01:00
|
|
|
// Validate values one by one or all together
|
|
|
|
public const validate_one_by_one = True;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate form element values with specified rule
|
|
|
|
*
|
|
|
|
* @param mixed $rule_name The LSformRule name
|
|
|
|
* @param mixed $value The values to validate
|
|
|
|
* @param array $options Validation options
|
|
|
|
* @param object $formElement The attached LSformElement object
|
|
|
|
*
|
|
|
|
* @return boolean True if value is valid, False otherwise
|
|
|
|
*/
|
|
|
|
public static function validate_values($rule_name, $values, $options=array(), &$formElement) {
|
|
|
|
// Compute PHP class name of the rule
|
|
|
|
$rule_class = "LSformRule_".$rule_name;
|
|
|
|
|
|
|
|
// Load PHP class (with error if fail)
|
|
|
|
if (!LSsession :: loadLSclass($rule_class)) {
|
|
|
|
LSerror :: addErrorCode('LSformRule_02', $rule_name);
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $rule_class :: validate_one_by_one)
|
|
|
|
return $rule_class :: validate($values, $options, $formElement);
|
|
|
|
|
|
|
|
foreach ($values as $value) {
|
|
|
|
if (!$rule_class :: validate($value, $options, $formElement))
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate form element value
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2020-12-21 14:53:36 +01:00
|
|
|
* @param mixed $value The value to validate
|
|
|
|
* @param array $options Validation options
|
|
|
|
* @param object $formElement The attached LSformElement object
|
2008-02-26 18:40:05 +01:00
|
|
|
*
|
2020-12-21 14:53:36 +01:00
|
|
|
* @return boolean True if value is valid, False otherwise
|
2008-02-26 18:40:05 +01:00
|
|
|
*/
|
2020-08-26 11:45:59 +02:00
|
|
|
public static function validate($value, $options=array(), &$formElement) {
|
2020-12-21 14:53:36 +01:00
|
|
|
return false;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
2019-03-11 22:42:20 +01:00
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
2009-01-02 17:00:25 +01:00
|
|
|
/**
|
|
|
|
* Error Codes
|
|
|
|
**/
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('LSformRule_01',
|
2020-12-21 14:53:36 +01:00
|
|
|
___("LSformRule_%{type}: Parameter %{param} is not found.")
|
|
|
|
);
|
|
|
|
LSerror :: defineError('LSformRule_02',
|
|
|
|
___("LSformRule: Unknown rule type %{type}.")
|
2009-01-02 17:00:25 +01:00
|
|
|
);
|