Changeset 4655 for trunk/lib/Doctrine
- Timestamp:
- 07/11/08 11:48:04 (6 months ago)
- Location:
- trunk/lib/Doctrine
- Files:
-
- 1 added
- 5 modified
-
ClassMetadata.php (modified) (28 diffs)
-
ClassMetadata/Factory.php (modified) (2 diffs)
-
Entity.php (modified) (3 diffs)
-
HydratorNew.php (modified) (13 diffs)
-
MappingException.php (added)
-
Query/Production/PathExpressionEndingWithAsterisk.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Doctrine/ClassMetadata.php
r4653 r4655 541 541 542 542 /** 543 * getColumnName 544 * 545 * returns a column name for a field name. 546 * if the column name for the field cannot be found 547 * this method returns the given field name. 548 * 549 * @param string $alias column alias 550 * @return string column name 543 * Gets a column name for a field name. 544 * If the column name for the field cannot be found, the given field name 545 * is returned. 546 * 547 * @param string $alias The field name. 548 * @return string The column name. 551 549 */ 552 550 public function getColumnName($fieldName) … … 557 555 558 556 /** 559 * @deprecated 560 */ 561 public function getColumnDefinition($columnName) 562 { 563 return $this->getColumnMapping($columnName); 564 } 565 557 * Gets the mapping of a (regular) fields that holds some data but not a 558 * reference to another object. 559 * 560 * @param string $fieldName The field name. 561 * @return array The mapping. 562 */ 566 563 public function getFieldMapping($fieldName) 567 564 { … … 569 566 $this->_fieldMappings[$fieldName] : false; 570 567 } 568 569 /** 570 * Gets the mapping of an association. 571 * 572 * @param string $fieldName The field name that represents the association in 573 * the object model. 574 * @return Doctrine::ORM::Mapping::AssociationMapping The mapping. 575 */ 576 public function getAssociationMapping($fieldName) 577 { 578 //... 579 } 571 580 572 581 /** … … 589 598 * @param string $lcColumnName 590 599 * @return string 600 * @todo Better name. 591 601 */ 592 602 public function getFieldNameForLowerColumnName($lcColumnName) … … 642 652 643 653 /** 644 * @deprecated645 */646 public function setColumns(array $definitions)647 {648 foreach ($definitions as $name => $options) {649 $this->setColumn($name, $options['type'], $options['length'], $options);650 }651 }652 653 /**654 654 * Maps a field of the class to a database column. 655 655 * … … 664 664 * 665 665 * @throws Doctrine_ClassMetadata_Exception If trying use wrongly typed parameter. 666 * @todo Rename to mapField()/addFieldMapping(). 666 667 */ 667 668 public function mapColumn($name, $type, $length = null, $options = array()) … … 784 785 785 786 /** 786 * Checks whether the classmapped class has a default value on any field.787 * Checks whether the mapped class has a default value on any field. 787 788 * 788 789 * @return boolean TRUE if the entity has a default value on any field, otherwise false. 789 790 */ 790 public function hasDefaultValues()791 /*public function hasDefaultValues() 791 792 { 792 793 return $this->_hasDefaultValues; 793 } 794 }*/ 794 795 795 796 /** … … 800 801 * @return mixed 801 802 */ 802 public function getDefaultValueOf($fieldName)803 /*public function getDefaultValueOf($fieldName) 803 804 { 804 805 if ( ! isset($this->_fieldMappings[$fieldName])) { … … 810 811 return null; 811 812 } 812 } 813 814 /** 815 * Gets the identifier (primary key) field (s) of the mappedclass.813 }*/ 814 815 /** 816 * Gets the identifier (primary key) field names of the class. 816 817 * 817 818 * @return mixed … … 824 825 825 826 /** 826 * Gets the identifier (primary key) field (s) of the mappedclass.827 * Gets the identifier (primary key) field names of the class. 827 828 * 828 829 * @return mixed … … 840 841 /** 841 842 * Gets the type of the identifier (primary key) used by the mapped class. The type 842 * can be either <tt>Doctrine::IDENTIFIER_NATURAL</tt>, <tt>Doctrine::IDENTIFIER_AUTOINCREMENT</tt>, 843 * <tt>Doctrine::IDENTIFIER_SEQUENCE</tt> or <tt>Doctrine::IDENTIFIER_COMPOSITE</tt>. 843 * can be either 844 * <tt>Doctrine::IDENTIFIER_NATURAL</tt>, 845 * <tt>Doctrine::IDENTIFIER_AUTOINCREMENT</tt>, 846 * <tt>Doctrine::IDENTIFIER_SEQUENCE</tt> or 847 * <tt>Doctrine::IDENTIFIER_COMPOSITE</tt>. 844 848 * 845 849 * @return integer … … 856 860 { 857 861 $this->_identifierType = $type; 858 }859 860 /**861 * hasColumn862 * @return boolean863 * @deprecated864 */865 public function hasColumn($columnName)866 {867 return isset($this->_fieldNames[$columnName]);868 862 } 869 863 … … 886 880 * @return array 887 881 */ 888 public function getEnumValues($fieldName)882 /*public function getEnumValues($fieldName) 889 883 { 890 884 if (isset($this->_fieldMappings[$fieldName]['values'])) { … … 893 887 return array(); 894 888 } 895 } 889 }*/ 896 890 897 891 /** … … 902 896 * @return mixed 903 897 */ 904 public function enumValue($fieldName, $index)898 /*public function enumValue($fieldName, $index) 905 899 { 906 900 if ($index instanceof Doctrine_Null) { … … 922 916 923 917 return $enumValue; 924 } 918 }*/ 925 919 926 920 /** … … 931 925 * @return mixed 932 926 */ 933 public function enumIndex($fieldName, $value)927 /*public function enumIndex($fieldName, $value) 934 928 { 935 929 $values = $this->getEnumValues($fieldName); … … 940 934 941 935 return $value; 942 } 936 }*/ 943 937 944 938 /** … … 948 942 * @deprecated 949 943 */ 950 public function getColumnCount()944 /*public function getColumnCount() 951 945 { 952 946 return $this->_columnCount; 953 } 947 }*/ 954 948 955 949 /** … … 958 952 * @return integer the number of mapped columns in the class. 959 953 */ 960 public function getMapped ColumnCount()954 public function getMappedFieldCount() 961 955 { 962 956 return $this->_columnCount; … … 964 958 965 959 /** 966 * 960 * Gets the custom accessor of a field. 961 * 967 962 * @return string The name of the accessor (getter) method or NULL if the field does 968 963 * not have a custom accessor. … … 975 970 976 971 /** 977 * 972 * Gets the custom mutator of a field. 973 * 978 974 * @return string The name of the mutator (setter) method or NULL if the field does 979 975 * not have a custom mutator. … … 984 980 $this->_fieldMappings[$fieldName]['mutator'] : null; 985 981 } 986 987 /** 988 * returns all columns and their definitions 989 * 990 * @return array 991 * @deprecated 992 */ 993 public function getColumns() 994 { 995 return $this->_fieldMappings; 996 } 997 998 /** 999 * Gets all mapped columns and their mapping definitions. 1000 * 1001 * @return array 1002 */ 1003 public function getMappedColumns() 1004 { 1005 return $this->_fieldMappings; 1006 } 1007 982 983 /** 984 * Gets all field mappings. 985 * 986 * @return unknown 987 */ 1008 988 public function getFieldMappings() 1009 989 { … … 1017 997 * @return boolean 1018 998 */ 1019 public function removeColumn($fieldName)999 /*public function removeColumn($fieldName) 1020 1000 { 1021 1001 $columnName = array_search($fieldName, $this->_fieldNames); … … 1030 1010 1031 1011 return false; 1032 } 1012 }*/ 1033 1013 1034 1014 /** … … 1077 1057 * @deprecated 1078 1058 */ 1079 public function getDefinitionOf($fieldName)1059 /*public function getDefinitionOf($fieldName) 1080 1060 { 1081 1061 $columnName = $this->getColumnName($fieldName); 1082 1062 1083 1063 return $this->getColumnDefinition($columnName); 1084 } 1085 1086 /** 1087 * Gets the mapping information for a field. 1088 * 1089 * @param string $fieldName 1090 * @return array 1091 */ 1092 public function getMappingForField($fieldName) 1093 { 1094 return $this->_fieldMappings[$fieldName]; 1095 } 1096 1097 /** 1098 * getTypeOf 1099 * 1100 * @return mixed string on success, false on failure 1101 * @deprecated 1102 */ 1103 public function getTypeOf($fieldName) 1104 { 1105 1106 return $this->getTypeOfColumn($this->getColumnName($fieldName)); 1107 } 1064 }*/ 1108 1065 1109 1066 /** … … 1162 1119 { 1163 1120 //... 1164 }1165 1166 public function bindRelation($args, $type)1167 {1168 return $this->bind($args, $type);1169 }1170 1171 /**1172 * DESCRIBE WHAT THIS METHOD DOES, PLEASE!1173 *1174 * @todo Name proposal: addRelation1175 */1176 public function bind($args, $type)1177 {1178 $options = array();1179 $options['type'] = $type;1180 1181 if ( ! isset($args[1])) {1182 $args[1] = array();1183 }1184 if ( ! is_array($args[1])) {1185 try {1186 throw new Exception();1187 } catch (Exception $e) {1188 echo $e->getTraceAsString();1189 }1190 }1191 $options = array_merge($args[1], $options);1192 $this->_parser->bind($args[0], $options);1193 }1194 1195 /**1196 * hasRelation1197 *1198 * @param string $alias the relation to check if exists1199 * @return boolean true if the relation exists otherwise false1200 */1201 public function hasRelation($alias)1202 {1203 return $this->_parser->hasRelation($alias);1204 }1205 1206 /**1207 * getRelation1208 *1209 * @param string $alias relation alias1210 */1211 public function getRelation($alias, $recursive = true)1212 {1213 return $this->_parser->getRelation($alias, $recursive);1214 }1215 1216 public function getRelationParser()1217 {1218 return $this->_parser;1219 }1220 1221 /**1222 * getRelations1223 * returns an array containing all relation objects1224 *1225 * @return array an array of Doctrine_Relation objects1226 */1227 public function getRelations()1228 {1229 return $this->_parser->getRelations();1230 1121 } 1231 1122 … … 2059 1950 } 2060 1951 } 2061 1952 1953 /* The following stuff needs to be touched for the association mapping rewrite */ 1954 1955 public function bindRelation($args, $type) 1956 { 1957 return $this->bind($args, $type); 1958 } 1959 1960 /** 1961 * @todo Relation mapping rewrite. 1962 */ 1963 public function bind($args, $type) 1964 { 1965 $options = array(); 1966 $options['type'] = $type; 1967 1968 if ( ! isset($args[1])) { 1969 $args[1] = array(); 1970 } 1971 if ( ! is_array($args[1])) { 1972 try { 1973 throw new Exception(); 1974 } catch (Exception $e) { 1975 echo $e->getTraceAsString(); 1976 } 1977 } 1978 $options = array_merge($args[1], $options); 1979 $this->_parser->bind($args[0], $options); 1980 } 1981 1982 /** 1983 * hasRelation 1984 * 1985 * @param string $alias the relation to check if exists 1986 * @return boolean true if the relation exists otherwise false 1987 */ 1988 public function hasRelation($alias) 1989 { 1990 return $this->_parser->hasRelation($alias); 1991 } 1992 1993 /** 1994 * getRelation 1995 * 1996 * @param string $alias relation alias 1997 */ 1998 public function getRelation($alias, $recursive = true) 1999 { 2000 return $this->_parser->getRelation($alias, $recursive); 2001 } 2002 2003 public function getRelationParser() 2004 { 2005 return $this->_parser; 2006 } 2007 2008 /** 2009 * getRelations 2010 * returns an array containing all relation objects 2011 * 2012 * @return array an array of Doctrine_Relation objects 2013 */ 2014 public function getRelations() 2015 { 2016 return $this->_parser->getRelations(); 2017 } 2062 2018 2063 2019 /** -
trunk/lib/Doctrine/ClassMetadata/Factory.php
r4653 r4655 131 131 protected function _addInheritedFields($subClass, $parentClass) 132 132 { 133 foreach ($parentClass->get Columns() as $name => $definition) {133 foreach ($parentClass->getFieldMappings() as $name => $definition) { 134 134 $fullName = "$name as " . $parentClass->getFieldName($name); 135 135 $definition['inherited'] = true; … … 247 247 foreach ($class->getIdentifier() as $pk) { 248 248 $columnName = $class->getColumnName($pk); 249 $thisColumns = $class->get Columns();249 $thisColumns = $class->getFieldMappings(); 250 250 $e = $thisColumns[$columnName]; 251 251 -
trunk/lib/Doctrine/Entity.php
r4653 r4655 343 343 344 344 foreach ($this->_data as $k => $v) { 345 if ($v instanceof Doctrine_Entity && $this->_class->getTypeOf ($k) != 'object') {345 if ($v instanceof Doctrine_Entity && $this->_class->getTypeOfField($k) != 'object') { 346 346 unset($vars['_data'][$k]); 347 347 } else if ($v === Doctrine_Null::$INSTANCE) { 348 348 unset($vars['_data'][$k]); 349 349 } else { 350 switch ($this->_class->getTypeOf ($k)) {350 switch ($this->_class->getTypeOfField($k)) { 351 351 case 'array': 352 352 case 'object': … … 401 401 402 402 foreach ($this->_data as $k => $v) { 403 switch ($this->_class->getTypeOf ($k)) {403 switch ($this->_class->getTypeOfField($k)) { 404 404 case 'array': 405 405 case 'object': … … 1025 1025 1026 1026 foreach ($modifiedFields as $field) { 1027 $type = $this->_class->getTypeOf ($field);1027 $type = $this->_class->getTypeOfField($field); 1028 1028 1029 1029 if ($this->_data[$field] === Doctrine_Null::$INSTANCE) { -
trunk/lib/Doctrine/HydratorNew.php
r4653 r4655 110 110 reset($this->_queryComponents); 111 111 $rootAlias = key($this->_queryComponents); 112 $root ComponentName = $this->_queryComponents[$rootAlias]['metadata']->getClassName();112 $rootEntityName = $this->_queryComponents[$rootAlias]['metadata']->getClassName(); 113 113 // if only one class is involved we can make our lives easier 114 114 $isSimpleQuery = count($this->_queryComponents) <= 1; … … 129 129 $result = array(); 130 130 } else { 131 $result = $driver->getElementCollection($root ComponentName);131 $result = $driver->getElementCollection($rootEntityName); 132 132 } 133 133 … … 140 140 // disable lazy-loading of related elements during hydration 141 141 $component['metadata']->setAttribute('loadReferences', false); 142 $ componentName = $component['metadata']->getClassName();142 $entityName = $component['metadata']->getClassName(); 143 143 $identifierMap[$dqlAlias] = array(); 144 144 $resultPointers[$dqlAlias] = array(); … … 164 164 } 165 165 166 // From here on its all about graph construction 167 168 // 1) Initialize 166 169 $id = $idTemplate; // initialize the id-memory 167 170 $nonemptyComponents = array(); 168 171 $rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents); 169 172 170 // 171 // hydrate the data of the root entity from the current row 172 // 173 $class = $this->_queryComponents[$rootAlias]['metadata']; 174 $componentName = $class->getComponentName(); 173 // 2) Hydrate the data of the root entity from the current row 174 //$class = $this->_queryComponents[$rootAlias]['metadata']; 175 //$entityName = $class->getComponentName(); 175 176 176 177 // Check for an existing element 177 178 $index = false; 178 179 if ($isSimpleQuery || ! isset($identifierMap[$rootAlias][$id[$rootAlias]])) { 179 $element = $driver->getElement($rowData[$rootAlias], $componentName); 180 181 // do we need to index by a custom field? 180 $element = $driver->getElement($rowData[$rootAlias], $rootEntityName); 182 181 if ($field = $this->_getCustomIndexField($rootAlias)) { 183 182 if ($parserResult->isMixedQuery()) { … … 199 198 $index = $identifierMap[$rootAlias][$id[$rootAlias]]; 200 199 } 201 $this->_ setLastElement($resultPointers, $result, $index, $rootAlias, false);200 $this->_updateResultPointer($resultPointers, $result, $index, $rootAlias, false); 202 201 unset($rowData[$rootAlias]); 203 202 // end hydrate data of the root component for the current row 204 203 205 // Check for scalar values204 // Extract scalar values. They're appended at the end. 206 205 if (isset($rowData['scalars'])) { 207 206 $scalars = $rowData['scalars']; … … 209 208 } 210 209 211 // now hydrate the rest of the data found in the current row, that belongs to other212 // (related) classes.210 // 3) Now hydrate the rest of the data found in the current row, that 211 // belongs to other (related) Entities. 213 212 foreach ($rowData as $dqlAlias => $data) { 214 213 $index = false; 215 214 $map = $this->_queryComponents[$dqlAlias]; 216 $ componentName = $map['metadata']->getClassName();215 $entityName = $map['metadata']->getClassName(); 217 216 $parent = $map['parent']; 218 217 $relation = $map['relation']; … … 228 227 $baseElement =& $resultPointers[$parent]; 229 228 } else { 230 unset($ prev[$dqlAlias]); // Ticket #1228229 unset($resultPointers[$dqlAlias]); // Ticket #1228 231 230 continue; 232 231 } … … 242 241 $indexIsValid = $index !== false ? isset($baseElement[$relationAlias][$index]) : false; 243 242 if ( ! $indexExists || ! $indexIsValid) { 244 $element = $driver->getElement($data, $ componentName);243 $element = $driver->getElement($data, $entityName); 245 244 if ($field = $this->_getCustomIndexField($dqlAlias)) { 246 245 $driver->addRelatedIndexedElement($baseElement, $relationAlias, $element, $field); … … 253 252 } else if ( ! isset($baseElement[$relationAlias])) { 254 253 $driver->setRelatedElement($baseElement, $relationAlias, 255 $driver->getElementCollection($ componentName));254 $driver->getElementCollection($entityName)); 256 255 } 257 256 } else { … … 264 263 } else if ( ! $driver->isFieldSet($baseElement, $relationAlias)) { 265 264 $driver->setRelatedElement($baseElement, $relationAlias, 266 $driver->getElement($data, $ componentName));265 $driver->getElement($data, $entityName)); 267 266 } 268 267 } 269 268 if (($coll =& $driver->getReferenceValue($baseElement, $relationAlias)) !== null) { 270 $this->_ setLastElement($resultPointers, $coll, $index, $dqlAlias, $oneToOne);269 $this->_updateResultPointer($resultPointers, $coll, $index, $dqlAlias, $oneToOne); 271 270 } 272 271