Fixed indentation and other issues related to coding style
This commit is contained in:
parent
34cce3e0c8
commit
be9d359937
@ -151,17 +151,17 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
* -- treeOptions the tree options
|
* -- treeOptions the tree options
|
||||||
*/
|
*/
|
||||||
protected $options = array('name' => null,
|
protected $options = array('name' => null,
|
||||||
'tableName' => null,
|
'tableName' => null,
|
||||||
'sequenceName' => null,
|
'sequenceName' => null,
|
||||||
'inheritanceMap' => array(),
|
'inheritanceMap' => array(),
|
||||||
'enumMap' => array(),
|
'enumMap' => array(),
|
||||||
'engine' => null,
|
'engine' => null,
|
||||||
'charset' => null,
|
'charset' => null,
|
||||||
'collation' => null,
|
'collation' => null,
|
||||||
'treeImpl' => null,
|
'treeImpl' => null,
|
||||||
'treeOptions' => null,
|
'treeOptions' => null,
|
||||||
'indexes' => array(),
|
'indexes' => array(),
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* @var Doctrine_Tree $tree tree object associated with this table
|
* @var Doctrine_Tree $tree tree object associated with this table
|
||||||
*/
|
*/
|
||||||
@ -223,67 +223,67 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
$this->options['tableName'] = Doctrine::tableize($class->getName());
|
$this->options['tableName'] = Doctrine::tableize($class->getName());
|
||||||
}
|
}
|
||||||
switch (count($this->primaryKeys)) {
|
switch (count($this->primaryKeys)) {
|
||||||
case 0:
|
case 0:
|
||||||
$this->columns = array_merge(array('id' =>
|
$this->columns = array_merge(array('id' =>
|
||||||
array('integer',
|
array('integer',
|
||||||
20,
|
20,
|
||||||
array('autoincrement' => true,
|
array('autoincrement' => true,
|
||||||
'primary' => true,
|
'primary' => true,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
), $this->columns);
|
), $this->columns);
|
||||||
|
|
||||||
$this->primaryKeys[] = 'id';
|
$this->primaryKeys[] = 'id';
|
||||||
$this->identifier = 'id';
|
$this->identifier = 'id';
|
||||||
$this->identifierType = Doctrine_Identifier::AUTO_INCREMENT;
|
$this->identifierType = Doctrine_Identifier::AUTO_INCREMENT;
|
||||||
$this->columnCount++;
|
$this->columnCount++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (count($this->primaryKeys) > 1) {
|
if (count($this->primaryKeys) > 1) {
|
||||||
$this->identifier = $this->primaryKeys;
|
$this->identifier = $this->primaryKeys;
|
||||||
$this->identifierType = Doctrine_Identifier::COMPOSITE;
|
$this->identifierType = Doctrine_Identifier::COMPOSITE;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
foreach ($this->primaryKeys as $pk) {
|
foreach ($this->primaryKeys as $pk) {
|
||||||
$e = $this->columns[$pk][2];
|
$e = $this->columns[$pk][2];
|
||||||
|
|
||||||
$found = false;
|
$found = false;
|
||||||
|
|
||||||
foreach ($e as $option => $value) {
|
foreach ($e as $option => $value) {
|
||||||
if ($found)
|
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::AUTO_INCREMENT;
|
$this->identifierType = Doctrine_Identifier::AUTO_INCREMENT;
|
||||||
$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 {
|
} else {
|
||||||
if (($sequence = $this->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
|
if (($sequence = $this->getAttribute(Doctrine::ATTR_DEFAULT_SEQUENCE)) !== null) {
|
||||||
$this->options['sequenceName'] = $sequence;
|
$this->options['sequenceName'] = $sequence;
|
||||||
} else {
|
} else {
|
||||||
$this->options['sequenceName'] = $this->conn->getSequenceName($this->options['tableName']);
|
$this->options['sequenceName'] = $this->conn->getSequenceName($this->options['tableName']);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if ( ! isset($this->identifierType)) {
|
|
||||||
$this->identifierType = Doctrine_Identifier::NORMAL;
|
|
||||||
}
|
|
||||||
$this->identifier = $pk;
|
|
||||||
}
|
}
|
||||||
|
if ( ! isset($this->identifierType)) {
|
||||||
|
$this->identifierType = Doctrine_Identifier::NORMAL;
|
||||||
|
}
|
||||||
|
$this->identifier = $pk;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
if ( ! isset($definition['values'])) {
|
if ( ! isset($definition['values'])) {
|
||||||
@ -294,7 +294,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
throw new Doctrine_Table_Exception('Enum column values should be specified as an array.');
|
throw new Doctrine_Table_Exception('Enum column values should be specified as an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -343,16 +343,16 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
$definition['length'] = $column[1];
|
$definition['length'] = $column[1];
|
||||||
|
|
||||||
switch ($definition['type']) {
|
switch ($definition['type']) {
|
||||||
case 'enum':
|
case 'enum':
|
||||||
if (isset($definition['default'])) {
|
if (isset($definition['default'])) {
|
||||||
$definition['default'] = $this->enumIndex($name, $definition['default']);
|
$definition['default'] = $this->enumIndex($name, $definition['default']);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
if (isset($definition['default'])) {
|
if (isset($definition['default'])) {
|
||||||
$definition['default'] = (int) $definition['default'];
|
$definition['default'] = (int) $definition['default'];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$columns[$name] = $definition;
|
$columns[$name] = $definition;
|
||||||
|
|
||||||
@ -399,8 +399,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
*/
|
*/
|
||||||
public function exportConstraints()
|
public function exportConstraints()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->conn->beginTransaction();
|
$this->conn->beginTransaction();
|
||||||
|
|
||||||
foreach ($this->options['index'] as $index => $definition) {
|
foreach ($this->options['index'] as $index => $definition) {
|
||||||
$this->conn->export->createIndex($this->options['tableName'], $index, $definition);
|
$this->conn->export->createIndex($this->options['tableName'], $index, $definition);
|
||||||
@ -454,7 +454,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
*/
|
*/
|
||||||
public function addIndex($index, array $definition)
|
public function addIndex($index, array $definition)
|
||||||
{
|
{
|
||||||
$index = $this->conn->getIndexName($index);
|
$index = $this->conn->getIndexName($index);
|
||||||
$this->options['indexes'][$index] = $definition;
|
$this->options['indexes'][$index] = $definition;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -494,17 +494,17 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
public function setOption($name, $value)
|
public function setOption($name, $value)
|
||||||
{
|
{
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
case 'name':
|
case 'name':
|
||||||
case 'tableName':
|
case 'tableName':
|
||||||
break;
|
break;
|
||||||
case 'enumMap':
|
case 'enumMap':
|
||||||
case 'inheritanceMap':
|
case 'inheritanceMap':
|
||||||
case 'index':
|
case 'index':
|
||||||
case 'treeOptions':
|
case 'treeOptions':
|
||||||
if ( ! is_array($value)) {
|
if ( ! is_array($value)) {
|
||||||
throw new Doctrine_Table_Exception($name . ' should be an array.');
|
throw new Doctrine_Table_Exception($name . ' should be an array.');
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->options[$name] = $value;
|
$this->options[$name] = $value;
|
||||||
}
|
}
|
||||||
@ -642,12 +642,12 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
final public function setPrimaryKey($key)
|
final public function setPrimaryKey($key)
|
||||||
{
|
{
|
||||||
switch (gettype($key)) {
|
switch (gettype($key)) {
|
||||||
case "array":
|
case "array":
|
||||||
$this->primaryKeys = array_values($key);
|
$this->primaryKeys = array_values($key);
|
||||||
break;
|
break;
|
||||||
case "string":
|
case "string":
|
||||||
$this->primaryKeys[] = $key;
|
$this->primaryKeys[] = $key;
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -737,9 +737,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
*/
|
*/
|
||||||
public function unbindAll()
|
public function unbindAll()
|
||||||
{ throw new Exception();
|
{ throw new Exception();
|
||||||
$this->bound = array();
|
$this->bound = array();
|
||||||
$this->relations = array();
|
$this->relations = array();
|
||||||
$this->boundAliases = array();
|
$this->boundAliases = array();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* unbinds a relation
|
* unbinds a relation
|
||||||
@ -793,9 +793,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->bound[$alias] = array('field' => $field,
|
$this->bound[$alias] = array('field' => $field,
|
||||||
'type' => $type,
|
'type' => $type,
|
||||||
'class' => $name,
|
'class' => $name,
|
||||||
'alias' => $alias);
|
'alias' => $alias);
|
||||||
if ($options !== null) {
|
if ($options !== null) {
|
||||||
$opt = array();
|
$opt = array();
|
||||||
if (is_string($options)) {
|
if (is_string($options)) {
|
||||||
@ -820,7 +820,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
*/
|
*/
|
||||||
final public function hasRelatedComponent($name, $component)
|
final public function hasRelatedComponent($name, $component)
|
||||||
{
|
{
|
||||||
return (strpos($this->bound[$name]['field'], $component . '.') !== false);
|
return (strpos($this->bound[$name]['field'], $component . '.') !== false);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param string $name component name of which a foreign key object is bound
|
* @param string $name component name of which a foreign key object is bound
|
||||||
@ -871,120 +871,120 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
// ONE-TO-ONE
|
// ONE-TO-ONE
|
||||||
if ($definition['type'] == Doctrine_Relation::ONE_COMPOSITE ||
|
if ($definition['type'] == Doctrine_Relation::ONE_COMPOSITE ||
|
||||||
$definition['type'] == Doctrine_Relation::ONE_AGGREGATE) {
|
$definition['type'] == Doctrine_Relation::ONE_AGGREGATE) {
|
||||||
// tree structure parent relation found
|
// tree structure parent relation found
|
||||||
|
|
||||||
if ( ! isset($definition['local'])) {
|
if ( ! isset($definition['local'])) {
|
||||||
$definition['local'] = $definition['foreign'];
|
$definition['local'] = $definition['foreign'];
|
||||||
$definition['foreign'] = $definition['table']->getIdentifier();
|
$definition['foreign'] = $definition['table']->getIdentifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
$relation = new Doctrine_Relation_LocalKey($definition);
|
$relation = new Doctrine_Relation_LocalKey($definition);
|
||||||
|
|
||||||
} else {
|
|
||||||
// tree structure children relation found
|
|
||||||
|
|
||||||
if ( ! isset($definition['local'])) {
|
|
||||||
$tmp = $definition['table']->getIdentifier();
|
|
||||||
|
|
||||||
$definition['local'] = $tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
//$definition['foreign'] = $tmp;
|
|
||||||
$definition['constraint'] = true;
|
|
||||||
|
|
||||||
$relation = new Doctrine_Relation_ForeignKey($definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
} elseif ($component == $definition['class'] ||
|
|
||||||
($component == $definition['alias'])) { // && ($name == $this->options['name'] || in_array($name,$this->parents))
|
|
||||||
|
|
||||||
if ( ! isset($defintion['local'])) {
|
|
||||||
$definition['local'] = $this->identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
$definition['constraint'] = true;
|
|
||||||
|
|
||||||
// ONE-TO-MANY or ONE-TO-ONE
|
|
||||||
$relation = new Doctrine_Relation_ForeignKey($definition);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// MANY-TO-MANY
|
|
||||||
// only aggregate relations allowed
|
|
||||||
|
|
||||||
if ($definition['type'] != Doctrine_Relation::MANY_AGGREGATE) {
|
|
||||||
throw new Doctrine_Table_Exception("Only aggregate relations are allowed for many-to-many relations");
|
|
||||||
}
|
|
||||||
|
|
||||||
$classes = array_merge($this->options['parents'], array($this->options['name']));
|
|
||||||
|
|
||||||
foreach (array_reverse($classes) as $class) {
|
|
||||||
try {
|
|
||||||
$bound = $definition['table']->getBoundForName($class, $component);
|
|
||||||
break;
|
|
||||||
} catch(Doctrine_Table_Exception $exc) { }
|
|
||||||
}
|
|
||||||
if ( ! isset($bound)) {
|
|
||||||
throw new Doctrine_Table_Exception("Couldn't map many-to-many relation for "
|
|
||||||
. $this->options['name'] . " and $name. Components use different join tables.");
|
|
||||||
}
|
|
||||||
if ( ! isset($definition['local'])) {
|
|
||||||
$definition['local'] = $this->identifier;
|
|
||||||
}
|
|
||||||
$e2 = explode('.', $bound['field']);
|
|
||||||
$fields = explode('-', $e2[1]);
|
|
||||||
|
|
||||||
if ($e2[0] != $component) {
|
|
||||||
throw new Doctrine_Table_Exception($e2[0] . ' doesn\'t match ' . $component);
|
|
||||||
}
|
|
||||||
$associationTable = $this->conn->getTable($e2[0], $allowExport);
|
|
||||||
|
|
||||||
if (count($fields) > 1) {
|
|
||||||
// SELF-REFERENCING THROUGH JOIN TABLE
|
|
||||||
|
|
||||||
$def['table'] = $associationTable;
|
|
||||||
$def['local'] = $this->identifier;
|
|
||||||
$def['foreign'] = $fields[0];
|
|
||||||
$def['alias'] = $e2[0];
|
|
||||||
$def['class'] = $e2[0];
|
|
||||||
$def['type'] = Doctrine_Relation::MANY_COMPOSITE;
|
|
||||||
|
|
||||||
$this->relations[$e2[0]] = new Doctrine_Relation_ForeignKey($def);
|
|
||||||
|
|
||||||
$definition['assocTable'] = $associationTable;
|
|
||||||
$definition['local'] = $fields[0];
|
|
||||||
$definition['foreign'] = $fields[1];
|
|
||||||
$relation = new Doctrine_Relation_Association_Self($definition);
|
|
||||||
} else {
|
|
||||||
if($definition['table'] === $this) {
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// auto initialize a new one-to-one relationships for association table
|
// tree structure children relation found
|
||||||
$associationTable->bind($this->getComponentName(),
|
|
||||||
$associationTable->getComponentName(). '.' . $e2[1],
|
|
||||||
Doctrine_Relation::ONE_AGGREGATE
|
|
||||||
);
|
|
||||||
|
|
||||||
$associationTable->bind($definition['table']->getComponentName(),
|
if ( ! isset($definition['local'])) {
|
||||||
$associationTable->getComponentName(). '.' . $definition['foreign'],
|
$tmp = $definition['table']->getIdentifier();
|
||||||
Doctrine_Relation::ONE_AGGREGATE
|
|
||||||
);
|
|
||||||
|
|
||||||
// NORMAL MANY-TO-MANY RELATIONSHIP
|
$definition['local'] = $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
//$definition['foreign'] = $tmp;
|
||||||
|
$definition['constraint'] = true;
|
||||||
|
|
||||||
|
$relation = new Doctrine_Relation_ForeignKey($definition);
|
||||||
|
}
|
||||||
|
|
||||||
|
} elseif ($component == $definition['class'] ||
|
||||||
|
($component == $definition['alias'])) { // && ($name == $this->options['name'] || in_array($name,$this->parents))
|
||||||
|
|
||||||
|
if ( ! isset($defintion['local'])) {
|
||||||
|
$definition['local'] = $this->identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
$definition['constraint'] = true;
|
||||||
|
|
||||||
|
// ONE-TO-MANY or ONE-TO-ONE
|
||||||
|
$relation = new Doctrine_Relation_ForeignKey($definition);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// MANY-TO-MANY
|
||||||
|
// only aggregate relations allowed
|
||||||
|
|
||||||
|
if ($definition['type'] != Doctrine_Relation::MANY_AGGREGATE) {
|
||||||
|
throw new Doctrine_Table_Exception("Only aggregate relations are allowed for many-to-many relations");
|
||||||
|
}
|
||||||
|
|
||||||
|
$classes = array_merge($this->options['parents'], array($this->options['name']));
|
||||||
|
|
||||||
|
foreach (array_reverse($classes) as $class) {
|
||||||
|
try {
|
||||||
|
$bound = $definition['table']->getBoundForName($class, $component);
|
||||||
|
break;
|
||||||
|
} catch(Doctrine_Table_Exception $exc) { }
|
||||||
|
}
|
||||||
|
if ( ! isset($bound)) {
|
||||||
|
throw new Doctrine_Table_Exception("Couldn't map many-to-many relation for "
|
||||||
|
. $this->options['name'] . " and $name. Components use different join tables.");
|
||||||
|
}
|
||||||
|
if ( ! isset($definition['local'])) {
|
||||||
|
$definition['local'] = $this->identifier;
|
||||||
|
}
|
||||||
|
$e2 = explode('.', $bound['field']);
|
||||||
|
$fields = explode('-', $e2[1]);
|
||||||
|
|
||||||
|
if ($e2[0] != $component) {
|
||||||
|
throw new Doctrine_Table_Exception($e2[0] . ' doesn\'t match ' . $component);
|
||||||
|
}
|
||||||
|
$associationTable = $this->conn->getTable($e2[0], $allowExport);
|
||||||
|
|
||||||
|
if (count($fields) > 1) {
|
||||||
|
// SELF-REFERENCING THROUGH JOIN TABLE
|
||||||
|
|
||||||
$def['table'] = $associationTable;
|
$def['table'] = $associationTable;
|
||||||
$def['foreign'] = $e2[1];
|
$def['local'] = $this->identifier;
|
||||||
$def['local'] = $definition['local'];
|
$def['foreign'] = $fields[0];
|
||||||
$def['alias'] = $e2[0];
|
$def['alias'] = $e2[0];
|
||||||
$def['class'] = $e2[0];
|
$def['class'] = $e2[0];
|
||||||
$def['type'] = Doctrine_Relation::MANY_COMPOSITE;
|
$def['type'] = Doctrine_Relation::MANY_COMPOSITE;
|
||||||
|
|
||||||
$this->relations[$e2[0]] = new Doctrine_Relation_ForeignKey($def);
|
$this->relations[$e2[0]] = new Doctrine_Relation_ForeignKey($def);
|
||||||
|
|
||||||
$definition['local'] = $e2[1];
|
|
||||||
$definition['assocTable'] = $associationTable;
|
$definition['assocTable'] = $associationTable;
|
||||||
$relation = new Doctrine_Relation_Association($definition);
|
$definition['local'] = $fields[0];
|
||||||
|
$definition['foreign'] = $fields[1];
|
||||||
|
$relation = new Doctrine_Relation_Association_Self($definition);
|
||||||
|
} else {
|
||||||
|
if($definition['table'] === $this) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// auto initialize a new one-to-one relationships for association table
|
||||||
|
$associationTable->bind($this->getComponentName(),
|
||||||
|
$associationTable->getComponentName(). '.' . $e2[1],
|
||||||
|
Doctrine_Relation::ONE_AGGREGATE
|
||||||
|
);
|
||||||
|
|
||||||
|
$associationTable->bind($definition['table']->getComponentName(),
|
||||||
|
$associationTable->getComponentName(). '.' . $definition['foreign'],
|
||||||
|
Doctrine_Relation::ONE_AGGREGATE
|
||||||
|
);
|
||||||
|
|
||||||
|
// NORMAL MANY-TO-MANY RELATIONSHIP
|
||||||
|
|
||||||
|
$def['table'] = $associationTable;
|
||||||
|
$def['foreign'] = $e2[1];
|
||||||
|
$def['local'] = $definition['local'];
|
||||||
|
$def['alias'] = $e2[0];
|
||||||
|
$def['class'] = $e2[0];
|
||||||
|
$def['type'] = Doctrine_Relation::MANY_COMPOSITE;
|
||||||
|
$this->relations[$e2[0]] = new Doctrine_Relation_ForeignKey($def);
|
||||||
|
|
||||||
|
$definition['local'] = $e2[1];
|
||||||
|
$definition['assocTable'] = $associationTable;
|
||||||
|
$relation = new Doctrine_Relation_Association($definition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->relations[$name] = $relation;
|
$this->relations[$name] = $relation;
|
||||||
|
|
||||||
@ -1145,8 +1145,8 @@ 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];
|
||||||
} 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();
|
||||||
@ -1154,43 +1154,41 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
return $record;
|
return $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the classname to return. Most often this is just the options['name']
|
* Get the classname to return. Most often this is just the options['name']
|
||||||
*
|
*
|
||||||
* Check the subclasses option and the inheritanceMap for each subclass to see
|
* Check the subclasses option and the inheritanceMap for each subclass to see
|
||||||
* if all the maps in a subclass is met. If this is the case return that
|
* if all the maps in a subclass is met. If this is the case return that
|
||||||
* subclass name. If no subclasses match or if there are no subclasses defined
|
* subclass name. If no subclasses match or if there are no subclasses defined
|
||||||
* return the name of the class for this tables record.
|
* return the name of the class for this tables record.
|
||||||
*
|
*
|
||||||
* @todo this function could use reflection to check the first time it runs
|
* @todo this function could use reflection to check the first time it runs
|
||||||
* if the subclassing option is not set.
|
* if the subclassing option is not set.
|
||||||
*
|
*
|
||||||
* @return string The name of the class to create
|
* @return string The name of the class to create
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getClassnameToReturn()
|
public function getClassnameToReturn()
|
||||||
{
|
{
|
||||||
if(!isset($this->options["subclasses"])){
|
if (!isset($this->options["subclasses"])) {
|
||||||
return $this->options['name'];
|
return $this->options['name'];
|
||||||
}
|
}
|
||||||
foreach($this->options["subclasses"] as $subclass){
|
foreach ($this->options["subclasses"] as $subclass) {
|
||||||
$table = $this->conn->getTable($subclass);
|
$table = $this->conn->getTable($subclass);
|
||||||
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!$nomatch){
|
if (!$nomatch) {
|
||||||
return $table->getComponentName();
|
return $table->getComponentName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->options['name'];
|
return $this->options['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $id database row id
|
* @param $id database row id
|
||||||
@ -1200,8 +1198,8 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
{
|
{
|
||||||
if ($id !== null) {
|
if ($id !== null) {
|
||||||
$query = 'SELECT ' . implode(', ',$this->primaryKeys)
|
$query = 'SELECT ' . implode(', ',$this->primaryKeys)
|
||||||
. ' FROM ' . $this->getTableName()
|
. ' FROM ' . $this->getTableName()
|
||||||
. ' WHERE ' . implode(' = ? && ',$this->primaryKeys).' = ?';
|
. ' WHERE ' . implode(' = ? && ',$this->primaryKeys).' = ?';
|
||||||
$query = $this->applyInheritance($query);
|
$query = $this->applyInheritance($query);
|
||||||
|
|
||||||
$params = array_merge(array($id), array_values($this->options['inheritanceMap']));
|
$params = array_merge(array($id), array_values($this->options['inheritanceMap']));
|
||||||
@ -1460,9 +1458,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -32,36 +32,35 @@
|
|||||||
*/
|
*/
|
||||||
class Doctrine_ColumnAggregationInheritance_TestCase extends Doctrine_UnitTestCase
|
class Doctrine_ColumnAggregationInheritance_TestCase extends Doctrine_UnitTestCase
|
||||||
{
|
{
|
||||||
protected $otherEntity = null;
|
protected $otherEntity = null;
|
||||||
|
|
||||||
public function prepareData()
|
public function prepareData()
|
||||||
{
|
{
|
||||||
|
|
||||||
parent::prepareData();
|
parent::prepareData();
|
||||||
//we create a test entity that is not a user and not a group
|
//we create a test entity that is not a user and not a group
|
||||||
$entity = new Entity();
|
$entity = new Entity();
|
||||||
$entity->name="Other Entity";
|
$entity->name='Other Entity';
|
||||||
$entity->type = 2;
|
$entity->type = 2;
|
||||||
$entity->save();
|
$entity->save();
|
||||||
$this->otherEntity = $entity;
|
$this->otherEntity = $entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueriedClassReturnedIfNoSubclassMatch()
|
public function testQueriedClassReturnedIfNoSubclassMatch()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query();
|
||||||
$entityOther = $q->from("Entity")->where("id=?")->execute(array($this->otherEntity->id))->getFirst();
|
$entityOther = $q->from('Entity')->where('id=?')->execute(array($this->otherEntity->id))->getFirst();
|
||||||
$this->assertTrue($entityOther instanceOf Entity);
|
$this->assertTrue($entityOther instanceOf Entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSubclassReturnedIfInheritanceMatches()
|
public function testSubclassReturnedIfInheritanceMatches()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query();
|
||||||
$group = $q->from("Entity")->where("id=?")->execute(array(1))->getFirst();
|
$group = $q->from('Entity')->where('id=?')->execute(array(1))->getFirst();
|
||||||
$this->assertTrue($group instanceOf Group);
|
$this->assertTrue($group instanceOf Group);
|
||||||
|
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query();
|
||||||
$user = $q->from("Entity")->where("id=?")->execute(array(5))->getFirst();
|
$user = $q->from('Entity')->where('id=?')->execute(array(5))->getFirst();
|
||||||
$this->assertTrue($user instanceOf User);
|
$this->assertTrue($user instanceOf User);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user