Introduced constants: Doctrine::ATTR_AUTO_LENGTH_VLD and Doctrine::ATTR_AUTO_TYPE_VLD.
Both default to TRUE. If set to false, you need to explicitly specify "length" and/or "type" in the parameter of hasColumn that specifies the validators for that column.
This commit is contained in:
parent
05cf2cd1b6
commit
4433e6ff40
@ -149,6 +149,14 @@ final class Doctrine {
|
||||
* accessor invoking attribute
|
||||
*/
|
||||
const ATTR_ACCESSORS = 18;
|
||||
/**
|
||||
* automatic length validations attribute
|
||||
*/
|
||||
const ATTR_AUTO_LENGTH_VLD = 19;
|
||||
/**
|
||||
* automatic type validations attribute
|
||||
*/
|
||||
const ATTR_AUTO_TYPE_VLD = 20;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -115,6 +115,8 @@ abstract class Doctrine_Configurable {
|
||||
|
||||
break;
|
||||
case Doctrine::ATTR_VLD:
|
||||
case Doctrine::ATTR_AUTO_LENGTH_VLD:
|
||||
case Doctrine::ATTR_AUTO_TYPE_VLD:
|
||||
case Doctrine::ATTR_QUERY_LIMIT:
|
||||
|
||||
break;
|
||||
@ -188,7 +190,7 @@ abstract class Doctrine_Configurable {
|
||||
public function getAttribute($attribute) {
|
||||
$attribute = (int) $attribute;
|
||||
|
||||
if($attribute < 1 || $attribute > 18)
|
||||
if($attribute < 1 || $attribute > 20)
|
||||
throw new InvalidKeyException();
|
||||
|
||||
if( ! isset($this->attributes[$attribute])) {
|
||||
|
@ -90,6 +90,8 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
|
||||
Doctrine::ATTR_LISTENER => new Doctrine_EventListener(),
|
||||
Doctrine::ATTR_LOCKMODE => 1,
|
||||
Doctrine::ATTR_VLD => false,
|
||||
Doctrine::ATTR_AUTO_LENGTH_VLD => true,
|
||||
Doctrine::ATTR_AUTO_TYPE_VLD => true,
|
||||
Doctrine::ATTR_CREATE_TABLES => true,
|
||||
Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS
|
||||
);
|
||||
|
@ -105,14 +105,11 @@ class Doctrine_Validator {
|
||||
}
|
||||
}
|
||||
|
||||
if($column[0] == "array" || $column[0] == "object")
|
||||
$length = strlen(serialize($value));
|
||||
else
|
||||
$length = strlen($value);
|
||||
|
||||
if($length > $column[1]) {
|
||||
$errorStack->add($key, 'length');
|
||||
continue;
|
||||
if($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD)) {
|
||||
if(!$this->validateLength($column, $key, $value)) {
|
||||
$errorStack->add($key, 'length');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( ! is_array($column[2]))
|
||||
@ -138,6 +135,24 @@ class Doctrine_Validator {
|
||||
$name == 'default')
|
||||
continue;
|
||||
|
||||
if(strtolower($name) == 'length') {
|
||||
if(!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_LENGTH_VLD)) {
|
||||
if(!$this->validateLength($column, $key, $value)) {
|
||||
$errorStack->add($key, 'length');
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if(strtolower($name) == 'type') {
|
||||
if(!$record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
|
||||
if( ! self::isValidType($value, $column[0])) {
|
||||
$errorStack->add($key, 'type');
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$validator = self::getValidator($name);
|
||||
if( ! $validator->validate($record, $key, $value, $args)) {
|
||||
|
||||
@ -147,15 +162,33 @@ class Doctrine_Validator {
|
||||
//$err[$key] = 'not valid';
|
||||
|
||||
// errors found quit validation looping for this column
|
||||
break;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
if( ! self::isValidType($value, $column[0])) {
|
||||
$errorStack->add($key, 'type');
|
||||
continue;
|
||||
|
||||
if($record->getTable()->getAttribute(Doctrine::ATTR_AUTO_TYPE_VLD)) {
|
||||
if( ! self::isValidType($value, $column[0])) {
|
||||
$errorStack->add($key, 'type');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
*/
|
||||
private function validateLength($column, $key, $value) {
|
||||
if($column[0] == "array" || $column[0] == "object")
|
||||
$length = strlen(serialize($value));
|
||||
else
|
||||
$length = strlen($value);
|
||||
|
||||
if($length > $column[1]) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* whether or not this validator has errors
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user