Minor validator fix
This commit is contained in:
parent
7b19bef12b
commit
d3098e3a25
@ -312,8 +312,10 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
* @return boolean
|
||||
*/
|
||||
public function remove($key) {
|
||||
if( ! isset($this->data[$key]))
|
||||
if( ! isset($this->data[$key])) {
|
||||
$this->expand($key);
|
||||
throw new InvalidKeyException();
|
||||
}
|
||||
|
||||
$removed = $this->data[$key];
|
||||
|
||||
@ -417,7 +419,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
||||
|
||||
if(in_array($record,$this->data)) {
|
||||
return false;
|
||||
} else
|
||||
}
|
||||
|
||||
if(isset($this->generator)) {
|
||||
$key = $this->generator->getIndex($record);
|
||||
|
@ -21,25 +21,24 @@ class Doctrine_Form implements Iterator {
|
||||
$definitions = $this->columns[$column];
|
||||
|
||||
$e = explode("|",$definitions[2]);
|
||||
|
||||
|
||||
$enum = false;
|
||||
foreach($e as $v) {
|
||||
$e2 = explode(":",$v);
|
||||
if($e2[0] == "enum") {
|
||||
$enum = explode("-",$e2[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($definitions[0] == "enum")
|
||||
$enum = $this->record->getTable()->getEnumValues($column);
|
||||
|
||||
$length = $definitions[1];
|
||||
if( ! in_array("autoincrement",$e) && ! in_array("protected",$e)) {
|
||||
if($enum) {
|
||||
$elements[$column] = "<select name='data[$column]'>\n";
|
||||
foreach($enum as $k => $v) {
|
||||
if($this->record->get($column) == $k) {
|
||||
if($this->record->get($column) == $v) {
|
||||
$str = 'selected';
|
||||
} else
|
||||
$str = '';
|
||||
|
||||
$elements[$column] .= " <option value='$k' $str>$v</option>\n";
|
||||
$elements[$column] .= " <option value='$v' $str>$v</option>\n";
|
||||
}
|
||||
$elements[$column] .= "</select>\n";
|
||||
} else {
|
||||
|
@ -29,7 +29,7 @@ class Doctrine_Lib {
|
||||
* @param Doctrine_Record $record
|
||||
* @return string
|
||||
*/
|
||||
public function getRecordAsString(Doctrine_Record $record) {
|
||||
public static function getRecordAsString(Doctrine_Record $record) {
|
||||
$r[] = "<pre>";
|
||||
$r[] = "Component : ".$record->getTable()->getComponentName();
|
||||
$r[] = "ID : ".$record->getID();
|
||||
@ -65,7 +65,7 @@ class Doctrine_Lib {
|
||||
* @param Doctrine_Session $session
|
||||
* @return string
|
||||
*/
|
||||
public function getSessionAsString(Doctrine_Session $session) {
|
||||
public static function getSessionAsString(Doctrine_Session $session) {
|
||||
$r[] = "<pre>";
|
||||
$r[] = "Doctrine_Session object";
|
||||
$r[] = "State : ".Doctrine_Lib::getSessionStateAsString($session->getState());
|
||||
@ -109,7 +109,7 @@ class Doctrine_Lib {
|
||||
* @param Doctrine_Table $table
|
||||
* @return string
|
||||
*/
|
||||
public function getTableAsString(Doctrine_Table $table) {
|
||||
public static function getTableAsString(Doctrine_Table $table) {
|
||||
$r[] = "<pre>";
|
||||
$r[] = "Component : ".$this->getComponentName();
|
||||
$r[] = "Table : ".$this->getTableName();
|
||||
@ -124,7 +124,7 @@ class Doctrine_Lib {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function formatSql($sql) {
|
||||
public static function formatSql($sql) {
|
||||
$e = explode("\n",$sql);
|
||||
$color = "367FAC";
|
||||
$l = $sql;
|
||||
@ -146,7 +146,7 @@ class Doctrine_Lib {
|
||||
* @param Doctrine_Collection $collection
|
||||
* @return string
|
||||
*/
|
||||
public function getCollectionAsString(Doctrine_Collection $collection) {
|
||||
public static function getCollectionAsString(Doctrine_Collection $collection) {
|
||||
$r[] = "<pre>";
|
||||
$r[] = get_class($collection);
|
||||
|
||||
|
@ -172,6 +172,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
// listen the onLoad event
|
||||
$this->table->getAttribute(Doctrine::ATTR_LISTENER)->onLoad($this);
|
||||
}
|
||||
|
||||
$this->table->getRepository()->add($this);
|
||||
}
|
||||
}
|
||||
@ -229,7 +230,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
if( ! isset($tmp[$name])) {
|
||||
if($type == 'array') {
|
||||
$this->data[$name] = array();
|
||||
$this->modified[] = $name;
|
||||
} else
|
||||
$this->data[$name] = self::$null;
|
||||
} else {
|
||||
@ -715,7 +715,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
final public function getModified() {
|
||||
$a = array();
|
||||
|
||||
foreach($this->modified as $k=>$v) {
|
||||
foreach($this->modified as $k => $v) {
|
||||
$a[$v] = $this->data[$v];
|
||||
}
|
||||
return $a;
|
||||
@ -726,10 +726,13 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
final public function getPrepared() {
|
||||
final public function getPrepared(array $array = array()) {
|
||||
$a = array();
|
||||
|
||||
foreach($this->modified as $k => $v) {
|
||||
if(empty($array))
|
||||
$array = $this->modified;
|
||||
|
||||
foreach($array as $k => $v) {
|
||||
$type = $this->table->getTypeOf($v);
|
||||
|
||||
if($type == 'array' ||
|
||||
|
@ -127,12 +127,9 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
|
||||
$record = new $name($this);
|
||||
|
||||
|
||||
$names = array();
|
||||
|
||||
$class = $name;
|
||||
|
||||
|
||||
|
||||
// get parent classes
|
||||
|
||||
@ -825,6 +822,16 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
final public function setEnumValues($field, array $values) {
|
||||
$this->enum[$field] = $values;
|
||||
}
|
||||
/**
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
final public function getEnumValues($field) {
|
||||
if(isset($this->enum[$field]))
|
||||
return $this->enum[$field];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
/**
|
||||
* enumValue
|
||||
*/
|
||||
@ -836,7 +843,7 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
*/
|
||||
final public function enumIndex($field, $value) {
|
||||
$v = array_search($value, $this->enum[$field]);
|
||||
return ($v !== false)?$v:$value;
|
||||
return $v;
|
||||
}
|
||||
/**
|
||||
* @return integer
|
||||
|
@ -106,21 +106,31 @@ class Doctrine_Validator {
|
||||
switch($record->getState()):
|
||||
case Doctrine_Record::STATE_TDIRTY:
|
||||
case Doctrine_Record::STATE_TCLEAN:
|
||||
// all fields will be validated
|
||||
$data = $record->getData();
|
||||
break;
|
||||
default:
|
||||
// only the modified fields will be validated
|
||||
$data = $record->getModified();
|
||||
endswitch;
|
||||
|
||||
$err = array();
|
||||
|
||||
foreach($data as $key => $value) {
|
||||
if($value === self::$null)
|
||||
$value = null;
|
||||
|
||||
$column = $columns[$key];
|
||||
|
||||
if($column[0] == "enum") {
|
||||
$value = $record->getTable()->enumIndex($value);
|
||||
|
||||
if($column[0] == 'array' || $column[0] == 'object')
|
||||
if($value === false) {
|
||||
$err[$key] = Doctrine_Validator::ERR_ENUM;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if($column[0] == "array" || $column[0] == "object")
|
||||
$length = strlen(serialize($value));
|
||||
else
|
||||
$length = strlen($value);
|
||||
@ -199,6 +209,9 @@ class Doctrine_Validator {
|
||||
*/
|
||||
public static function isValidType($var, $type) {
|
||||
$looseType = self::gettype($var);
|
||||
if($type == 'enum')
|
||||
$type = 'integer';
|
||||
|
||||
switch($looseType):
|
||||
case 'float':
|
||||
case 'double':
|
||||
|
@ -158,5 +158,6 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase {
|
||||
$this->assertEqual($a["User"][0]["name"], Doctrine_Validator::ERR_LENGTH);
|
||||
$this->manager->setAttribute(Doctrine::ATTR_VLD, false);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user