1
0
mirror of synced 2024-12-15 07:36:03 +03:00

refactoring the table class

This commit is contained in:
zYne 2007-09-20 20:53:15 +00:00
parent 2169cbe95e
commit e24d9c69dd

View File

@ -36,7 +36,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
/** /**
* @var array $data temporary data which is then loaded into Doctrine_Record::$data * @var array $data temporary data which is then loaded into Doctrine_Record::$data
*/ */
private $data = array(); private $_data = array();
/** /**
* @var array $primaryKeys an array containing all primary key column names * @var array $primaryKeys an array containing all primary key column names
*/ */
@ -150,7 +150,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
/** /**
* @var Doctrine_Tree $tree tree object associated with this table * @var Doctrine_Tree $tree tree object associated with this table
*/ */
protected $tree; protected $_tree;
/** /**
* @var Doctrine_Relation_Parser $_parser relation parser object * @var Doctrine_Relation_Parser $_parser relation parser object
*/ */
@ -237,12 +237,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$this->_identifierType = Doctrine::IDENTIFIER_AUTOINC; $this->_identifierType = Doctrine::IDENTIFIER_AUTOINC;
$this->columnCount++; $this->columnCount++;
break; break;
default: case 1:
if (count($this->primaryKeys) > 1) {
$this->_identifier = $this->primaryKeys;
$this->_identifierType = Doctrine::IDENTIFIER_COMPOSITE;
} else {
foreach ($this->primaryKeys as $pk) { foreach ($this->primaryKeys as $pk) {
$e = $this->columns[$pk]; $e = $this->columns[$pk];
@ -282,9 +277,11 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
} }
$this->_identifier = $pk; $this->_identifier = $pk;
} }
break;
default:
$this->_identifier = $this->primaryKeys;
$this->_identifierType = Doctrine::IDENTIFIER_COMPOSITE;
} }
}
$record->setUp(); $record->setUp();
@ -814,9 +811,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* @return Doctrine_Record * @return Doctrine_Record
*/ */
public function create(array $array = array()) { public function create(array $array = array()) {
$this->data = $array; $this->_data = $array;
$record = new $this->options['name']($this, true); $record = new $this->options['name']($this, true);
$this->data = array(); $this->_data = array();
return $record; return $record;
} }
/** /**
@ -925,8 +922,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/ */
public function getRecord() public function getRecord()
{ {
if ( ! empty($this->data)) { if ( ! empty($this->_data)) {
$this->data = array_change_key_case($this->data, CASE_LOWER); $this->_data = array_change_key_case($this->_data, CASE_LOWER);
$key = $this->getIdentifier(); $key = $this->getIdentifier();
@ -936,18 +933,18 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$found = false; $found = false;
foreach ($key as $k) { foreach ($key as $k) {
if ( ! isset($this->data[$k])) { if ( ! isset($this->_data[$k])) {
// primary key column not found return new record // primary key column not found return new record
$found = true; $found = true;
break; break;
} }
$id[] = $this->data[$k]; $id[] = $this->_data[$k];
} }
if ($found) { if ($found) {
$recordName = $this->getClassnameToReturn(); $recordName = $this->getClassnameToReturn();
$record = new $recordName($this, true); $record = new $recordName($this, true);
$this->data = array(); $this->_data = array();
return $record; return $record;
} }
@ -957,13 +954,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if (isset($this->_identityMap[$id])) { if (isset($this->_identityMap[$id])) {
$record = $this->_identityMap[$id]; $record = $this->_identityMap[$id];
$record->hydrate($this->data); $record->hydrate($this->_data);
} else { } else {
$recordName = $this->getClassnameToReturn(); $recordName = $this->getClassnameToReturn();
$record = new $recordName($this); $record = new $recordName($this);
$this->_identityMap[$id] = $record; $this->_identityMap[$id] = $record;
} }
$this->data = array(); $this->_data = array();
} else { } else {
$recordName = $this->getClassnameToReturn(); $recordName = $this->getClassnameToReturn();
$record = new $recordName($this, true); $record = new $recordName($this, true);
@ -997,7 +994,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$inheritanceMap = $table->getOption('inheritanceMap'); $inheritanceMap = $table->getOption('inheritanceMap');
$nomatch = false; $nomatch = false;
foreach ($inheritanceMap as $key => $value) { foreach ($inheritanceMap as $key => $value) {
if ( ! isset($this->data[$key]) || $this->data[$key] != $value) { if ( ! isset($this->_data[$key]) || $this->_data[$key] != $value) {
$nomatch = true; $nomatch = true;
break; break;
} }
@ -1023,9 +1020,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
$params = array_merge(array($id), array_values($this->options['inheritanceMap'])); $params = array_merge(array($id), array_values($this->options['inheritanceMap']));
$this->data = $this->_conn->execute($query, $params)->fetch(PDO::FETCH_ASSOC); $this->_data = $this->_conn->execute($query, $params)->fetch(PDO::FETCH_ASSOC);
if ($this->data === false) if ($this->_data === false)
return false; return false;
} }
return $this->getRecord(); return $this->getRecord();
@ -1160,7 +1157,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/ */
public function setData(array $data) public function setData(array $data)
{ {
$this->data = $data; $this->_data = $data;
} }
/** /**
* returns internal data, used by Doctrine_Record instances * returns internal data, used by Doctrine_Record instances
@ -1170,7 +1167,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/ */
public function getData() public function getData()
{ {
return $this->data; return $this->_data;
} }
/** /**
* prepareValue * prepareValue
@ -1244,14 +1241,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/ */
public function getTree() { public function getTree() {
if (isset($this->options['treeImpl'])) { if (isset($this->options['treeImpl'])) {
if ( ! $this->tree) { if ( ! $this->_tree) {
$options = isset($this->options['treeOptions']) ? $this->options['treeOptions'] : array(); $options = isset($this->options['treeOptions']) ? $this->options['treeOptions'] : array();
$this->tree = Doctrine_Tree::factory($this, $this->_tree = Doctrine_Tree::factory($this,
$this->options['treeImpl'], $this->options['treeImpl'],
$options $options
); );
} }
return $this->tree; return $this->_tree;
} }
return false; return false;
} }