diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 3d51ea4e3..b4abaa41f 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -222,14 +222,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable } switch (count($this->primaryKeys)) { case 0: - $this->columns = array_merge(array('id' => - array('integer', - 20, - array('autoincrement' => true, - 'primary' => true - ) - ) - ), $this->columns); + $definition = array('id' => + new Doctrine_Column( + array('type' => 'integer', + 'length' => 20, + 'autoincrement' => true, + 'primary' => true, + ))); + $this->columns = array_merge($definition, $this->columns); $this->primaryKeys[] = 'id'; $this->identifier = 'id'; @@ -243,7 +243,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable } else { foreach ($this->primaryKeys as $pk) { - $e = $this->columns[$pk][2]; + $e = $this->columns[$pk]; $found = false; @@ -336,9 +336,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable $primary = array(); foreach ($this->columns as $name => $column) { - $definition = $column[2]; - $definition['type'] = $column[0]; - $definition['length'] = $column[1]; + $definition = $column->getDefinition(); switch ($definition['type']) { case 'enum': @@ -517,7 +515,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable throw new Doctrine_Table_Exception('Invalid argument given for column length'); } - $this->columns[$name] = array($type, $length, $options); + $definition = array('type' => $type, 'length' => $length) + $options; + $this->columns[$name] = new Doctrine_Column($definition); if (isset($options['primary'])) { $this->primaryKeys[] = $name; @@ -536,25 +535,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { return $this->hasDefaultValues; } - /** - * getDefaultValueOf - * returns the default value(if any) for given column - * - * @param string $column - * @return mixed - */ - public function getDefaultValueOf($column) - { - $column = strtolower($column); - if ( ! isset($this->columns[$column])) { - throw new Doctrine_Table_Exception("Couldn't get default value. Column ".$column." doesn't exist."); - } - if (isset($this->columns[$column][2]['default'])) { - return $this->columns[$column][2]['default']; - } else { - return null; - } - } /** * @return mixed */ @@ -1109,8 +1089,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable */ final public function getEnumValues($field) { - if (isset($this->columns[$field][2]['values'])) { - return $this->columns[$field][2]['values']; + if (isset($this->columns[$field]['values'])) { + return $this->columns[$field]['values']; } else { return array(); } @@ -1127,7 +1107,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable if ($index instanceof Doctrine_Null) return $index; - return isset($this->columns[$field][2]['values'][$index]) ? $this->columns[$field][2]['values'][$index] : $index; + return isset($this->columns[$field]['values'][$index]) ? $this->columns[$field]['values'][$index] : $index; } /** * enumIndex @@ -1186,35 +1166,34 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable return $value; } - - /** - * getDefinitionOf - * - * @return string ValueWrapper class name on success, false on failure - */ - public function getValueWrapperOf($column) - { - if (isset($this->columns[$column][2]['wrapper'])) { - return $this->columns[$column][2]['wrapper']; - } - return false; - } /** * getColumnCount * * @return integer the number of columns in this table */ - final public function getColumnCount() + public function getColumnCount() { return $this->columnCount; } - + /** + * getColumn + * + * @param string $name + * @return Doctrine_Column + */ + public function getColumn($name) + { + if (isset($this->columns[$name])) { + return $this->columns[$name]; + } + throw new Doctrine_Table_Exception('Unknown column ' . $name); + } /** * returns all columns and their definitions * * @return array */ - final public function getColumns() + public function getColumns() { return $this->columns; } @@ -1227,31 +1206,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { return array_keys($this->columns); } - - /** - * getDefinitionOf - * - * @return mixed array on success, false on failure - */ - public function getDefinitionOf($column) - { - if (isset($this->columns[$column])) { - return $this->columns[$column]; - } - return false; - } - /** - * getTypeOf - * - * @return mixed string on success, false on failure - */ - public function getTypeOf($column) - { - if (isset($this->columns[$column])) { - return $this->columns[$column][0]; - } - return false; - } /** * setData * doctrine uses this function internally @@ -1321,6 +1275,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { return $this->options['tableName']; } + public function setTableName($name) + { + $this->options['tableName'] = $name; + } /** * determine if table acts as tree *