Commit c43f9588 authored by romanb's avatar romanb

Cleanups, improvements, fixes.

parent 3cd7b954
...@@ -540,14 +540,12 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -540,14 +540,12 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
} }
/** /**
* getColumnName * Gets a column name for a field name.
* If the column name for the field cannot be found, the given field name
* is returned.
* *
* returns a column name for a field name. * @param string $alias The field name.
* if the column name for the field cannot be found * @return string The column name.
* this method returns the given field name.
*
* @param string $alias column alias
* @return string column name
*/ */
public function getColumnName($fieldName) public function getColumnName($fieldName)
{ {
...@@ -556,18 +554,29 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -556,18 +554,29 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
} }
/** /**
* @deprecated * Gets the mapping of a (regular) fields that holds some data but not a
* reference to another object.
*
* @param string $fieldName The field name.
* @return array The mapping.
*/ */
public function getColumnDefinition($columnName)
{
return $this->getColumnMapping($columnName);
}
public function getFieldMapping($fieldName) public function getFieldMapping($fieldName)
{ {
return isset($this->_fieldMappings[$fieldName]) ? return isset($this->_fieldMappings[$fieldName]) ?
$this->_fieldMappings[$fieldName] : false; $this->_fieldMappings[$fieldName] : false;
} }
/**
* Gets the mapping of an association.
*
* @param string $fieldName The field name that represents the association in
* the object model.
* @return Doctrine::ORM::Mapping::AssociationMapping The mapping.
*/
public function getAssociationMapping($fieldName)
{
//...
}
/** /**
* Gets the field name for a column name. * Gets the field name for a column name.
...@@ -588,6 +597,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -588,6 +597,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* *
* @param string $lcColumnName * @param string $lcColumnName
* @return string * @return string
* @todo Better name.
*/ */
public function getFieldNameForLowerColumnName($lcColumnName) public function getFieldNameForLowerColumnName($lcColumnName)
{ {
...@@ -640,16 +650,6 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -640,16 +650,6 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
throw new Doctrine_ClassMetadata_Exception("No field name found for column name '$lcColumnName' during lookup."); throw new Doctrine_ClassMetadata_Exception("No field name found for column name '$lcColumnName' during lookup.");
} }
/**
* @deprecated
*/
public function setColumns(array $definitions)
{
foreach ($definitions as $name => $options) {
$this->setColumn($name, $options['type'], $options['length'], $options);
}
}
/** /**
* Maps a field of the class to a database column. * Maps a field of the class to a database column.
* *
...@@ -663,6 +663,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -663,6 +663,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* By default the column gets appended. * By default the column gets appended.
* *
* @throws Doctrine_ClassMetadata_Exception If trying use wrongly typed parameter. * @throws Doctrine_ClassMetadata_Exception If trying use wrongly typed parameter.
* @todo Rename to mapField()/addFieldMapping().
*/ */
public function mapColumn($name, $type, $length = null, $options = array()) public function mapColumn($name, $type, $length = null, $options = array())
{ {
...@@ -783,14 +784,14 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -783,14 +784,14 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
} }
/** /**
* Checks whether the class mapped class has a default value on any field. * Checks whether the mapped class has a default value on any field.
* *
* @return boolean TRUE if the entity has a default value on any field, otherwise false. * @return boolean TRUE if the entity has a default value on any field, otherwise false.
*/ */
public function hasDefaultValues() /*public function hasDefaultValues()
{ {
return $this->_hasDefaultValues; return $this->_hasDefaultValues;
} }*/
/** /**
* getDefaultValueOf * getDefaultValueOf
...@@ -799,7 +800,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -799,7 +800,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* @param string $fieldName * @param string $fieldName
* @return mixed * @return mixed
*/ */
public function getDefaultValueOf($fieldName) /*public function getDefaultValueOf($fieldName)
{ {
if ( ! isset($this->_fieldMappings[$fieldName])) { if ( ! isset($this->_fieldMappings[$fieldName])) {
throw new Doctrine_Table_Exception("Couldn't get default value. Column ".$fieldName." doesn't exist."); throw new Doctrine_Table_Exception("Couldn't get default value. Column ".$fieldName." doesn't exist.");
...@@ -809,10 +810,10 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -809,10 +810,10 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
} else { } else {
return null; return null;
} }
} }*/
/** /**
* Gets the identifier (primary key) field(s) of the mapped class. * Gets the identifier (primary key) field names of the class.
* *
* @return mixed * @return mixed
* @deprecated Use getIdentifierFieldNames() * @deprecated Use getIdentifierFieldNames()
...@@ -823,7 +824,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -823,7 +824,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
} }
/** /**
* Gets the identifier (primary key) field(s) of the mapped class. * Gets the identifier (primary key) field names of the class.
* *
* @return mixed * @return mixed
*/ */
...@@ -839,8 +840,11 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -839,8 +840,11 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
/** /**
* Gets the type of the identifier (primary key) used by the mapped class. The type * Gets the type of the identifier (primary key) used by the mapped class. The type
* can be either <tt>Doctrine::IDENTIFIER_NATURAL</tt>, <tt>Doctrine::IDENTIFIER_AUTOINCREMENT</tt>, * can be either
* <tt>Doctrine::IDENTIFIER_SEQUENCE</tt> or <tt>Doctrine::IDENTIFIER_COMPOSITE</tt>. * <tt>Doctrine::IDENTIFIER_NATURAL</tt>,
* <tt>Doctrine::IDENTIFIER_AUTOINCREMENT</tt>,
* <tt>Doctrine::IDENTIFIER_SEQUENCE</tt> or
* <tt>Doctrine::IDENTIFIER_COMPOSITE</tt>.
* *
* @return integer * @return integer
*/ */
...@@ -857,16 +861,6 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -857,16 +861,6 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
$this->_identifierType = $type; $this->_identifierType = $type;
} }
/**
* hasColumn
* @return boolean
* @deprecated
*/
public function hasColumn($columnName)
{
return isset($this->_fieldNames[$columnName]);
}
public function hasMappedColumn($columnName) public function hasMappedColumn($columnName)
{ {
return isset($this->_fieldNames[$columnName]); return isset($this->_fieldNames[$columnName]);
...@@ -885,14 +879,14 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -885,14 +879,14 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* @param string $fieldName * @param string $fieldName
* @return array * @return array
*/ */
public function getEnumValues($fieldName) /*public function getEnumValues($fieldName)
{ {
if (isset($this->_fieldMappings[$fieldName]['values'])) { if (isset($this->_fieldMappings[$fieldName]['values'])) {
return $this->_fieldMappings[$fieldName]['values']; return $this->_fieldMappings[$fieldName]['values'];
} else { } else {
return array(); return array();
} }
} }*/
/** /**
* enumValue * enumValue
...@@ -901,7 +895,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -901,7 +895,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* @param integer $index * @param integer $index
* @return mixed * @return mixed
*/ */
public function enumValue($fieldName, $index) /*public function enumValue($fieldName, $index)
{ {
if ($index instanceof Doctrine_Null) { if ($index instanceof Doctrine_Null) {
return $index; return $index;
...@@ -921,7 +915,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -921,7 +915,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
$this->_enumValues[$fieldName][$index] = $enumValue; $this->_enumValues[$fieldName][$index] = $enumValue;
return $enumValue; return $enumValue;
} }*/
/** /**
* enumIndex * enumIndex
...@@ -930,7 +924,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -930,7 +924,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* @param mixed $value * @param mixed $value
* @return mixed * @return mixed
*/ */
public function enumIndex($fieldName, $value) /*public function enumIndex($fieldName, $value)
{ {
$values = $this->getEnumValues($fieldName); $values = $this->getEnumValues($fieldName);
$index = array_search($value, $values); $index = array_search($value, $values);
...@@ -939,7 +933,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -939,7 +933,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
} }
return $value; return $value;
} }*/
/** /**
* getColumnCount * getColumnCount
...@@ -947,23 +941,24 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -947,23 +941,24 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* @return integer the number of columns in this table * @return integer the number of columns in this table
* @deprecated * @deprecated
*/ */
public function getColumnCount() /*public function getColumnCount()
{ {
return $this->_columnCount; return $this->_columnCount;
} }*/
/** /**
* getMappedColumnCount * getMappedColumnCount
* *
* @return integer the number of mapped columns in the class. * @return integer the number of mapped columns in the class.
*/ */
public function getMappedColumnCount() public function getMappedFieldCount()
{ {
return $this->_columnCount; return $this->_columnCount;
} }
/** /**
* * Gets the custom accessor of a field.
*
* @return string The name of the accessor (getter) method or NULL if the field does * @return string The name of the accessor (getter) method or NULL if the field does
* not have a custom accessor. * not have a custom accessor.
*/ */
...@@ -974,7 +969,8 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -974,7 +969,8 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
} }
/** /**
* * Gets the custom mutator of a field.
*
* @return string The name of the mutator (setter) method or NULL if the field does * @return string The name of the mutator (setter) method or NULL if the field does
* not have a custom mutator. * not have a custom mutator.
*/ */
...@@ -983,28 +979,12 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -983,28 +979,12 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
return isset($this->_fieldMappings[$fieldName]['mutator']) ? return isset($this->_fieldMappings[$fieldName]['mutator']) ?
$this->_fieldMappings[$fieldName]['mutator'] : null; $this->_fieldMappings[$fieldName]['mutator'] : null;
} }
/**
* returns all columns and their definitions
*
* @return array
* @deprecated
*/
public function getColumns()
{
return $this->_fieldMappings;
}
/** /**
* Gets all mapped columns and their mapping definitions. * Gets all field mappings.
* *
* @return array * @return unknown
*/ */
public function getMappedColumns()
{
return $this->_fieldMappings;
}
public function getFieldMappings() public function getFieldMappings()
{ {
return $this->_fieldMappings; return $this->_fieldMappings;
...@@ -1016,7 +996,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -1016,7 +996,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* *
* @return boolean * @return boolean
*/ */
public function removeColumn($fieldName) /*public function removeColumn($fieldName)
{ {
$columnName = array_search($fieldName, $this->_fieldNames); $columnName = array_search($fieldName, $this->_fieldNames);
...@@ -1029,7 +1009,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -1029,7 +1009,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
$this->_columnCount--; $this->_columnCount--;
return false; return false;
} }*/
/** /**
* returns an array containing all the column names. * returns an array containing all the column names.
...@@ -1076,35 +1056,12 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -1076,35 +1056,12 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* @return mixed array on success, false on failure * @return mixed array on success, false on failure
* @deprecated * @deprecated
*/ */
public function getDefinitionOf($fieldName) /*public function getDefinitionOf($fieldName)
{ {
$columnName = $this->getColumnName($fieldName); $columnName = $this->getColumnName($fieldName);
return $this->getColumnDefinition($columnName); return $this->getColumnDefinition($columnName);
} }*/
/**
* Gets the mapping information for a field.
*
* @param string $fieldName
* @return array
*/
public function getMappingForField($fieldName)
{
return $this->_fieldMappings[$fieldName];
}
/**
* getTypeOf
*
* @return mixed string on success, false on failure
* @deprecated
*/
public function getTypeOf($fieldName)
{
return $this->getTypeOfColumn($this->getColumnName($fieldName));
}
/** /**
* Gets the type of a field. * Gets the type of a field.
...@@ -1163,72 +1120,6 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -1163,72 +1120,6 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
//... //...
} }
public function bindRelation($args, $type)
{
return $this->bind($args, $type);
}
/**
* DESCRIBE WHAT THIS METHOD DOES, PLEASE!
*
* @todo Name proposal: addRelation
*/
public function bind($args, $type)
{
$options = array();
$options['type'] = $type;
if ( ! isset($args[1])) {
$args[1] = array();
}
if ( ! is_array($args[1])) {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString();
}
}
$options = array_merge($args[1], $options);
$this->_parser->bind($args[0], $options);
}
/**
* hasRelation
*
* @param string $alias the relation to check if exists
* @return boolean true if the relation exists otherwise false
*/
public function hasRelation($alias)
{
return $this->_parser->hasRelation($alias);
}
/**
* getRelation
*
* @param string $alias relation alias
*/
public function getRelation($alias, $recursive = true)
{
return $this->_parser->getRelation($alias, $recursive);
}
public function getRelationParser()
{
return $this->_parser;
}
/**
* getRelations
* returns an array containing all relation objects
*
* @return array an array of Doctrine_Relation objects
*/
public function getRelations()
{
return $this->_parser->getRelations();
}
/** /**
* getBehaviors * getBehaviors
* returns all behaviors attached to the class. * returns all behaviors attached to the class.
...@@ -2058,7 +1949,72 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable ...@@ -2058,7 +1949,72 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
$this->_attributes[$name] = $value; $this->_attributes[$name] = $value;
} }
} }
/* The following stuff needs to be touched for the association mapping rewrite */
public function bindRelation($args, $type)
{
return $this->bind($args, $type);
}
/**
* @todo Relation mapping rewrite.
*/
public function bind($args, $type)
{
$options = array();
$options['type'] = $type;
if ( ! isset($args[1])) {
$args[1] = array();
}
if ( ! is_array($args[1])) {
try {
throw new Exception();
} catch (Exception $e) {
echo $e->getTraceAsString();
}
}
$options = array_merge($args[1], $options);
$this->_parser->bind($args[0], $options);
}
/**
* hasRelation
*
* @param string $alias the relation to check if exists
* @return boolean true if the relation exists otherwise false
*/
public function hasRelation($alias)
{
return $this->_parser->hasRelation($alias);
}
/**
* getRelation
*
* @param string $alias relation alias
*/
public function getRelation($alias, $recursive = true)
{
return $this->_parser->getRelation($alias, $recursive);
}
public function getRelationParser()
{
return $this->_parser;
}
/**
* getRelations
* returns an array containing all relation objects
*
* @return array an array of Doctrine_Relation objects
*/
public function getRelations()
{
return $this->_parser->getRelations();
}
/** /**
* *
......
...@@ -130,7 +130,7 @@ class Doctrine_ClassMetadata_Factory ...@@ -130,7 +130,7 @@ class Doctrine_ClassMetadata_Factory
protected function _addInheritedFields($subClass, $parentClass) protected function _addInheritedFields($subClass, $parentClass)
{ {
foreach ($parentClass->getColumns() as $name => $definition) { foreach ($parentClass->getFieldMappings() as $name => $definition) {
$fullName = "$name as " . $parentClass->getFieldName($name); $fullName = "$name as " . $parentClass->getFieldName($name);
$definition['inherited'] = true; $definition['inherited'] = true;
$subClass->mapColumn( $subClass->mapColumn(
...@@ -246,7 +246,7 @@ class Doctrine_ClassMetadata_Factory ...@@ -246,7 +246,7 @@ class Doctrine_ClassMetadata_Factory
case 1: // A single identifier is in the mapping case 1: // A single identifier is in the mapping
foreach ($class->getIdentifier() as $pk) { foreach ($class->getIdentifier() as $pk) {
$columnName = $class->getColumnName($pk); $columnName = $class->getColumnName($pk);
$thisColumns = $class->getColumns(); $thisColumns = $class->getFieldMappings();
$e = $thisColumns[$columnName]; $e = $thisColumns[$columnName];
$found = false; $found = false;
......
...@@ -342,12 +342,12 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable ...@@ -342,12 +342,12 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
$this->_data = array_merge($this->_data, $this->_id); $this->_data = array_merge($this->_data, $this->_id);
foreach ($this->_data as $k => $v) { foreach ($this->_data as $k => $v) {
if ($v instanceof Doctrine_Entity && $this->_class->getTypeOf($k) != 'object') { if ($v instanceof Doctrine_Entity && $this->_class->getTypeOfField($k) != 'object') {
unset($vars['_data'][$k]); unset($vars['_data'][$k]);
} else if ($v === Doctrine_Null::$INSTANCE) { } else if ($v === Doctrine_Null::$INSTANCE) {
unset($vars['_data'][$k]); unset($vars['_data'][$k]);
} else { } else {
switch ($this->_class->getTypeOf($k)) { switch ($this->_class->getTypeOfField($k)) {
case 'array': case 'array':
case 'object': case 'object':
$vars['_data'][$k] = serialize($vars['_data'][$k]); $vars['_data'][$k] = serialize($vars['_data'][$k]);
...@@ -400,7 +400,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable ...@@ -400,7 +400,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
$this->_class = $this->_em->getClassMetadata($this->_entityName); $this->_class = $this->_em->getClassMetadata($this->_entityName);
foreach ($this->_data as $k => $v) { foreach ($this->_data as $k => $v) {
switch ($this->_class->getTypeOf($k)) { switch ($this->_class->getTypeOfField($k)) {
case 'array': case 'array':
case 'object': case 'object':
$this->_data[$k] = unserialize($this->_data[$k]); $this->_data[$k] = unserialize($this->_data[$k]);
...@@ -1024,7 +1024,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable ...@@ -1024,7 +1024,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
} }
foreach ($modifiedFields as $field) { foreach ($modifiedFields as $field) {
$type = $this->_class->getTypeOf($field); $type = $this->_class->getTypeOfField($field);
if ($this->_data[$field] === Doctrine_Null::$INSTANCE) { if ($this->_data[$field] === Doctrine_Null::$INSTANCE) {
$dataSet[$field] = null; $dataSet[$field] = null;
......
...@@ -109,7 +109,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -109,7 +109,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
// Used variables during hydration // Used variables during hydration
reset($this->_queryComponents); reset($this->_queryComponents);
$rootAlias = key($this->_queryComponents); $rootAlias = key($this->_queryComponents);
$rootComponentName = $this->_queryComponents[$rootAlias]['metadata']->getClassName(); $rootEntityName = $this->_queryComponents[$rootAlias]['metadata']->getClassName();
// if only one class is involved we can make our lives easier // if only one class is involved we can make our lives easier
$isSimpleQuery = count($this->_queryComponents) <= 1; $isSimpleQuery = count($this->_queryComponents) <= 1;
// Lookup map to quickly discover/lookup existing records in the result // Lookup map to quickly discover/lookup existing records in the result
...@@ -128,7 +128,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -128,7 +128,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
if ($parserResult->isMixedQuery() || $hydrationMode == Doctrine::HYDRATE_SCALAR) { if ($parserResult->isMixedQuery() || $hydrationMode == Doctrine::HYDRATE_SCALAR) {
$result = array(); $result = array();
} else { } else {
$result = $driver->getElementCollection($rootComponentName); $result = $driver->getElementCollection($rootEntityName);
} }
if ($stmt === false || $stmt === 0) { if ($stmt === false || $stmt === 0) {
...@@ -139,7 +139,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -139,7 +139,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
foreach ($this->_queryComponents as $dqlAlias => $component) { foreach ($this->_queryComponents as $dqlAlias => $component) {
// disable lazy-loading of related elements during hydration // disable lazy-loading of related elements during hydration
$component['metadata']->setAttribute('loadReferences', false); $component['metadata']->setAttribute('loadReferences', false);
$componentName = $component['metadata']->getClassName(); $entityName = $component['metadata']->getClassName();
$identifierMap[$dqlAlias] = array(); $identifierMap[$dqlAlias] = array();
$resultPointers[$dqlAlias] = array(); $resultPointers[$dqlAlias] = array();
$idTemplate[$dqlAlias] = ''; $idTemplate[$dqlAlias] = '';
...@@ -163,22 +163,21 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -163,22 +163,21 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
continue; continue;
} }
// From here on its all about graph construction
// 1) Initialize
$id = $idTemplate; // initialize the id-memory $id = $idTemplate; // initialize the id-memory
$nonemptyComponents = array(); $nonemptyComponents = array();
$rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents); $rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents);
// // 2) Hydrate the data of the root entity from the current row
// hydrate the data of the root entity from the current row //$class = $this->_queryComponents[$rootAlias]['metadata'];
// //$entityName = $class->getComponentName();
$class = $this->_queryComponents[$rootAlias]['metadata'];
$componentName = $class->getComponentName();
// Check for an existing element // Check for an existing element
$index = false; $index = false;
if ($isSimpleQuery || ! isset($identifierMap[$rootAlias][$id[$rootAlias]])) { if ($isSimpleQuery || ! isset($identifierMap[$rootAlias][$id[$rootAlias]])) {
$element = $driver->getElement($rowData[$rootAlias], $componentName); $element = $driver->getElement($rowData[$rootAlias], $rootEntityName);
// do we need to index by a custom field?
if ($field = $this->_getCustomIndexField($rootAlias)) { if ($field = $this->_getCustomIndexField($rootAlias)) {
if ($parserResult->isMixedQuery()) { if ($parserResult->isMixedQuery()) {
$result[] = array( $result[] = array(
...@@ -198,22 +197,22 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -198,22 +197,22 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
} else { } else {
$index = $identifierMap[$rootAlias][$id[$rootAlias]]; $index = $identifierMap[$rootAlias][$id[$rootAlias]];
} }
$this->_setLastElement($resultPointers, $result, $index, $rootAlias, false); $this->_updateResultPointer($resultPointers, $result, $index, $rootAlias, false);
unset($rowData[$rootAlias]); unset($rowData[$rootAlias]);
// end hydrate data of the root component for the current row // end hydrate data of the root component for the current row
// Check for scalar values // Extract scalar values. They're appended at the end.
if (isset($rowData['scalars'])) { if (isset($rowData['scalars'])) {
$scalars = $rowData['scalars']; $scalars = $rowData['scalars'];
unset($rowData['scalars']); unset($rowData['scalars']);
} }
// now hydrate the rest of the data found in the current row, that belongs to other // 3) Now hydrate the rest of the data found in the current row, that
// (related) classes. // belongs to other (related) Entities.
foreach ($rowData as $dqlAlias => $data) { foreach ($rowData as $dqlAlias => $data) {
$index = false; $index = false;
$map = $this->_queryComponents[$dqlAlias]; $map = $this->_queryComponents[$dqlAlias];
$componentName = $map['metadata']->getClassName(); $entityName = $map['metadata']->getClassName();
$parent = $map['parent']; $parent = $map['parent'];
$relation = $map['relation']; $relation = $map['relation'];
$relationAlias = $relation->getAlias(); $relationAlias = $relation->getAlias();
...@@ -227,7 +226,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -227,7 +226,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
} else if (isset($resultPointers[$parent])) { } else if (isset($resultPointers[$parent])) {
$baseElement =& $resultPointers[$parent]; $baseElement =& $resultPointers[$parent];
} else { } else {
unset($prev[$dqlAlias]); // Ticket #1228 unset($resultPointers[$dqlAlias]); // Ticket #1228
continue; continue;
} }
...@@ -241,7 +240,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -241,7 +240,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
$index = $indexExists ? $identifierMap[$path][$id[$parent]][$id[$dqlAlias]] : false; $index = $indexExists ? $identifierMap[$path][$id[$parent]][$id[$dqlAlias]] : false;
$indexIsValid = $index !== false ? isset($baseElement[$relationAlias][$index]) : false; $indexIsValid = $index !== false ? isset($baseElement[$relationAlias][$index]) : false;
if ( ! $indexExists || ! $indexIsValid) { if ( ! $indexExists || ! $indexIsValid) {
$element = $driver->getElement($data, $componentName); $element = $driver->getElement($data, $entityName);
if ($field = $this->_getCustomIndexField($dqlAlias)) { if ($field = $this->_getCustomIndexField($dqlAlias)) {
$driver->addRelatedIndexedElement($baseElement, $relationAlias, $element, $field); $driver->addRelatedIndexedElement($baseElement, $relationAlias, $element, $field);
} else { } else {
...@@ -252,7 +251,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -252,7 +251,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
} }
} else if ( ! isset($baseElement[$relationAlias])) { } else if ( ! isset($baseElement[$relationAlias])) {
$driver->setRelatedElement($baseElement, $relationAlias, $driver->setRelatedElement($baseElement, $relationAlias,
$driver->getElementCollection($componentName)); $driver->getElementCollection($entityName));
} }
} else { } else {
// x-1 relation // x-1 relation
...@@ -263,11 +262,11 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -263,11 +262,11 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
$driver->getNullPointer()); $driver->getNullPointer());
} else if ( ! $driver->isFieldSet($baseElement, $relationAlias)) { } else if ( ! $driver->isFieldSet($baseElement, $relationAlias)) {
$driver->setRelatedElement($baseElement, $relationAlias, $driver->setRelatedElement($baseElement, $relationAlias,
$driver->getElement($data, $componentName)); $driver->getElement($data, $entityName));
} }
} }
if (($coll =& $driver->getReferenceValue($baseElement, $relationAlias)) !== null) { if (($coll =& $driver->getReferenceValue($baseElement, $relationAlias)) !== null) {
$this->_setLastElement($resultPointers, $coll, $index, $dqlAlias, $oneToOne); $this->_updateResultPointer($resultPointers, $coll, $index, $dqlAlias, $oneToOne);
} }
} }
...@@ -295,27 +294,23 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -295,27 +294,23 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
} }
/** /**
* sets the last element of given data array / collection * Updates the result pointer for an Entity. The result pointers point to the
* as previous element * last seen instance of each Entity. This is used for graph construction.
* *
* @param array $prev The array that contains the pointers to the latest element of each class. * @param array $resultPointers The result pointers.
* @param array|Collection The object collection. * @param array|Collection $coll The element.
* @param boolean|integer $index Index of the element in the collection. * @param boolean|integer $index Index of the element in the collection.
* @param string $dqlAlias * @param string $dqlAlias
* @param boolean $oneToOne Whether it is a single-valued association or not. * @param boolean $oneToOne Whether it is a single-valued association or not.
* @return void
* @todo Detailed documentation
*/ */
protected function _setLastElement(&$resultPointers, &$coll, $index, $dqlAlias, $oneToOne) protected function _updateResultPointer(&$resultPointers, &$coll, $index, $dqlAlias, $oneToOne)
{ {
if ($coll === $this->_nullObject || $coll === null) { if ($coll === $this->_nullObject || $coll === null) {
unset($resultPointers[$dqlAlias]); // Ticket #1228 unset($resultPointers[$dqlAlias]); // Ticket #1228
return false; return;
} }
if ($index !== false) { if ($index !== false) {
// Link element at $index to previous element for the component
// identified by the DQL alias $alias
$resultPointers[$dqlAlias] =& $coll[$index]; $resultPointers[$dqlAlias] =& $coll[$index];
return; return;
} }
...@@ -356,10 +351,12 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -356,10 +351,12 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
if ( ! isset($cache[$key])) { if ( ! isset($cache[$key])) {
if ($this->_isIgnoredName($key)) continue; if ($this->_isIgnoredName($key)) continue;
// cache general information like the column name <-> field name mapping // Cache general information like the column name <-> field name mapping
$e = explode('__', $key); $e = explode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $key);
$columnName = strtolower(array_pop($e)); $columnName = array_pop($e);
$cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))]; $cache[$key]['dqlAlias'] = $this->_tableAliases[
implode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $e)
];
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; $classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
// check whether it's an aggregate value or a regular field // check whether it's an aggregate value or a regular field
if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) { if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) {
...@@ -439,9 +436,11 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract ...@@ -439,9 +436,11 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
if ($this->_isIgnoredName($key)) continue; if ($this->_isIgnoredName($key)) continue;
// cache general information like the column name <-> field name mapping // cache general information like the column name <-> field name mapping
$e = explode('__', $key); $e = explode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $key);
$columnName = strtolower(array_pop($e)); $columnName = array_pop($e);
$cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))]; $cache[$key]['dqlAlias'] = $this->_tableAliases[
implode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $e)
];
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; $classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
// check whether it's an aggregate value or a regular field // check whether it's an aggregate value or a regular field
if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) { if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) {
......
<?php
/**
* A MappingException indicates that something is wrong with the mapping setup.
*
* @since 2.0
*/
class Doctrine_MappingException extends Doctrine_Exception
{
public static function identifierRequired($entityName)
{
return new self("No identifier specified for Entity '$entityName'."
. " Every Entity must have an identifier.");
}
}
?>
\ No newline at end of file
...@@ -133,7 +133,7 @@ class Doctrine_Query_Production_PathExpressionEndingWithAsterisk extends Doctrin ...@@ -133,7 +133,7 @@ class Doctrine_Query_Production_PathExpressionEndingWithAsterisk extends Doctrin
} }
// Generating the SQL piece // Generating the SQL piece
$fields = $this->_queryComponent['metadata']->getMappedColumns(); $fields = $this->_queryComponent['metadata']->getFieldMappings();
$tableAlias = $parserResult->getTableAliasFromComponentAlias($componentAlias); $tableAlias = $parserResult->getTableAliasFromComponentAlias($componentAlias);
$str = ''; $str = '';
......
<?php <?php
require_once 'lib/DoctrineTestInit.php'; require_once 'lib/DoctrineTestInit.php';
class Orm_Entity_AccessorTestCase extends Doctrine_OrmTestCase class Orm_Entity_AccessorTest extends Doctrine_OrmTestCase
{ {
public function testGetterSetterOverride() public function testGetterSetterOverride()
{ {
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$entity1 = new CustomAccessorMutatorTestEntity(); $entity1 = new CustomAccessorMutatorTestEntity();
$entity1->username = 'romanb'; $entity1->username = 'romanb';
$this->assertEquals('romanb?!', $entity1->username); $this->assertEquals('romanb?!', $entity1->username);
...@@ -14,10 +12,14 @@ class Orm_Entity_AccessorTestCase extends Doctrine_OrmTestCase ...@@ -14,10 +12,14 @@ class Orm_Entity_AccessorTestCase extends Doctrine_OrmTestCase
$entity2 = new MagicAccessorMutatorTestEntity(); $entity2 = new MagicAccessorMutatorTestEntity();
$entity2->username = 'romanb'; $entity2->username = 'romanb';
$this->assertEquals('romanb?!', $entity1->username); $this->assertEquals('romanb?!', $entity1->username);
} }
} }
/* Local test classes */
class CustomAccessorMutatorTestEntity extends Doctrine_Entity class CustomAccessorMutatorTestEntity extends Doctrine_Entity
{ {
public static function initMetadata($class) public static function initMetadata($class)
......
...@@ -6,7 +6,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) { ...@@ -6,7 +6,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
require_once 'lib/DoctrineTestInit.php'; require_once 'lib/DoctrineTestInit.php';
// Tests // Tests
require_once 'Orm/Entity/AccessorTestCase.php'; require_once 'Orm/Entity/AccessorTest.php';
require_once 'Orm/Entity/ConstructorTest.php'; require_once 'Orm/Entity/ConstructorTest.php';
class Orm_Entity_AllTests class Orm_Entity_AllTests
...@@ -20,7 +20,7 @@ class Orm_Entity_AllTests ...@@ -20,7 +20,7 @@ class Orm_Entity_AllTests
{ {
$suite = new Doctrine_TestSuite('Doctrine Orm Entity Tests'); $suite = new Doctrine_TestSuite('Doctrine Orm Entity Tests');
$suite->addTestSuite('Orm_Entity_AccessorTestCase'); $suite->addTestSuite('Orm_Entity_AccessorTest');
$suite->addTestSuite('Orm_Entity_ConstructorTest'); $suite->addTestSuite('Orm_Entity_ConstructorTest');
return $suite; return $suite;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment