1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 12:48:26 +02:00

validator handler - temporary BC till '-' separator is replaced with ':' separator (min:max range), OO related improvements

This commit is contained in:
secretr
2010-02-09 13:34:23 +00:00
parent 6cfbdf01f5
commit ab26b37476

View File

@@ -9,8 +9,8 @@
* Handler - general purpose validation functions * Handler - general purpose validation functions
* *
* $Source: /cvs_backup/e107_0.8/e107_handlers/validator_class.php,v $ * $Source: /cvs_backup/e107_0.8/e107_handlers/validator_class.php,v $
* $Revision: 1.20 $ * $Revision: 1.21 $
* $Date: 2010-02-07 13:55:38 $ * $Date: 2010-02-09 13:34:23 $
* $Author: secretr $ * $Author: secretr $
* *
*/ */
@@ -315,7 +315,7 @@ class e_validator
if(($required || $this->isOptionalField($field_name)) && !$this->validateField($field_name, $value, $required)) if(($required || $this->isOptionalField($field_name)) && !$this->validateField($field_name, $value, $required))
{ {
$this->_is_valid_data = false; $this->_is_valid_data = false;
$this->addValidateMessage($this->getFieldName($field_name, $required), $this->getErrorCode($field_name), $this->getFieldMessage($field_name, $required, $value)); $this->addValidateMessage($this->getFieldName($field_name, $required), $this->getErrorCode($field_name), $this->getFieldMessage($field_name, $value, $required));
continue; continue;
} }
} }
@@ -511,12 +511,13 @@ class e_validator
case 'int': case 'int':
case 'integer': case 'integer':
if(!preg_match('/[0-9]/', $value)) // TODO - negative values! if(!preg_match('/^-?[\d]+$/', $value)) // negative values support
{ {
$this->addValidateResult($name, self::ERR_INT_EXPECTED); $this->addValidateResult($name, self::ERR_INT_EXPECTED);
return false; return false;
} }
$tmp = explode(':', $cond); // BC! Will be removed after we replace '-' with ':' separator!
$tmp = $this->parseMinMax($cond);
if(is_numeric($tmp[0]) && (integer) $tmp[0] > (integer) $value) if(is_numeric($tmp[0]) && (integer) $tmp[0] > (integer) $value)
{ {
$this->addValidateResult($name, self::ERR_TOO_LOW); $this->addValidateResult($name, self::ERR_TOO_LOW);
@@ -535,7 +536,7 @@ class e_validator
case 'string': case 'string':
case 'text': case 'text':
case 'varchar': case 'varchar':
$tmp = explode(':', $cond); $tmp = $this->parseMinMax($cond);
$length = e107::getParser()->ustrlen($value); $length = e107::getParser()->ustrlen($value);
if(is_numeric($tmp[0]) && (integer) $tmp[0] > $length) if(is_numeric($tmp[0]) && (integer) $tmp[0] > $length)
{ {
@@ -560,7 +561,7 @@ class e_validator
$this->addValidateResult($name, self::ERR_FLOAT_EXPECTED); $this->addValidateResult($name, self::ERR_FLOAT_EXPECTED);
return false; return false;
} }
$tmp = explode(':', $cond); $tmp = $this->parseMinMax($cond);
if(is_numeric($tmp[0]) && (float) $tmp[0] > (float) $value) if(is_numeric($tmp[0]) && (float) $tmp[0] > (float) $value)
{ {
$this->addValidateResult($name, self::ERR_TOO_LOW); $this->addValidateResult($name, self::ERR_TOO_LOW);
@@ -582,7 +583,7 @@ class e_validator
return false; return false;
} }
$length = count($value); $length = count($value);
$tmp = explode('-', $cond); $tmp = $this->parseMinMax($cond);
if(is_numeric($tmp[0]) && (integer) $tmp[0] > $length) if(is_numeric($tmp[0]) && (integer) $tmp[0] > $length)
{ {
$this->addValidateResult($name, self::ERR_ARRCOUNT_LOW); $this->addValidateResult($name, self::ERR_ARRCOUNT_LOW);
@@ -612,7 +613,7 @@ class e_validator
} }
if(vartrue($params['size'])) if(vartrue($params['size']))
{ {
$tmp = explode('-', $params['size'], 2); $tmp = $this->parseMinMax($cond);
$fs = filesize($path); $fs = filesize($path);
if(!$fs || (integer) $tmp[0] > $fs) if(!$fs || (integer) $tmp[0] > $fs)
{ {
@@ -624,12 +625,12 @@ class e_validator
$this->addValidateResult($name, self::ERR_SIZEMAX_FILE); $this->addValidateResult($name, self::ERR_SIZEMAX_FILE);
return false; return false;
} }
elseif(is_numeric(varset($params['maxlen'])) && (integer) $params['maxlen'] < e107::getParser()->ustrlen($fs)) }
if(is_numeric(varset($params['maxlen'])) && (integer) $params['maxlen'] < e107::getParser()->ustrlen($value))
{ {
$this->addValidateResult($name, self::ERR_TOO_LONG); $this->addValidateResult($name, self::ERR_TOO_LONG);
return false; return false;
} }
}
$this->addValidData($name, $value); $this->addValidData($name, $value);
return true; return true;
break; break;
@@ -658,7 +659,7 @@ class e_validator
// check length // check length
if($cond) if($cond)
{ {
$tmp = explode('-', $cond); $tmp = $this->parseMinMax($cond);
$length = e107::getParser()->ustrlen($value[0]); $length = e107::getParser()->ustrlen($value[0]);
if(is_numeric($tmp[0]) && (integer) $tmp[0] > $length) if(is_numeric($tmp[0]) && (integer) $tmp[0] > $length)
{ {
@@ -690,7 +691,7 @@ class e_validator
// check length // check length
if($cond) if($cond)
{ {
$tmp = explode('-', $cond); $tmp = $this->parseMinMax($cond);
$length = e107::getParser()->ustrlen($value[0]); $length = e107::getParser()->ustrlen($value[0]);
if(is_numeric($tmp[0]) && (integer) $tmp[0] > $length) if(is_numeric($tmp[0]) && (integer) $tmp[0] > $length)
{ {
@@ -714,6 +715,21 @@ class e_validator
} }
} }
protected function parseMinMax($string)
{
return explode(':', $this->_convertConditionBC($string), 2);
}
private function _convertConditionBC($condition)
{
// BC! Will be removed after we replace '-' with ':' separator!
if(strpos($condition, ':') === false)
{
return preg_replace('/^([0-9]+)-([0-9]+)$/', '$1:$2', $condition);
}
return $condition;
}
/** /**
* Add validation error to validate result stack * Add validation error to validate result stack
* *