refactoring the table class
This commit is contained in:
parent
2169cbe95e
commit
e24d9c69dd
@ -36,11 +36,11 @@ 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
|
||||||
*/
|
*/
|
||||||
private $primaryKeys = array();
|
private $primaryKeys = array();
|
||||||
/**
|
/**
|
||||||
* @var mixed $identifier
|
* @var mixed $identifier
|
||||||
*/
|
*/
|
||||||
@ -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,55 +237,52 @@ 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) {
|
foreach ($this->primaryKeys as $pk) {
|
||||||
$this->_identifier = $this->primaryKeys;
|
$e = $this->columns[$pk];
|
||||||
$this->_identifierType = Doctrine::IDENTIFIER_COMPOSITE;
|
|
||||||
|
|
||||||
} else {
|
$found = false;
|
||||||
foreach ($this->primaryKeys as $pk) {
|
|
||||||
$e = $this->columns[$pk];
|
|
||||||
|
|
||||||
$found = false;
|
foreach ($e as $option => $value) {
|
||||||
|
if ($found)
|
||||||
foreach ($e as $option => $value) {
|
|
||||||
if ($found)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
$e2 = explode(':', $option);
|
$e2 = explode(':', $option);
|
||||||
|
|
||||||
switch (strtolower($e2[0])) {
|
switch (strtolower($e2[0])) {
|
||||||
case 'autoincrement':
|
case 'autoincrement':
|
||||||
case 'autoinc':
|
case 'autoinc':
|
||||||
$this->_identifierType = Doctrine::IDENTIFIER_AUTOINC;
|
$this->_identifierType = Doctrine::IDENTIFIER_AUTOINC;
|
||||||
$found = true;
|
$found = true;
|
||||||
break;
|
break;
|
||||||
case 'seq':
|
case 'seq':
|
||||||
case 'sequence':
|
case 'sequence':
|
||||||
$this->_identifierType = Doctrine::IDENTIFIER_SEQUENCE;
|
$this->_identifierType = Doctrine::IDENTIFIER_SEQUENCE;
|
||||||
$found = true;
|
$found = true;
|
||||||
|
|
||||||
if ($value) {
|
if ($value) {
|
||||||
$this->options['sequenceName'] = $value;
|
$this->options['sequenceName'] = $value;
|
||||||
|
} else {
|
||||||
|
if (($sequence = $this->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
|
||||||
|
$this->options['sequenceName'] = $sequence;
|
||||||
} else {
|
} else {
|
||||||
if (($sequence = $this->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
|
$this->options['sequenceName'] = $this->_conn->getSequenceName($this->options['tableName']);
|
||||||
$this->options['sequenceName'] = $sequence;
|
|
||||||
} else {
|
|
||||||
$this->options['sequenceName'] = $this->_conn->getSequenceName($this->options['tableName']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
if ( ! isset($this->_identifierType)) {
|
|
||||||
$this->_identifierType = Doctrine::IDENTIFIER_NATURAL;
|
|
||||||
}
|
|
||||||
$this->_identifier = $pk;
|
|
||||||
}
|
}
|
||||||
}
|
if ( ! isset($this->_identifierType)) {
|
||||||
|
$this->_identifierType = Doctrine::IDENTIFIER_NATURAL;
|
||||||
|
}
|
||||||
|
$this->_identifier = $pk;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$this->_identifier = $this->primaryKeys;
|
||||||
|
$this->_identifierType = Doctrine::IDENTIFIER_COMPOSITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$record->setUp();
|
$record->setUp();
|
||||||
|
|
||||||
// if tree, set up tree
|
// if tree, set up tree
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user