From f11fe0ca341652277a67f7b446ff359fc25d067f Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 31 Aug 2006 10:00:09 +0000 Subject: [PATCH] Possibility to pass the hasColumn constraint/validator arg as an array --- Doctrine/DataDict.php | 5 ++- Doctrine/Identifier.php | 4 -- Doctrine/Locking/Manager/Pessimistic.php | 8 ++-- Doctrine/Record.php | 2 +- Doctrine/Table.php | 50 ++++++++++++++++-------- 5 files changed, 42 insertions(+), 27 deletions(-) diff --git a/Doctrine/DataDict.php b/Doctrine/DataDict.php index 89633dd2d..40c5b88fc 100644 --- a/Doctrine/DataDict.php +++ b/Doctrine/DataDict.php @@ -32,7 +32,10 @@ class Doctrine_DataDict { */ public function createTable($tablename, array $columns) { foreach($columns as $name => $args) { - $r[] = $name." ".$this->getADOType($args[0],$args[1])." ".str_replace("|"," ",$args[2]); + if( ! is_array($args[2])) + $args[2] = array(); + + $r[] = $name." ".$this->getADOType($args[0],$args[1])." ".implode(' ',$args[2]); } diff --git a/Doctrine/Identifier.php b/Doctrine/Identifier.php index 9bcc3a20b..48e6f747b 100644 --- a/Doctrine/Identifier.php +++ b/Doctrine/Identifier.php @@ -1,9 +1,5 @@ _dataSource->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true) { $columns = array(); - $columns['object_type'] = array('string', 50, 'notnull|primary'); - $columns['object_key'] = array('string', 250, 'notnull|primary'); - $columns['user_ident'] = array('string', 50, 'notnull'); - $columns['timestamp_obtained'] = array('integer', 10, 'notnull'); + $columns['object_type'] = array('string', 50, array('notnull','primary')); + $columns['object_key'] = array('string', 250, array('notnull','primary')); + $columns['user_ident'] = array('string', 50, array('notnull')); + $columns['timestamp_obtained'] = array('integer', 10, array('notnull')); $dataDict = new Doctrine_DataDict($this->_dataSource->getDBH()); $dataDict->createTable($this->_lockTable, $columns); diff --git a/Doctrine/Record.php b/Doctrine/Record.php index 3a8cd415b..7995387e8 100644 --- a/Doctrine/Record.php +++ b/Doctrine/Record.php @@ -274,7 +274,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite $value = unserialize($tmp[$name]); if($value === false) - throw new Doctrine_Exception("Unserialization of $name failed. ".var_dump($tmp[$name],true)); + throw new Doctrine_Record_Exception("Unserialization of $name failed. ".var_dump($tmp[$name],true)); } else $value = $tmp[$name]; diff --git a/Doctrine/Table.php b/Doctrine/Table.php index 856482137..0e9dd7c62 100644 --- a/Doctrine/Table.php +++ b/Doctrine/Table.php @@ -1,4 +1,23 @@ . + */ require_once("Exception/Find.class.php"); require_once("Exception/Mapping.class.php"); require_once("Exception/PrimaryKey.class.php"); @@ -158,7 +177,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { switch(count($this->primaryKeys)): case 0: - $this->columns = array_merge(array("id" => array("integer",11,"autoincrement|primary")), $this->columns); + $this->columns = array_merge(array("id" => array("integer",11, array("autoincrement", "primary"))), $this->columns); $this->primaryKeys[] = "id"; $this->identifier = "id"; $this->identifierType = Doctrine_Identifier::AUTO_INCREMENT; @@ -171,10 +190,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { } else { foreach($this->primaryKeys as $pk) { - $o = $this->columns[$pk][2]; - $e = explode("|",$o); - $found = false; + $e = $this->columns[$pk][2]; + $found = false; foreach($e as $option) { if($found) @@ -183,10 +201,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $e2 = explode(":",$option); switch(strtolower($e2[0])): - case "unique": - $this->identifierType = Doctrine_Identifier::UNIQUE; - $found = true; - break; case "autoincrement": $this->identifierType = Doctrine_Identifier::AUTO_INCREMENT; $found = true; @@ -261,11 +275,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { * @param mixed $options * @return void */ - final public function setColumn($name, $type, $length, $options = "") { + final public function setColumn($name, $type, $length, $options = array()) { + if(is_string($options)) + $options = explode('|', $options); + $this->columns[$name] = array($type,$length,$options); - $e = explode("|",$options); - if(in_array("primary",$e)) { + if(in_array("primary",$options)) { $this->primaryKeys[] = $name; } } @@ -525,7 +541,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { * @param string $name component name of which a foreign key object is bound * @return boolean */ - final public function hasForeignKey($name) { + final public function hasRelation($name) { if(isset($this->bound[$name])) return true; @@ -565,7 +581,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $relation = new Doctrine_LocalKey($table,$foreign,$local,$type, $alias); } else - throw new Doctrine_Mapping_Exception("Only one-to-one relations are possible when local reference key is used."); + throw new Doctrine_Table_Exception("Only one-to-one relations are possible when local reference key is used."); } elseif($component == $name || ($component == $alias && $name == $this->name)) { if( ! isset($local)) @@ -579,7 +595,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { // only aggregate relations allowed if($type != Doctrine_Relation::MANY_AGGREGATE) - throw new Doctrine_Mapping_Exception("Only aggregate relations are allowed for many-to-many relations"); + throw new Doctrine_Table_Exception("Only aggregate relations are allowed for many-to-many relations"); $classes = array_merge($this->parents, array($this->name)); @@ -597,7 +613,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $fields = explode("-",$e2[1]); if($e2[0] != $component) - throw new Doctrine_Mapping_Exception($e2[0]." doesn't match ".$component); + throw new Doctrine_Table_Exception($e2[0]." doesn't match ".$component); $associationTable = $this->connection->getTable($e2[0]); @@ -617,7 +633,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $this->relations[$alias] = $relation; return $this->relations[$alias]; } - throw new InvalidKeyException('Unknown relation '.$original); + throw new Doctrine_Table_Exception('Unknown relation '.$original); } /** * returns an array containing all foreign key objects @@ -795,7 +811,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $this->data = $this->connection->execute($query,$params)->fetch(PDO::FETCH_ASSOC); if($this->data === false) - throw new Doctrine_Find_Exception(); + return false; } return $this->getRecord(); }