Cleanups, improvements, fixes.
This commit is contained in:
parent
3cd7b95424
commit
c43f9588be
@ -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.
|
||||
* if the column name for the field cannot be found
|
||||
* this method returns the given field name.
|
||||
*
|
||||
* @param string $alias column alias
|
||||
* @return string column name
|
||||
* @param string $alias The field name.
|
||||
* @return string The column name.
|
||||
*/
|
||||
public function getColumnName($fieldName)
|
||||
{
|
||||
@ -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)
|
||||
{
|
||||
return isset($this->_fieldMappings[$fieldName]) ?
|
||||
$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.
|
||||
@ -588,6 +597,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
*
|
||||
* @param string $lcColumnName
|
||||
* @return string
|
||||
* @todo Better name.
|
||||
*/
|
||||
public function getFieldNameForLowerColumnName($lcColumnName)
|
||||
{
|
||||
@ -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.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
@ -663,6 +663,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
* By default the column gets appended.
|
||||
*
|
||||
* @throws Doctrine_ClassMetadata_Exception If trying use wrongly typed parameter.
|
||||
* @todo Rename to mapField()/addFieldMapping().
|
||||
*/
|
||||
public function mapColumn($name, $type, $length = null, $options = array())
|
||||
{
|
||||
@ -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.
|
||||
*/
|
||||
public function hasDefaultValues()
|
||||
/*public function hasDefaultValues()
|
||||
{
|
||||
return $this->_hasDefaultValues;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* getDefaultValueOf
|
||||
@ -799,7 +800,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
* @param string $fieldName
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefaultValueOf($fieldName)
|
||||
/*public function getDefaultValueOf($fieldName)
|
||||
{
|
||||
if ( ! isset($this->_fieldMappings[$fieldName])) {
|
||||
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
|
||||
} else {
|
||||
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
|
||||
* @deprecated Use getIdentifierFieldNames()
|
||||
@ -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
|
||||
*/
|
||||
@ -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
|
||||
* can be either <tt>Doctrine::IDENTIFIER_NATURAL</tt>, <tt>Doctrine::IDENTIFIER_AUTOINCREMENT</tt>,
|
||||
* <tt>Doctrine::IDENTIFIER_SEQUENCE</tt> or <tt>Doctrine::IDENTIFIER_COMPOSITE</tt>.
|
||||
* can be either
|
||||
* <tt>Doctrine::IDENTIFIER_NATURAL</tt>,
|
||||
* <tt>Doctrine::IDENTIFIER_AUTOINCREMENT</tt>,
|
||||
* <tt>Doctrine::IDENTIFIER_SEQUENCE</tt> or
|
||||
* <tt>Doctrine::IDENTIFIER_COMPOSITE</tt>.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
@ -857,16 +861,6 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
$this->_identifierType = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* hasColumn
|
||||
* @return boolean
|
||||
* @deprecated
|
||||
*/
|
||||
public function hasColumn($columnName)
|
||||
{
|
||||
return isset($this->_fieldNames[$columnName]);
|
||||
}
|
||||
|
||||
public function hasMappedColumn($columnName)
|
||||
{
|
||||
return isset($this->_fieldNames[$columnName]);
|
||||
@ -885,14 +879,14 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
* @param string $fieldName
|
||||
* @return array
|
||||
*/
|
||||
public function getEnumValues($fieldName)
|
||||
/*public function getEnumValues($fieldName)
|
||||
{
|
||||
if (isset($this->_fieldMappings[$fieldName]['values'])) {
|
||||
return $this->_fieldMappings[$fieldName]['values'];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* enumValue
|
||||
@ -901,7 +895,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
* @param integer $index
|
||||
* @return mixed
|
||||
*/
|
||||
public function enumValue($fieldName, $index)
|
||||
/*public function enumValue($fieldName, $index)
|
||||
{
|
||||
if ($index instanceof Doctrine_Null) {
|
||||
return $index;
|
||||
@ -921,7 +915,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
$this->_enumValues[$fieldName][$index] = $enumValue;
|
||||
|
||||
return $enumValue;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* enumIndex
|
||||
@ -930,7 +924,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
public function enumIndex($fieldName, $value)
|
||||
/*public function enumIndex($fieldName, $value)
|
||||
{
|
||||
$values = $this->getEnumValues($fieldName);
|
||||
$index = array_search($value, $values);
|
||||
@ -939,7 +933,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* getColumnCount
|
||||
@ -947,23 +941,24 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
* @return integer the number of columns in this table
|
||||
* @deprecated
|
||||
*/
|
||||
public function getColumnCount()
|
||||
/*public function getColumnCount()
|
||||
{
|
||||
return $this->_columnCount;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* getMappedColumnCount
|
||||
*
|
||||
* @return integer the number of mapped columns in the class.
|
||||
*/
|
||||
public function getMappedColumnCount()
|
||||
public function getMappedFieldCount()
|
||||
{
|
||||
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
|
||||
* not have a custom accessor.
|
||||
*/
|
||||
@ -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
|
||||
* not have a custom mutator.
|
||||
*/
|
||||
@ -983,28 +979,12 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
return isset($this->_fieldMappings[$fieldName]['mutator']) ?
|
||||
$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.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMappedColumns()
|
||||
{
|
||||
return $this->_fieldMappings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all field mappings.
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
public function getFieldMappings()
|
||||
{
|
||||
return $this->_fieldMappings;
|
||||
@ -1016,7 +996,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function removeColumn($fieldName)
|
||||
/*public function removeColumn($fieldName)
|
||||
{
|
||||
$columnName = array_search($fieldName, $this->_fieldNames);
|
||||
|
||||
@ -1029,7 +1009,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
$this->_columnCount--;
|
||||
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* returns an array containing all the column names.
|
||||
@ -1076,35 +1056,12 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
* @return mixed array on success, false on failure
|
||||
* @deprecated
|
||||
*/
|
||||
public function getDefinitionOf($fieldName)
|
||||
/*public function getDefinitionOf($fieldName)
|
||||
{
|
||||
$columnName = $this->getColumnName($fieldName);
|
||||
|
||||
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.
|
||||
@ -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
|
||||
* returns all behaviors attached to the class.
|
||||
@ -2058,7 +1949,72 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
|
||||
$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
|
||||
|
||||
protected function _addInheritedFields($subClass, $parentClass)
|
||||
{
|
||||
foreach ($parentClass->getColumns() as $name => $definition) {
|
||||
foreach ($parentClass->getFieldMappings() as $name => $definition) {
|
||||
$fullName = "$name as " . $parentClass->getFieldName($name);
|
||||
$definition['inherited'] = true;
|
||||
$subClass->mapColumn(
|
||||
@ -246,7 +246,7 @@ class Doctrine_ClassMetadata_Factory
|
||||
case 1: // A single identifier is in the mapping
|
||||
foreach ($class->getIdentifier() as $pk) {
|
||||
$columnName = $class->getColumnName($pk);
|
||||
$thisColumns = $class->getColumns();
|
||||
$thisColumns = $class->getFieldMappings();
|
||||
$e = $thisColumns[$columnName];
|
||||
|
||||
$found = false;
|
||||
|
@ -342,12 +342,12 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
|
||||
$this->_data = array_merge($this->_data, $this->_id);
|
||||
|
||||
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]);
|
||||
} else if ($v === Doctrine_Null::$INSTANCE) {
|
||||
unset($vars['_data'][$k]);
|
||||
} else {
|
||||
switch ($this->_class->getTypeOf($k)) {
|
||||
switch ($this->_class->getTypeOfField($k)) {
|
||||
case 'array':
|
||||
case 'object':
|
||||
$vars['_data'][$k] = serialize($vars['_data'][$k]);
|
||||
@ -400,7 +400,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
|
||||
$this->_class = $this->_em->getClassMetadata($this->_entityName);
|
||||
|
||||
foreach ($this->_data as $k => $v) {
|
||||
switch ($this->_class->getTypeOf($k)) {
|
||||
switch ($this->_class->getTypeOfField($k)) {
|
||||
case 'array':
|
||||
case 'object':
|
||||
$this->_data[$k] = unserialize($this->_data[$k]);
|
||||
@ -1024,7 +1024,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Serializable
|
||||
}
|
||||
|
||||
foreach ($modifiedFields as $field) {
|
||||
$type = $this->_class->getTypeOf($field);
|
||||
$type = $this->_class->getTypeOfField($field);
|
||||
|
||||
if ($this->_data[$field] === Doctrine_Null::$INSTANCE) {
|
||||
$dataSet[$field] = null;
|
||||
|
@ -109,7 +109,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
// Used variables during hydration
|
||||
reset($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
|
||||
$isSimpleQuery = count($this->_queryComponents) <= 1;
|
||||
// Lookup map to quickly discover/lookup existing records in the result
|
||||
@ -128,7 +128,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
if ($parserResult->isMixedQuery() || $hydrationMode == Doctrine::HYDRATE_SCALAR) {
|
||||
$result = array();
|
||||
} else {
|
||||
$result = $driver->getElementCollection($rootComponentName);
|
||||
$result = $driver->getElementCollection($rootEntityName);
|
||||
}
|
||||
|
||||
if ($stmt === false || $stmt === 0) {
|
||||
@ -139,7 +139,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
foreach ($this->_queryComponents as $dqlAlias => $component) {
|
||||
// disable lazy-loading of related elements during hydration
|
||||
$component['metadata']->setAttribute('loadReferences', false);
|
||||
$componentName = $component['metadata']->getClassName();
|
||||
$entityName = $component['metadata']->getClassName();
|
||||
$identifierMap[$dqlAlias] = array();
|
||||
$resultPointers[$dqlAlias] = array();
|
||||
$idTemplate[$dqlAlias] = '';
|
||||
@ -163,22 +163,21 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
continue;
|
||||
}
|
||||
|
||||
// From here on its all about graph construction
|
||||
|
||||
// 1) Initialize
|
||||
$id = $idTemplate; // initialize the id-memory
|
||||
$nonemptyComponents = array();
|
||||
$rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents);
|
||||
|
||||
//
|
||||
// hydrate the data of the root entity from the current row
|
||||
//
|
||||
$class = $this->_queryComponents[$rootAlias]['metadata'];
|
||||
$componentName = $class->getComponentName();
|
||||
// 2) Hydrate the data of the root entity from the current row
|
||||
//$class = $this->_queryComponents[$rootAlias]['metadata'];
|
||||
//$entityName = $class->getComponentName();
|
||||
|
||||
// Check for an existing element
|
||||
$index = false;
|
||||
if ($isSimpleQuery || ! isset($identifierMap[$rootAlias][$id[$rootAlias]])) {
|
||||
$element = $driver->getElement($rowData[$rootAlias], $componentName);
|
||||
|
||||
// do we need to index by a custom field?
|
||||
$element = $driver->getElement($rowData[$rootAlias], $rootEntityName);
|
||||
if ($field = $this->_getCustomIndexField($rootAlias)) {
|
||||
if ($parserResult->isMixedQuery()) {
|
||||
$result[] = array(
|
||||
@ -198,22 +197,22 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
} else {
|
||||
$index = $identifierMap[$rootAlias][$id[$rootAlias]];
|
||||
}
|
||||
$this->_setLastElement($resultPointers, $result, $index, $rootAlias, false);
|
||||
$this->_updateResultPointer($resultPointers, $result, $index, $rootAlias, false);
|
||||
unset($rowData[$rootAlias]);
|
||||
// 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'])) {
|
||||
$scalars = $rowData['scalars'];
|
||||
unset($rowData['scalars']);
|
||||
}
|
||||
|
||||
// now hydrate the rest of the data found in the current row, that belongs to other
|
||||
// (related) classes.
|
||||
// 3) Now hydrate the rest of the data found in the current row, that
|
||||
// belongs to other (related) Entities.
|
||||
foreach ($rowData as $dqlAlias => $data) {
|
||||
$index = false;
|
||||
$map = $this->_queryComponents[$dqlAlias];
|
||||
$componentName = $map['metadata']->getClassName();
|
||||
$entityName = $map['metadata']->getClassName();
|
||||
$parent = $map['parent'];
|
||||
$relation = $map['relation'];
|
||||
$relationAlias = $relation->getAlias();
|
||||
@ -227,7 +226,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
} else if (isset($resultPointers[$parent])) {
|
||||
$baseElement =& $resultPointers[$parent];
|
||||
} else {
|
||||
unset($prev[$dqlAlias]); // Ticket #1228
|
||||
unset($resultPointers[$dqlAlias]); // Ticket #1228
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -241,7 +240,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
$index = $indexExists ? $identifierMap[$path][$id[$parent]][$id[$dqlAlias]] : false;
|
||||
$indexIsValid = $index !== false ? isset($baseElement[$relationAlias][$index]) : false;
|
||||
if ( ! $indexExists || ! $indexIsValid) {
|
||||
$element = $driver->getElement($data, $componentName);
|
||||
$element = $driver->getElement($data, $entityName);
|
||||
if ($field = $this->_getCustomIndexField($dqlAlias)) {
|
||||
$driver->addRelatedIndexedElement($baseElement, $relationAlias, $element, $field);
|
||||
} else {
|
||||
@ -252,7 +251,7 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
}
|
||||
} else if ( ! isset($baseElement[$relationAlias])) {
|
||||
$driver->setRelatedElement($baseElement, $relationAlias,
|
||||
$driver->getElementCollection($componentName));
|
||||
$driver->getElementCollection($entityName));
|
||||
}
|
||||
} else {
|
||||
// x-1 relation
|
||||
@ -263,11 +262,11 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
$driver->getNullPointer());
|
||||
} else if ( ! $driver->isFieldSet($baseElement, $relationAlias)) {
|
||||
$driver->setRelatedElement($baseElement, $relationAlias,
|
||||
$driver->getElement($data, $componentName));
|
||||
$driver->getElement($data, $entityName));
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the last element of given data array / collection
|
||||
* as previous element
|
||||
* Updates the result pointer for an Entity. The result pointers point to the
|
||||
* 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|Collection The object collection.
|
||||
* @param array $resultPointers The result pointers.
|
||||
* @param array|Collection $coll The element.
|
||||
* @param boolean|integer $index Index of the element in the collection.
|
||||
* @param string $dqlAlias
|
||||
* @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) {
|
||||
unset($resultPointers[$dqlAlias]); // Ticket #1228
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($index !== false) {
|
||||
// Link element at $index to previous element for the component
|
||||
// identified by the DQL alias $alias
|
||||
$resultPointers[$dqlAlias] =& $coll[$index];
|
||||
return;
|
||||
}
|
||||
@ -356,10 +351,12 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
if ( ! isset($cache[$key])) {
|
||||
if ($this->_isIgnoredName($key)) continue;
|
||||
|
||||
// cache general information like the column name <-> field name mapping
|
||||
$e = explode('__', $key);
|
||||
$columnName = strtolower(array_pop($e));
|
||||
$cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];
|
||||
// Cache general information like the column name <-> field name mapping
|
||||
$e = explode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $key);
|
||||
$columnName = array_pop($e);
|
||||
$cache[$key]['dqlAlias'] = $this->_tableAliases[
|
||||
implode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $e)
|
||||
];
|
||||
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
|
||||
// check whether it's an aggregate value or a regular field
|
||||
if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) {
|
||||
@ -439,9 +436,11 @@ class Doctrine_HydratorNew extends Doctrine_Hydrator_Abstract
|
||||
if ($this->_isIgnoredName($key)) continue;
|
||||
|
||||
// cache general information like the column name <-> field name mapping
|
||||
$e = explode('__', $key);
|
||||
$columnName = strtolower(array_pop($e));
|
||||
$cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];
|
||||
$e = explode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $key);
|
||||
$columnName = array_pop($e);
|
||||
$cache[$key]['dqlAlias'] = $this->_tableAliases[
|
||||
implode(Doctrine_Query_Production::SQLALIAS_SEPARATOR, $e)
|
||||
];
|
||||
$classMetadata = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata'];
|
||||
// check whether it's an aggregate value or a regular field
|
||||
if (isset($this->_queryComponents[$cache[$key]['dqlAlias']]['agg'][$columnName])) {
|
||||
|
17
lib/Doctrine/MappingException.php
Normal file
17
lib/Doctrine/MappingException.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?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.");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -133,7 +133,7 @@ class Doctrine_Query_Production_PathExpressionEndingWithAsterisk extends Doctrin
|
||||
}
|
||||
|
||||
// Generating the SQL piece
|
||||
$fields = $this->_queryComponent['metadata']->getMappedColumns();
|
||||
$fields = $this->_queryComponent['metadata']->getFieldMappings();
|
||||
$tableAlias = $parserResult->getTableAliasFromComponentAlias($componentAlias);
|
||||
$str = '';
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
<?php
|
||||
require_once 'lib/DoctrineTestInit.php';
|
||||
|
||||
class Orm_Entity_AccessorTestCase extends Doctrine_OrmTestCase
|
||||
class Orm_Entity_AccessorTest extends Doctrine_OrmTestCase
|
||||
{
|
||||
public function testGetterSetterOverride()
|
||||
{
|
||||
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
|
||||
|
||||
{
|
||||
$entity1 = new CustomAccessorMutatorTestEntity();
|
||||
$entity1->username = 'romanb';
|
||||
$this->assertEquals('romanb?!', $entity1->username);
|
||||
@ -14,10 +12,14 @@ class Orm_Entity_AccessorTestCase extends Doctrine_OrmTestCase
|
||||
$entity2 = new MagicAccessorMutatorTestEntity();
|
||||
$entity2->username = 'romanb';
|
||||
$this->assertEquals('romanb?!', $entity1->username);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Local test classes */
|
||||
|
||||
class CustomAccessorMutatorTestEntity extends Doctrine_Entity
|
||||
{
|
||||
public static function initMetadata($class)
|
@ -6,7 +6,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
|
||||
require_once 'lib/DoctrineTestInit.php';
|
||||
|
||||
// Tests
|
||||
require_once 'Orm/Entity/AccessorTestCase.php';
|
||||
require_once 'Orm/Entity/AccessorTest.php';
|
||||
require_once 'Orm/Entity/ConstructorTest.php';
|
||||
|
||||
class Orm_Entity_AllTests
|
||||
@ -20,7 +20,7 @@ class Orm_Entity_AllTests
|
||||
{
|
||||
$suite = new Doctrine_TestSuite('Doctrine Orm Entity Tests');
|
||||
|
||||
$suite->addTestSuite('Orm_Entity_AccessorTestCase');
|
||||
$suite->addTestSuite('Orm_Entity_AccessorTest');
|
||||
$suite->addTestSuite('Orm_Entity_ConstructorTest');
|
||||
|
||||
return $suite;
|
||||
|
Loading…
Reference in New Issue
Block a user