Changeset 4655 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
07/11/08 11:48:04 (6 months ago)
Author:
romanb
Message:

Cleanups, improvements, fixes.

Location:
trunk/lib/Doctrine
Files:
1 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine/ClassMetadata.php

    r4653 r4655  
    541541 
    542542    /** 
    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. 
    551549     */ 
    552550    public function getColumnName($fieldName) 
     
    557555 
    558556    /** 
    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     */ 
    566563    public function getFieldMapping($fieldName) 
    567564    { 
     
    569566                $this->_fieldMappings[$fieldName] : false; 
    570567    } 
     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    } 
    571580 
    572581    /** 
     
    589598     * @param string $lcColumnName 
    590599     * @return string 
     600     * @todo Better name. 
    591601     */ 
    592602    public function getFieldNameForLowerColumnName($lcColumnName) 
     
    642652 
    643653    /** 
    644      * @deprecated 
    645      */ 
    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     /** 
    654654     * Maps a field of the class to a database column. 
    655655     * 
     
    664664     * 
    665665     * @throws Doctrine_ClassMetadata_Exception If trying use wrongly typed parameter. 
     666     * @todo Rename to mapField()/addFieldMapping(). 
    666667     */ 
    667668    public function mapColumn($name, $type, $length = null, $options = array()) 
     
    784785 
    785786    /** 
    786      * Checks whether the class mapped class has a default value on any field. 
     787     * Checks whether the mapped class has a default value on any field. 
    787788     * 
    788789     * @return boolean  TRUE if the entity has a default value on any field, otherwise false. 
    789790     */ 
    790     public function hasDefaultValues() 
     791    /*public function hasDefaultValues() 
    791792    { 
    792793        return $this->_hasDefaultValues; 
    793     } 
     794    }*/ 
    794795 
    795796    /** 
     
    800801     * @return mixed 
    801802     */ 
    802     public function getDefaultValueOf($fieldName) 
     803    /*public function getDefaultValueOf($fieldName) 
    803804    { 
    804805        if ( ! isset($this->_fieldMappings[$fieldName])) { 
     
    810811            return null; 
    811812        } 
    812     } 
    813  
    814     /** 
    815      * Gets the identifier (primary key) field(s) of the mapped class. 
     813    }*/ 
     814 
     815    /** 
     816     * Gets the identifier (primary key) field names of the class. 
    816817     * 
    817818     * @return mixed 
     
    824825 
    825826    /** 
    826      * Gets the identifier (primary key) field(s) of the mapped class. 
     827     * Gets the identifier (primary key) field names of the class. 
    827828     * 
    828829     * @return mixed 
     
    840841    /** 
    841842     * 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>. 
    844848     * 
    845849     * @return integer 
     
    856860    { 
    857861        $this->_identifierType = $type; 
    858     } 
    859  
    860     /** 
    861      * hasColumn 
    862      * @return boolean 
    863      * @deprecated 
    864      */ 
    865     public function hasColumn($columnName) 
    866     { 
    867         return isset($this->_fieldNames[$columnName]); 
    868862    } 
    869863 
     
    886880     * @return array 
    887881     */ 
    888     public function getEnumValues($fieldName) 
     882    /*public function getEnumValues($fieldName) 
    889883    { 
    890884        if (isset($this->_fieldMappings[$fieldName]['values'])) { 
     
    893887            return array(); 
    894888        } 
    895     } 
     889    }*/ 
    896890 
    897891    /** 
     
    902896     * @return mixed 
    903897     */ 
    904     public function enumValue($fieldName, $index) 
     898    /*public function enumValue($fieldName, $index) 
    905899    { 
    906900        if ($index instanceof Doctrine_Null) { 
     
    922916 
    923917        return $enumValue; 
    924     } 
     918    }*/ 
    925919 
    926920    /** 
     
    931925     * @return mixed 
    932926     */ 
    933     public function enumIndex($fieldName, $value) 
     927    /*public function enumIndex($fieldName, $value) 
    934928    { 
    935929        $values = $this->getEnumValues($fieldName); 
     
    940934 
    941935        return $value; 
    942     } 
     936    }*/ 
    943937 
    944938    /** 
     
    948942     * @deprecated 
    949943     */ 
    950     public function getColumnCount() 
     944    /*public function getColumnCount() 
    951945    { 
    952946        return $this->_columnCount; 
    953     } 
     947    }*/ 
    954948 
    955949    /** 
     
    958952     * @return integer      the number of mapped columns in the class. 
    959953     */ 
    960     public function getMappedColumnCount() 
     954    public function getMappedFieldCount() 
    961955    { 
    962956        return $this->_columnCount; 
     
    964958 
    965959    /** 
    966      * 
     960     * Gets the custom accessor of a field. 
     961     *  
    967962     * @return string  The name of the accessor (getter) method or NULL if the field does 
    968963     *                 not have a custom accessor. 
     
    975970 
    976971    /** 
    977      * 
     972     * Gets the custom mutator of a field. 
     973     *  
    978974     * @return string  The name of the mutator (setter) method or NULL if the field does 
    979975     *                 not have a custom mutator. 
     
    984980                $this->_fieldMappings[$fieldName]['mutator'] : null; 
    985981    } 
    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     */ 
    1008988    public function getFieldMappings() 
    1009989    { 
     
    1017997     * @return boolean 
    1018998     */ 
    1019     public function removeColumn($fieldName) 
     999    /*public function removeColumn($fieldName) 
    10201000    { 
    10211001        $columnName = array_search($fieldName, $this->_fieldNames); 
     
    10301010 
    10311011        return false; 
    1032     } 
     1012    }*/ 
    10331013 
    10341014    /** 
     
    10771057     * @deprecated 
    10781058     */ 
    1079     public function getDefinitionOf($fieldName) 
     1059    /*public function getDefinitionOf($fieldName) 
    10801060    { 
    10811061        $columnName = $this->getColumnName($fieldName); 
    10821062 
    10831063        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    }*/ 
    11081065     
    11091066    /** 
     
    11621119    { 
    11631120        //... 
    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: addRelation 
    1175      */ 
    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      * hasRelation 
    1197      * 
    1198      * @param string $alias      the relation to check if exists 
    1199      * @return boolean           true if the relation exists otherwise false 
    1200      */ 
    1201     public function hasRelation($alias) 
    1202     { 
    1203         return $this->_parser->hasRelation($alias); 
    1204     } 
    1205  
    1206     /** 
    1207      * getRelation 
    1208      * 
    1209      * @param string $alias      relation alias 
    1210      */ 
    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      * getRelations 
    1223      * returns an array containing all relation objects 
    1224      * 
    1225      * @return array        an array of Doctrine_Relation objects 
    1226      */ 
    1227     public function getRelations() 
    1228     { 
    1229         return $this->_parser->getRelations(); 
    12301121    } 
    12311122 
     
    20591950        } 
    20601951    } 
    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    } 
    20622018 
    20632019    /** 
  • trunk/lib/Doctrine/ClassMetadata/Factory.php

    r4653 r4655  
    131131    protected function _addInheritedFields($subClass, $parentClass) 
    132132    { 
    133         foreach ($parentClass->getColumns() as $name => $definition) { 
     133        foreach ($parentClass->getFieldMappings() as $name => $definition) { 
    134134            $fullName = "$name as " . $parentClass->getFieldName($name); 
    135135            $definition['inherited'] = true; 
     
    247247                foreach ($class->getIdentifier() as $pk) { 
    248248                    $columnName = $class->getColumnName($pk); 
    249                     $thisColumns = $class->getColumns(); 
     249                    $thisColumns = $class->getFieldMappings(); 
    250250                    $e = $thisColumns[$columnName]; 
    251251 
  • trunk/lib/Doctrine/Entity.php

    r4653 r4655  
    343343 
    344344        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') { 
    346346                unset($vars['_data'][$k]); 
    347347            } else if ($v === Doctrine_Null::$INSTANCE) { 
    348348                unset($vars['_data'][$k]); 
    349349            } else { 
    350                 switch ($this->_class->getTypeOf($k)) { 
     350                switch ($this->_class->getTypeOfField($k)) { 
    351351                    case 'array': 
    352352                    case 'object': 
     
    401401 
    402402        foreach ($this->_data as $k => $v) { 
    403             switch ($this->_class->getTypeOf($k)) { 
     403            switch ($this->_class->getTypeOfField($k)) { 
    404404                case 'array': 
    405405                case 'object': 
     
    10251025 
    10261026        foreach ($modifiedFields as $field) { 
    1027             $type = $this->_class->getTypeOf($field); 
     1027            $type = $this->_class->getTypeOfField($field); 
    10281028 
    10291029            if ($this->_data[$field] === Doctrine_Null::$INSTANCE) { 
  • trunk/lib/Doctrine/HydratorNew.php

    r4653 r4655  
    110110        reset($this->_queryComponents); 
    111111        $rootAlias = key($this->_queryComponents); 
    112         $rootComponentName = $this->_queryComponents[$rootAlias]['metadata']->getClassName(); 
     112        $rootEntityName = $this->_queryComponents[$rootAlias]['metadata']->getClassName(); 
    113113        // if only one class is involved we can make our lives easier 
    114114        $isSimpleQuery = count($this->_queryComponents) <= 1; 
     
    129129            $result = array(); 
    130130        } else { 
    131             $result = $driver->getElementCollection($rootComponentName); 
     131            $result = $driver->getElementCollection($rootEntityName); 
    132132        }   
    133133 
     
    140140            // disable lazy-loading of related elements during hydration 
    141141            $component['metadata']->setAttribute('loadReferences', false); 
    142             $componentName = $component['metadata']->getClassName(); 
     142            $entityName = $component['metadata']->getClassName(); 
    143143            $identifierMap[$dqlAlias] = array(); 
    144144            $resultPointers[$dqlAlias] = array(); 
     
    164164            } 
    165165             
     166            // From here on its all about graph construction             
     167             
     168            // 1) Initialize 
    166169            $id = $idTemplate; // initialize the id-memory 
    167170            $nonemptyComponents = array(); 
    168171            $rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents); 
    169172 
    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(); 
    175176             
    176177            // Check for an existing element 
    177178            $index = false; 
    178179            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); 
    182181                if ($field = $this->_getCustomIndexField($rootAlias)) { 
    183182                    if ($parserResult->isMixedQuery()) { 
     
    199198                $index = $identifierMap[$rootAlias][$id[$rootAlias]]; 
    200199            } 
    201             $this->_setLastElement($resultPointers, $result, $index, $rootAlias, false); 
     200            $this->_updateResultPointer($resultPointers, $result, $index, $rootAlias, false); 
    202201            unset($rowData[$rootAlias]); 
    203202            // end hydrate data of the root component for the current row 
    204203             
    205             // Check for scalar values 
     204            // Extract scalar values. They're appended at the end. 
    206205            if (isset($rowData['scalars'])) { 
    207206                $scalars = $rowData['scalars']; 
     
    209208            } 
    210209             
    211             // now hydrate the rest of the data found in the current row, that belongs to other 
    212             // (related) classes. 
     210            // 3) Now hydrate the rest of the data found in the current row, that 
     211            // belongs to other (related) Entities. 
    213212            foreach ($rowData as $dqlAlias => $data) {                 
    214213                $index = false; 
    215214                $map = $this->_queryComponents[$dqlAlias]; 
    216                 $componentName = $map['metadata']->getClassName(); 
     215                $entityName = $map['metadata']->getClassName(); 
    217216                $parent = $map['parent']; 
    218217                $relation = $map['relation']; 
     
    228227                    $baseElement =& $resultPointers[$parent]; 
    229228                } else { 
    230                     unset($prev[$dqlAlias]); // Ticket #1228 
     229                    unset($resultPointers[$dqlAlias]); // Ticket #1228 
    231230                    continue; 
    232231                } 
     
    242241                        $indexIsValid = $index !== false ? isset($baseElement[$relationAlias][$index]) : false; 
    243242                        if ( ! $indexExists || ! $indexIsValid) { 
    244                             $element = $driver->getElement($data, $componentName); 
     243                            $element = $driver->getElement($data, $entityName); 
    245244                            if ($field = $this->_getCustomIndexField($dqlAlias)) { 
    246245                                $driver->addRelatedIndexedElement($baseElement, $relationAlias, $element, $field); 
     
    253252                    } else if ( ! isset($baseElement[$relationAlias])) { 
    254253                        $driver->setRelatedElement($baseElement, $relationAlias, 
    255                                 $driver->getElementCollection($componentName)); 
     254                                $driver->getElementCollection($entityName)); 
    256255                    } 
    257256                } else { 
     
    264263                    } else if ( ! $driver->isFieldSet($baseElement, $relationAlias)) { 
    265264                        $driver->setRelatedElement($baseElement, $relationAlias, 
    266                                 $driver->getElement($data, $componentName)); 
     265                                $driver->getElement($data, $entityName)); 
    267266                    } 
    268267                } 
    269268                if (($coll =& $driver->getReferenceValue($baseElement, $relationAlias)) !== null) { 
    270                     $this->_setLastElement($resultPointers, $coll, $index, $dqlAlias, $oneToOne);    
     269                    $this->_updateResultPointer($resultPointers, $coll, $index, $dqlAlias, $oneToOne);    
    271270                } 
    272271