mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-12-23 00:43:48 +01:00
LSformRules : clean code by using LSconfig :: get() helper
This commit is contained in:
parent
f32fb31d6e
commit
c4687bdfdb
25 changed files with 184 additions and 187 deletions
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_LSformElement_select_validValue extends LSformRule {
|
class LSformRule_LSformElement_select_validValue extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate value
|
* Validate value
|
||||||
*
|
*
|
||||||
|
@ -35,7 +35,7 @@ class LSformRule_LSformElement_select_validValue extends LSformRule {
|
||||||
* @param object $formElement The related formElement object
|
* @param object $formElement The related formElement object
|
||||||
*
|
*
|
||||||
* @return boolean true if the value is valide, false if not
|
* @return boolean true if the value is valide, false if not
|
||||||
*/
|
*/
|
||||||
public static function validate($value,$option,$formElement) {
|
public static function validate($value,$option,$formElement) {
|
||||||
$ret = $formElement -> isValidValue($value);
|
$ret = $formElement -> isValidValue($value);
|
||||||
if ($ret===False) return False;
|
if ($ret===False) return False;
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_alphanumeric extends LSformRule {
|
class LSformRule_alphanumeric extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
|
@ -39,8 +39,7 @@ class LSformRule_alphanumeric extends LSformRule {
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options=array(),$formElement) {
|
public static function validate ($value,$options=array(),$formElement) {
|
||||||
|
|
||||||
|
if (LSconfig :: get('params.withAccents', false, 'bool', $options)) {
|
||||||
if (isset($options['params']['withAccents']) && $options['params']['withAccents'] == true){
|
|
||||||
$regex = '/(*UTF8)^[0-9\p{L}]+$/';
|
$regex = '/(*UTF8)^[0-9\p{L}]+$/';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -50,6 +49,6 @@ class LSformRule_alphanumeric extends LSformRule {
|
||||||
return LSformRule_regex :: validate($value,$regex,$formElement);
|
return LSformRule_regex :: validate($value,$regex,$formElement);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_callable extends LSformRule {
|
class LSformRule_callable extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the value using the callable object
|
* Check the value using the callable object
|
||||||
*
|
*
|
||||||
|
@ -40,15 +40,21 @@ class LSformRule_callable extends LSformRule {
|
||||||
* @param object $formElement The LSformElement object
|
* @param object $formElement The LSformElement object
|
||||||
*
|
*
|
||||||
* @return boolean true if the value is valid, false otherwise
|
* @return boolean true if the value is valid, false otherwise
|
||||||
*/
|
*/
|
||||||
public static function validate($value,$options,$formElement) {
|
public static function validate($value,$options,$formElement) {
|
||||||
if (is_callable($options['params']['callable'])) {
|
$callable = LSconfig :: get('params.callable', null, null, $options);
|
||||||
return call_user_func_array($options['params']['callable'],array($value,$options['params'],&$formElement));
|
if (is_callable($callable))
|
||||||
}
|
return call_user_func_array(
|
||||||
else {
|
$callable,
|
||||||
LSerror :: addErrorCode('LSformRule_callable_01');
|
array(
|
||||||
return False;
|
$value,
|
||||||
}
|
LSconfig :: get('params', array(), null, $options),
|
||||||
|
&$formElement
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
LSerror :: addErrorCode('LSformRule_callable_01');
|
||||||
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_compare extends LSformRule {
|
class LSformRule_compare extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retourne l'operateur de comparaison.
|
* Retourne l'operateur de comparaison.
|
||||||
*
|
*
|
||||||
|
@ -61,18 +61,19 @@ class LSformRule_compare extends LSformRule {
|
||||||
* Vérification des valeurs.
|
* Vérification des valeurs.
|
||||||
*
|
*
|
||||||
* @param string $values Valeurs à vérifier
|
* @param string $values Valeurs à vérifier
|
||||||
* @param array $options Options de validation :
|
* @param array $options Options de validation :
|
||||||
* - Operateur : $options['params']['operator']
|
* - Operateur : $options['params']['operator']
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public static function validate ($values,$options=array(),$formElement) {
|
public static function validate ($values,$options=array(),$formElement) {
|
||||||
if (!isset($options['params']['operator'])) {
|
$operator = LSconfig :: get('params.operator', null, 'string', $options);
|
||||||
|
if (!$operator) {
|
||||||
LSerror :: addErrorCode('LSformRule_01',array('type' => 'compare', 'param' => 'operator'));
|
LSerror :: addErrorCode('LSformRule_01',array('type' => 'compare', 'param' => 'operator'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$operator = self :: _findOperator($options['params']['operator']);
|
$operator = self :: _findOperator($operator);
|
||||||
if ('==' != $operator && '!=' != $operator) {
|
if ('==' != $operator && '!=' != $operator) {
|
||||||
$compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
|
$compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
|
||||||
}
|
}
|
||||||
|
@ -81,6 +82,6 @@ class LSformRule_compare extends LSformRule {
|
||||||
}
|
}
|
||||||
return $compareFn($values[0], $values[1]);
|
return $compareFn($values[0], $values[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_date extends LSformRule {
|
class LSformRule_date extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation de données
|
* Validation de données
|
||||||
*
|
*
|
||||||
|
@ -38,11 +38,12 @@ class LSformRule_date extends LSformRule {
|
||||||
* @return boolean True si les données sont valide, False sinon.
|
* @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=NULL,$formElement) {
|
||||||
if (!isset($options['params']['format'])) {
|
$format = LSconfig :: get('params.format', null, 'string', $options);
|
||||||
|
if (is_null($format)) {
|
||||||
LSerror :: addErrorCode('LSformRule_date_01');
|
LSerror :: addErrorCode('LSformRule_date_01');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$date = strptime($value,$options['params']['format']);
|
$date = strptime($value, $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)) {
|
||||||
|
|
|
@ -31,17 +31,18 @@ class LSformRule_differentPassword extends LSformRule {
|
||||||
* Check the value
|
* Check the value
|
||||||
*
|
*
|
||||||
* @param string $values Value to check
|
* @param string $values Value to check
|
||||||
* @param array $options Validation options :
|
* @param array $options Validation options :
|
||||||
* - Other attribute : $options['params']['otherAttributes']
|
* - Other attribute : $options['params']['otherPasswordAttributes']
|
||||||
* @param object $formElement The linked LSformElement object
|
* @param object $formElement The linked LSformElement object
|
||||||
*
|
*
|
||||||
* @return boolean true si la valeur est valide, false sinon
|
* @return boolean true si la valeur est valide, false sinon
|
||||||
*/
|
*/
|
||||||
public static function validate($value, $options, $formElement) {
|
public static function validate($value, $options, $formElement) {
|
||||||
if (is_array($options) && isset($options['params']['otherPasswordAttributes'])) {
|
$otherPasswordAttributes = LSconfig :: get('params.otherPasswordAttributes', null, null, $options);
|
||||||
|
if (!is_null($otherPasswordAttributes)) {
|
||||||
// Make sure otherPasswordAttributes is an array
|
// Make sure otherPasswordAttributes is an array
|
||||||
if (!is_array($options['params']['otherPasswordAttributes']))
|
if (!is_array($otherPasswordAttributes))
|
||||||
$options['params']['otherPasswordAttributes'] = array($options['params']['otherPasswordAttributes']);
|
$otherPasswordAttributes = array($otherPasswordAttributes);
|
||||||
|
|
||||||
// Load LSattr_ldap_password
|
// Load LSattr_ldap_password
|
||||||
if (!LSsession :: loadLSclass("LSattr_ldap_password")) {
|
if (!LSsession :: loadLSclass("LSattr_ldap_password")) {
|
||||||
|
@ -50,7 +51,7 @@ class LSformRule_differentPassword extends LSformRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iter on otherPasswordAttributes to check password does not match
|
// Iter on otherPasswordAttributes to check password does not match
|
||||||
foreach($options['params']['otherPasswordAttributes'] as $attr) {
|
foreach($otherPasswordAttributes as $attr) {
|
||||||
// Check attribute exist
|
// Check attribute exist
|
||||||
if (!isset($formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr])) {
|
if (!isset($formElement -> attr_html -> attribute -> ldapObject -> attrs[$attr])) {
|
||||||
LSerror :: addErrorCode('LSformRule_differentPassword_03', $attr);
|
LSerror :: addErrorCode('LSformRule_differentPassword_03', $attr);
|
||||||
|
|
|
@ -26,19 +26,23 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_email extends LSformRule {
|
class LSformRule_email extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @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 : $options['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
|
||||||
*/
|
*/
|
||||||
public static function validate($value,$options=array(),$formElement) {
|
public static function validate($value,$options=array(),$formElement) {
|
||||||
return checkEmail($value,$options['params']['domain'],$options['params']['checkDomain']);
|
return checkEmail(
|
||||||
|
$value,
|
||||||
|
LSconfig :: get('params.domain', NULL, 'string', $options),
|
||||||
|
LSconfig :: get('params.checkDomain', true, 'bool', $options)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class LSformRule_filesize extends LSformRule {
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @param string $values Valeur à vérifier
|
* @param string $values Valeur à vérifier
|
||||||
* @param array $options Options de validation :
|
* @param array $options Options de validation :
|
||||||
* - Taille max (en octet) : $options['params']['maxSize']
|
* - Taille max (en octet) : $options['params']['maxSize']
|
||||||
* - Taille min (en octet) : $options['params']['minSize']
|
* - Taille min (en octet) : $options['params']['minSize']
|
||||||
* @param object $formElement L'objet formElement attaché
|
* @param object $formElement L'objet formElement attaché
|
||||||
|
@ -40,23 +40,19 @@ class LSformRule_filesize extends LSformRule {
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options,$formElement) {
|
public static function validate ($value,$options,$formElement) {
|
||||||
$file = LSsession :: getTmpFile($value);
|
$file = LSsession :: getTmpFile($value);
|
||||||
|
|
||||||
$size = filesize($file);
|
|
||||||
|
|
||||||
if (is_int($options['params']['maxSize'])) {
|
|
||||||
if ($size > $options['params']['maxSize']) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_int($options['params']['minSize'])) {
|
$size = filesize($file);
|
||||||
if ($size < $options['params']['minSize']) {
|
|
||||||
return;
|
$maxSize = LSconfig :: get('params.maxSize', null, 'int', $options);
|
||||||
}
|
if (is_int($maxSize) && $size > $maxSize)
|
||||||
}
|
return;
|
||||||
|
|
||||||
|
$minSize = LSconfig :: get('params.minSize', null, 'int', $options);
|
||||||
|
if (is_int($minSize) && $size < $minSize)
|
||||||
|
return;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class LSformRule_imagefile extends LSformRule {
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @param string $values Valeur à vérifier
|
* @param string $values Valeur à vérifier
|
||||||
* @param array $options Options de validation :
|
* @param array $options Options de validation :
|
||||||
* - Type MIME : $options['params']['mimeType']
|
* - Type MIME : $options['params']['mimeType']
|
||||||
* - Type MIME (regex) : $options['params']['mimeTypeRegEx']
|
* - Type MIME (regex) : $options['params']['mimeTypeRegEx']
|
||||||
* @param object $formElement L'objet formElement attaché
|
* @param object $formElement L'objet formElement attaché
|
||||||
|
@ -42,19 +42,21 @@ class LSformRule_imagefile extends LSformRule {
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options,$formElement) {
|
public static function validate ($value,$options,$formElement) {
|
||||||
$file = LSsession :: getTmpFile($value);
|
$file = LSsession :: getTmpFile($value);
|
||||||
|
|
||||||
$mimetype = mime_content_type($file);
|
$mimetype = mime_content_type($file);
|
||||||
|
|
||||||
if ( (!isset($options['params']['mimeType'])) && (!isset($options['params']['mimeTypeRegEx'])) ) {
|
$mimeType = LSconfig :: get('params.mimeType', null, null, $options);
|
||||||
|
$mimeTypeRegEx = LSconfig :: get('params.mimeTypeRegEx', null, null, $options);
|
||||||
|
if ( is_null($mimeType) && is_null($mimeTypeRegEx)) {
|
||||||
$options = array(
|
$options = array(
|
||||||
'params' => array(
|
'params' => array(
|
||||||
'mimeTypeRegEx' => '/image\/.*/'
|
'mimeTypeRegEx' => '/image\/.*/'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return LSformRule_mimetype :: validate($value,$options,$formElement);
|
return LSformRule_mimetype :: validate($value,$options,$formElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class LSformRule_imagesize extends LSformRule {
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @param string $values Valeur à vérifier
|
* @param string $values Valeur à vérifier
|
||||||
* @param array $options Options de validation :
|
* @param array $options Options de validation :
|
||||||
* - Largeur max : $options['params']['maxWidth']
|
* - Largeur max : $options['params']['maxWidth']
|
||||||
* - Largeur min : $options['params']['minWidth']
|
* - Largeur min : $options['params']['minWidth']
|
||||||
* - Hauteur max : $options['params']['maxHeight']
|
* - Hauteur max : $options['params']['maxHeight']
|
||||||
|
@ -43,30 +43,25 @@ class LSformRule_imagesize extends LSformRule {
|
||||||
public static function validate ($value,$options,$formElement) {
|
public static function validate ($value,$options,$formElement) {
|
||||||
$file = LSsession :: getTmpFile($value);
|
$file = LSsession :: getTmpFile($value);
|
||||||
list($width, $height, $type, $attr) = getimagesize($file);
|
list($width, $height, $type, $attr) = getimagesize($file);
|
||||||
|
|
||||||
if (is_int($options['params']['maxWidth'])) {
|
$maxWidth = LSconfig :: get('params.maxWidth', null, 'int', $options);
|
||||||
if ($width > $options['params']['maxWidth']) {
|
if (is_int($maxWidth) && $width > $maxWidth)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
$minWidth = LSconfig :: get('params.minWidth', null, 'int', $options);
|
||||||
if (is_int($options['params']['minWidth'])) {
|
if (is_int($minWidth) && $width < $minWidth)
|
||||||
if ($width < $options['params']['minWidth']) {
|
return;
|
||||||
return;
|
|
||||||
}
|
$maxHeight = LSconfig :: get('params.maxHeight', null, 'int', $options);
|
||||||
}
|
if (is_int($maxHeight) && $height > $maxHeight)
|
||||||
if (is_int($options['params']['maxHeight'])) {
|
return;
|
||||||
if ($height > $options['params']['maxHeight']) {
|
|
||||||
return;
|
$minHeight = LSconfig :: get('params.minHeight', null, 'int', $options);
|
||||||
}
|
if (is_int($minHeight) && $height < $minHeight)
|
||||||
}
|
return;
|
||||||
if (is_int($options['params']['minHeight'])) {
|
|
||||||
if ($height < $options['params']['minHeight']) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,23 +26,24 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_inarray extends LSformRule {
|
class LSformRule_inarray extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @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']['possible_values'] ou $option
|
* - Regex : $option['params']['possible_values'] ou $option
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public static function validate($value,$option,$formElement) {
|
public static function validate($value,$option,$formElement) {
|
||||||
if (!isset($option['params']['possible_values']) || !is_array($option['params']['possible_values'])) {
|
$possible_values = LSconfig :: get('params.possible_values', null, null, $options);
|
||||||
|
if (!is_array($possible_values)) {
|
||||||
LSerror :: addErrorCode('LSformRule_inarray_01');
|
LSerror :: addErrorCode('LSformRule_inarray_01');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!in_array($value,$option['params']['possible_values']))
|
if (!in_array($value, $possible_values))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_integer extends LSformRule{
|
class LSformRule_integer extends LSformRule{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verification value.
|
* Verification value.
|
||||||
*
|
*
|
||||||
|
@ -41,16 +41,18 @@ class LSformRule_integer extends LSformRule{
|
||||||
* @return boolean true if the value is valided, false otherwise
|
* @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) {
|
||||||
if($options['params']['max'] && $value > $options['params']['max']) {
|
$max = LSconfig :: get('params.max', null, 'int', $options);
|
||||||
|
if(is_int($max) && $value > $max)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if($options['params']['min'] && $value < $options['params']['min']) {
|
$min = LSconfig :: get('params.min', null, 'int', $options);
|
||||||
|
if(is_int($min) && $value < $min)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if($options['params']['negative']) {
|
if(LSconfig :: get('params.negative', false, 'bool', $options)) {
|
||||||
$regex = '/^-[0-9]*$/';
|
$regex = '/^-[0-9]*$/';
|
||||||
}
|
}
|
||||||
elseif($options['params']['positive']) {
|
elseif(LSconfig :: get('params.positive', false, 'bool', $options)) {
|
||||||
$regex = '/^[0-9]*$/';
|
$regex = '/^[0-9]*$/';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -59,6 +61,6 @@ class LSformRule_integer extends LSformRule{
|
||||||
LSsession :: loadLSclass('LSformRule_regex');
|
LSsession :: loadLSclass('LSformRule_regex');
|
||||||
return LSformRule_regex :: validate($value,$regex,$formElement);
|
return LSformRule_regex :: validate($value,$regex,$formElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_lettersonly extends LSformRule {
|
class LSformRule_lettersonly extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
|
@ -41,6 +41,6 @@ class LSformRule_lettersonly extends LSformRule {
|
||||||
LSsession :: loadLSclass('LSformRule_regex');
|
LSsession :: loadLSclass('LSformRule_regex');
|
||||||
return LSformRule_regex :: validate($value,$regex,$formElement);
|
return LSformRule_regex :: validate($value,$regex,$formElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,19 +31,20 @@ class LSformRule_maxlength extends LSformRule {
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @param string $values Valeur à vérifier
|
* @param string $values Valeur à vérifier
|
||||||
* @param array $options Options de validation :
|
* @param array $options Options de validation :
|
||||||
* - Longueur max : $options['params']['limit']
|
* - Longueur max : $options['params']['limit']
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options,$formElement) {
|
public static function validate ($value,$options,$formElement) {
|
||||||
if(!isset($options['params']['limit'])) {
|
$limit = LSconfig :: get('params.limit', null, 'int', $options);
|
||||||
|
if(is_null($limit)) {
|
||||||
LSerror :: addErrorCode('LSformRule_01',array('type' => 'maxlength', 'param' => 'limit'));
|
LSerror :: addErrorCode('LSformRule_01',array('type' => 'maxlength', 'param' => 'limit'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return (strlen($value)<=$options['params']['limit']);
|
return (strlen($value) <= $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ class LSformRule_mimetype extends LSformRule {
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @param string $values Valeur à vérifier
|
* @param string $values Valeur à vérifier
|
||||||
* @param array $options Options de validation :
|
* @param array $options Options de validation :
|
||||||
* - Type MIME : $options['params']['mimeType']
|
* - Type MIME : $options['params']['mimeType']
|
||||||
* - Type MIME (regex) : $options['params']['mimeTypeRegEx']
|
* - Type MIME (regex) : $options['params']['mimeTypeRegEx']
|
||||||
* @param object $formElement L'objet formElement attaché
|
* @param object $formElement L'objet formElement attaché
|
||||||
|
@ -40,30 +40,26 @@ class LSformRule_mimetype extends LSformRule {
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options,$formElement) {
|
public static function validate ($value,$options,$formElement) {
|
||||||
$file = LSsession :: getTmpFile($value);
|
$file = LSsession :: getTmpFile($value);
|
||||||
|
$real_mimetype = mime_content_type($file);
|
||||||
$mimetype = mime_content_type($file);
|
|
||||||
|
$mimetype = LSconfig :: get('params.mimeType', null, null, $options);
|
||||||
if (isset($options['params']['mimeType'])) {
|
if (!is_null($mimetype)) {
|
||||||
if (is_array($options['params']['mimeType'])) {
|
if (is_array($mimetype)) {
|
||||||
if (!in_array($mimetype,$options['params']['mimeType'])) {
|
if (!in_array($real_mimetype, $mimetype))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ($mimetype != $options['params']['mimeType']) {
|
if ($real_mimetype != $mimetype)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($options['params']['mimeTypeRegEx'])) {
|
$mimeTypeRegEx = LSconfig :: get('params.mimeTypeRegEx', null, 'string', $options);
|
||||||
if (!preg_match($options['params']['mimeTypeRegEx'], $mimetype)) {
|
if (is_string($mimeTypeRegEx) && !preg_match($mimeTypeRegEx, $real_mimetype))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,19 +31,20 @@ class LSformRule_minlength extends LSformRule {
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @param string $values Valeur à vérifier
|
* @param string $values Valeur à vérifier
|
||||||
* @param array $options Options de validation :
|
* @param array $options Options de validation :
|
||||||
* - Longueur min : $options['params']['limit']
|
* - Longueur min : $options['params']['limit']
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options,$formElement) {
|
public static function validate ($value,$options,$formElement) {
|
||||||
if(!isset($options['params']['limit'])) {
|
$limit = LSconfig :: get('params.limit', null, 'int', $options);
|
||||||
|
if(is_null($limit)) {
|
||||||
LSerror :: addErrorCode('LSformRule_01',array('type' => 'minlength', 'param' => 'limit'));
|
LSerror :: addErrorCode('LSformRule_01',array('type' => 'minlength', 'param' => 'limit'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return (strlen($value)>=$options['params']['limit']);
|
return (strlen($value) >= $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_nonzero extends LSformRule {
|
class LSformRule_nonzero extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
|
@ -35,12 +35,12 @@ class LSformRule_nonzero extends LSformRule {
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options,$formElement) {
|
public static function validate ($value,$options,$formElement) {
|
||||||
$regex = '/^-?[1-9][0-9]*/';
|
$regex = '/^-?[1-9][0-9]*/';
|
||||||
LSsession :: loadLSclass('LSformRule_regex');
|
LSsession :: loadLSclass('LSformRule_regex');
|
||||||
return LSformRule_regex :: validate($value,$regex,$formElement);
|
return LSformRule_regex :: validate($value,$regex,$formElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_nopunctuation extends LSformRule {
|
class LSformRule_nopunctuation extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
|
@ -41,6 +41,6 @@ class LSformRule_nopunctuation extends LSformRule {
|
||||||
LSsession :: loadLSclass('LSformRule_regex');
|
LSsession :: loadLSclass('LSformRule_regex');
|
||||||
return LSformRule_regex :: validate($value,$regex,$formElement);
|
return LSformRule_regex :: validate($value,$regex,$formElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_numeric extends LSformRule{
|
class LSformRule_numeric extends LSformRule{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
|
@ -41,6 +41,6 @@ class LSformRule_numeric extends LSformRule{
|
||||||
LSsession :: loadLSclass('LSformRule_regex');
|
LSsession :: loadLSclass('LSformRule_regex');
|
||||||
return LSformRule_regex :: validate($value,$regex,$formElement);
|
return LSformRule_regex :: validate($value,$regex,$formElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_password extends LSformRule {
|
class LSformRule_password extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
|
@ -42,52 +42,45 @@ class LSformRule_password extends LSformRule {
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options=array(),$formElement) {
|
public static function validate ($value,$options=array(),$formElement) {
|
||||||
if(isset($options['params']['maxLength'])) {
|
$maxLength = LSconfig :: get('params.maxLength', null, 'int', $options);
|
||||||
if (strlen($value)>$options['params']['maxLength'])
|
if(is_int($maxLength) && strlen($value) > $maxLength)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
$minLength = LSconfig :: get('params.minLength', null, 'int', $options);
|
||||||
if(isset($options['params']['minLength'])) {
|
if(is_int($minLength) && strlen($value) < $minLength)
|
||||||
if (strlen($value)<$options['params']['minLength'])
|
return;
|
||||||
return;
|
|
||||||
}
|
$regex = LSconfig :: get('params.regex', null, null, $options);
|
||||||
|
if(!is_null($regex)) {
|
||||||
if(isset($options['params']['regex'])) {
|
if (!is_array($regex))
|
||||||
if (!is_array($options['params']['regex'])) {
|
$regex = array($regex);
|
||||||
$options['params']['regex']=array($options['params']['regex']);
|
|
||||||
}
|
$minValidRegex = LSconfig :: get('params.minValidRegex', count($regex), 'int', $options);
|
||||||
if (isset($options['params']['minValidRegex'])) {
|
if ($minValidRegex == 0 || $minValidRegex > count($regex))
|
||||||
$options['params']['minValidRegex']=(int)$options['params']['minValidRegex'];
|
$minValidRegex = count($regex);
|
||||||
if ($options['params']['minValidRegex']==0 || $options['params']['minValidRegex']>count($options['params']['regex'])) {
|
|
||||||
$options['params']['minValidRegex']=count($options['params']['regex']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$options['params']['minValidRegex']=count($options['params']['regex']);
|
|
||||||
}
|
|
||||||
$valid=0;
|
$valid=0;
|
||||||
foreach($options['params']['regex'] as $regex) {
|
foreach($regex as $r) {
|
||||||
if ($regex[0]!='/') {
|
if ($r[0] != '/') {
|
||||||
LSerror :: addErrorCode('LSformRule_password_01');
|
LSerror :: addErrorCode('LSformRule_password_01');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (preg_match($regex,$value))
|
if (preg_match($r, $value))
|
||||||
$valid++;
|
$valid++;
|
||||||
}
|
}
|
||||||
if ($valid<$options['params']['minValidRegex'])
|
if ($valid < $minValidRegex)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($options['params']['prohibitedValues']) && is_array($options['params']['prohibitedValues'])) {
|
$prohibitedValues = LSconfig :: get('params.prohibitedValues', null, null, $options);
|
||||||
if (in_array($value,$options['params']['prohibitedValues']))
|
if(is_array($prohibitedValues) && in_array($value, $prohibitedValues))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,26 +26,27 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_rangelength extends LSformRule {
|
class LSformRule_rangelength extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @param string $values Valeur à vérifier
|
* @param string $values Valeur à vérifier
|
||||||
* @param array $options Options de validation :
|
* @param array $options Options de validation :
|
||||||
* - Longueur min : $options['params']['limits'][0]
|
* - Longueur min : $options['params']['limits'][0]
|
||||||
* - Longueur max : $options['params']['limits'][1]
|
* - Longueur max : $options['params']['limits'][1]
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options=array(),$formElement) {
|
public static function validate ($value,$options=array(),$formElement) {
|
||||||
if(!isset($options['params']['limits'])) {
|
$limits = LSconfig :: get('params.limits', null, null, $options);
|
||||||
|
if(!is_array($limits) || count($limits) != 2) {
|
||||||
LSerror :: addErrorCode('LSformRule_01',array('type' => 'rangelength', 'param' => 'limits'));
|
LSerror :: addErrorCode('LSformRule_01',array('type' => 'rangelength', 'param' => 'limits'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$len=strlen($value);
|
$len = strlen($value);
|
||||||
return ($len >= $options['params']['limits'][0] && $len <= $options['params']['limits'][1]);
|
return ($len >= $limits[0] && $len <= $limits[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,34 +26,31 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_regex extends LSformRule {
|
class LSformRule_regex extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @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 : $options['params']['regex'] ou $options
|
* - 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
|
||||||
*/
|
*/
|
||||||
public static function validate($value,$options,$formElement) {
|
public static function validate($value, $options, $formElement) {
|
||||||
if (is_array($options)) {
|
if (is_array($options)) {
|
||||||
if (isset($options['params']['regex'])) {
|
$regex = LSconfig :: get('params.regex', null, 'string', $options);
|
||||||
$regex=$options['params']['regex'];
|
if (!is_string($regex)) {
|
||||||
}
|
|
||||||
else {
|
|
||||||
LSerror :: addErrorCode('LSformRule_regex_01');
|
LSerror :: addErrorCode('LSformRule_regex_01');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$regex=$options;
|
$regex = $options;
|
||||||
}
|
}
|
||||||
if (!preg_match($regex, $value)) {
|
if (!preg_match($regex, $value))
|
||||||
return false;
|
return false;
|
||||||
}
|
return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,10 @@ class LSformRule_required extends LSformRule {
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
public static function validate ($value,$options=NULL,$formElement) {
|
public static function validate ($value,$options=NULL,$formElement) {
|
||||||
return ((string)$value != '');
|
return ((string)$value != '');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_ssh_pub_key extends LSformRule {
|
class LSformRule_ssh_pub_key extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate SSH public key value
|
* Validate SSH public key value
|
||||||
*
|
*
|
||||||
|
@ -35,7 +35,7 @@ class LSformRule_ssh_pub_key extends LSformRule {
|
||||||
* @param object $formElement The related formElement object
|
* @param object $formElement The related formElement object
|
||||||
*
|
*
|
||||||
* @return boolean true if the value is valide, false if not
|
* @return boolean true if the value is valide, false if not
|
||||||
*/
|
*/
|
||||||
public static function validate($value,$options,$formElement) {
|
public static function validate($value,$options,$formElement) {
|
||||||
if (preg_match('/^(ssh-[a-z0-9]+) +([^ ]+) +(.*)$/', $value, $m)) {
|
if (preg_match('/^(ssh-[a-z0-9]+) +([^ ]+) +(.*)$/', $value, $m)) {
|
||||||
$data=@base64_decode($m[2]);
|
$data=@base64_decode($m[2]);
|
||||||
|
|
|
@ -26,12 +26,12 @@
|
||||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||||
*/
|
*/
|
||||||
class LSformRule_telephonenumber extends LSformRule {
|
class LSformRule_telephonenumber extends LSformRule {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vérification de la valeur.
|
* Vérification de la valeur.
|
||||||
*
|
*
|
||||||
* @param string $value Valeur à vérifier
|
* @param string $value Valeur à vérifier
|
||||||
* @param array $options Options de validation :
|
* @param array $options Options de validation :
|
||||||
* @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
|
||||||
|
|
Loading…
Reference in a new issue