Changeset 4776 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
08/16/08 20:40:59 (5 months ago)
Author:
romanb
Message:

continued refactorings.

Location:
trunk/lib/Doctrine
Files:
3 added
27 modified

Legend:

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

    r4718 r4776  
    3535 * @version     $Revision$ 
    3636 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi> 
    37  * @todo Consider making Collection & Entity implement ArrayAccess directly. 
    38  *       This base class is not really a huge benefit. 
     37 * @todo Remove. 
    3938 */ 
    4039abstract class Doctrine_Access implements ArrayAccess 
  • trunk/lib/Doctrine/Association.php

    r4699 r4776  
    2525 * Base class for association mappings. 
    2626 * 
     27 * @author Roman Borschel <roman@code-factory.org> 
    2728 * @since 2.0 
    28  * @author Roman Borschel <roman@code-factory.org> 
    2929 * @todo Rename to AssociationMapping. 
    3030 */ 
     
    5353    protected $_isCascadeRefresh; 
    5454     
     55    protected $_customAccessor; 
     56    protected $_customMutator; 
     57     
    5558    /** 
    5659     * The fetch mode used for the association. 
     
    6972     
    7073    /** 
     74     * Whether the association is optional (0..X) or not (1..X). 
     75     * By default all associations are optional. 
     76     * 
     77     * @var boolean 
     78     */ 
     79    protected $_isOptional = true; 
     80     
     81    /** 
    7182     * The name of the source Entity (the Entity that defines this mapping). 
    7283     * 
     
    8596    /** 
    8697     * Identifies the field on the source class (the class this AssociationMapping 
    87      * belongs to) that represents the association. 
     98     * belongs to) that represents the association and stores the reference to the 
     99     * other entity/entities. 
    88100     * 
    89101     * @var string 
     
    107119    public function __construct(array $mapping) 
    108120    { 
    109         $this->_validateMapping($mapping); 
    110         if ($this->_isOwningSide) { 
    111             $this->_sourceEntityName = $mapping['sourceEntity']; 
    112             $this->_targetEntityName = $mapping['targetEntity']; 
    113             $this->_sourceFieldName = $mapping['fieldName']; 
    114         } else { 
     121        $this->_validateAndCompleteMapping($mapping); 
     122         
     123        $this->_sourceEntityName = $mapping['sourceEntity']; 
     124        $this->_targetEntityName = $mapping['targetEntity']; 
     125        $this->_sourceFieldName = $mapping['fieldName']; 
     126         
     127        if ( ! $this->_isOwningSide) { 
    115128            $this->_mappedByFieldName = $mapping['mappedBy']; 
    116129        }         
     
    123136     * @return array  The validated & completed mapping. 
    124137     */ 
    125     protected function _validateMapping(array $mapping) 
    126     { 
     138    protected function _validateAndCompleteMapping(array $mapping) 
     139    {         
    127140        if (isset($mapping['mappedBy'])) { 
     141            // Inverse side, mapping can be found on the owning side. 
    128142            $this->_isOwningSide = false; 
    129         } 
    130          
    131         if ($this->_isOwningSide) { 
    132             if ( ! isset($mapping['targetEntity'])) { 
    133                 throw Doctrine_MappingException::missingTargetEntity(); 
    134             } else if ( ! isset($mapping['fieldName'])) { 
    135                 throw Doctrine_MappingException::missingFieldName(); 
    136             } 
    137         } 
     143        } else { 
     144            // Owning side 
     145        } 
     146         
     147        // Mandatory attributes 
     148        if ( ! isset($mapping['fieldName'])) { 
     149            throw Doctrine_MappingException::missingFieldName(); 
     150        } 
     151        if ( ! isset($mapping['sourceEntity'])) { 
     152            throw Doctrine_MappingException::missingSourceEntity($mapping['fieldName']); 
     153        } 
     154        if ( ! isset($mapping['targetEntity'])) { 
     155            throw Doctrine_MappingException::missingTargetEntity($mapping['fieldName']); 
     156        } 
     157         
     158        // Optional attributes 
     159        $this->_customAccessor = isset($mapping['accessor']) ? $mapping['accessor'] : null; 
     160        $this->_customMutator = isset($mapping['mutator']) ? $mapping['mutator'] : null; 
     161        $this->_isOptional = isset($mapping['isOptional']) ? (bool)$mapping['isOptional'] : true; 
    138162 
    139163        return $mapping; 
    140164    } 
    141165     
     166    protected function _validateAndCompleteInverseSideMapping() 
     167    { 
     168         
     169    } 
     170     
     171    protected function _validateAndCompleteOwningSideMapping() 
     172    { 
     173         
     174    } 
     175     
     176    /** 
     177     * Whether the association cascades delete() operations from the source entity 
     178     * to the target entity/entities. 
     179     * 
     180     * @return boolean 
     181     */ 
    142182    public function isCascadeDelete() 
    143183    { 
     
    148188    } 
    149189     
     190    /** 
     191     * Whether the association cascades save() operations from the source entity 
     192     * to the target entity/entities. 
     193     * 
     194     * @return boolean 
     195     */ 
    150196    public function isCascadeSave() 
    151197    { 
     
    156202    } 
    157203     
     204    /** 
     205     * Whether the association cascades refresh() operations from the source entity 
     206     * to the target entity/entities. 
     207     * 
     208     * @return boolean 
     209     */ 
    158210    public function isCascadeRefresh() 
    159211    { 
     
    164216    } 
    165217     
     218    /** 
     219     * Whether the target entity/entities of the association are eagerly fetched. 
     220     * 
     221     * @return boolean 
     222     */ 
    166223    public function isEagerlyFetched() 
    167224    { 
     
    169226    } 
    170227     
     228    /** 
     229     * Whether the target entity/entities of the association are lazily fetched. 
     230     * 
     231     * @return boolean 
     232     */ 
    171233    public function isLazilyFetched() 
    172234    { 
     
    174236    } 
    175237     
     238    /** 
     239     * Whether the target entity/entities of the association are manually fetched. 
     240     * 
     241     * @return boolean 
     242     */ 
    176243    public function isManuallyFetched() 
    177244    { 
     
    179246    } 
    180247     
     248    /** 
     249     * Whether the source entity of this association represents the owning side. 
     250     * 
     251     * @return boolean 
     252     */ 
    181253    public function isOwningSide() 
    182254    { 
     
    184256    } 
    185257     
     258    /** 
     259     * Whether the source entity of this association represents the inverse side. 
     260     * 
     261     * @return boolean 
     262     */ 
    186263    public function isInverseSide() 
    187264    { 
     
    189266    } 
    190267     
     268    /** 
     269     * Whether the association is optional (0..X), or not (1..X). 
     270     * 
     271     * @return boolean TRUE if the association is optional, FALSE otherwise. 
     272     */ 
     273    public function isOptional() 
     274    { 
     275        return $this->_isOptional; 
     276    } 
     277     
     278    /** 
     279     * Gets the name of the source entity class. 
     280     * 
     281     * @return string 
     282     */ 
    191283    public function getSourceEntityName() 
    192284    { 
     
    194286    } 
    195287     
     288    /** 
     289     * Gets the name of the target entity class. 
     290     * 
     291     * @return string 
     292     */ 
    196293    public function getTargetEntityName() 
    197294    { 
     
    202299     * Get the name of the field the association is mapped into. 
    203300     * 
     301     * @return string 
    204302     */ 
    205303    public function getSourceFieldName() 
     
    208306    } 
    209307     
     308    /** 
     309     * Gets the field name of the owning side in a bi-directional association. 
     310     * 
     311     * @return string 
     312     */ 
    210313    public function getMappedByFieldName() 
    211314    { 
    212315        return $this->_mappedByFieldName; 
     316    } 
     317     
     318    /** 
     319     * Whether the source field of the association has a custom accessor. 
     320     * 
     321     * @return boolean TRUE if the source field of the association has a custom accessor, 
     322     *                 FALSE otherwise. 
     323     */ 
     324    public function hasCustomAccessor() 
     325    { 
     326        return isset($this->_customAccessor); 
     327    } 
     328     
     329    /** 
     330     * Gets the name of the custom accessor method of the source field. 
     331     * 
     332     * @return string The name of the accessor method or NULL. 
     333     */ 
     334    public function getCustomAccessor() 
     335    { 
     336        return $this->_customAccessor; 
     337    } 
     338     
     339    /** 
     340     * Whether the source field of the association has a custom mutator. 
     341     * 
     342     * @return boolean TRUE if the source field of the association has a custom mutator, 
     343     *                 FALSE otherwise. 
     344     */ 
     345    public function hasCustomMutator() 
     346    { 
     347        return isset($this->_customMutator); 
     348    } 
     349     
     350    /** 
     351     * Gets the name of the custom mutator method of the source field. 
     352     * 
     353     * @return string The name of the mutator method or NULL. 
     354     */ 
     355    public function getCustomMutator() 
     356    { 
     357        return $this->_customMutator; 
     358    } 
     359     
     360    public function isOneToOne() 
     361    { 
     362        return false; 
     363    } 
     364     
     365    public function isOneToMany() 
     366    { 
     367        return false; 
     368    } 
     369     
     370    public function isManyToMany() 
     371    { 
     372        return false; 
    213373    } 
    214374     
  • trunk/lib/Doctrine/Association/OneToOne.php

    r4718 r4776  
    107107     
    108108    /** 
     109     * Whether the association is one-to-one. 
     110     * 
     111     * @return boolean 
     112     * @override 
     113     */ 
     114    public function isOneToOne() 
     115    { 
     116        return true; 
     117    } 
     118     
     119    /** 
    109120     * Lazy-loads the associated entity for a given entity. 
    110121     * 
  • trunk/lib/Doctrine/ClassMetadata.php

    r4723 r4776  
    4949     
    5050    /* The Entity types */ 
    51     // A regular entity is assumed to have persistent state that Doctrine should manage. 
     51    /** 
     52     * A regular entity is assumed to have persistent state that Doctrine should manage. 
     53     */ 
    5254    const ENTITY_TYPE_REGULAR = 'regular'; 
    53     // A transient entity is ignored by Doctrine. 
     55    /** 
     56     * A transient entity is ignored by Doctrine. 
     57     */ 
    5458    const ENTITY_TYPE_TRANSIENT = 'transient'; 
    55     // A mapped superclass entity is itself not persisted by Doctrine but it's 
    56     // field & association mappings are inherited by subclasses. 
     59    /** 
     60     * A mapped superclass entity is itself not persisted by Doctrine but it's 
     61     * field & association mappings are inherited by subclasses. 
     62     */ 
    5763    const ENTITY_TYPE_MAPPED_SUPERCLASS = 'mappedSuperclass'; 
    5864     
     
    123129     */ 
    124130    protected $_generatorType = self::GENERATOR_TYPE_NONE; 
    125  
    126     /** 
    127      * An array containing all behaviors attached to the class. 
    128      * 
    129      * @see Doctrine_Template 
    130      * @var array $_templates 
    131      * @todo Unify under 'Behaviors'. 
    132      */ 
    133     //protected $_behaviors = array(); 
    134131     
    135132    /** 
     
    219216     */ 
    220217    protected $_lcColumnToFieldNames = array(); 
    221      
    222     /** 
    223      * Enter description here... 
    224      * 
    225      * @var unknown_type 
    226      */ 
    227     //protected $_subclassFieldNames = array(); 
    228218 
    229219    /** 
     
    311301     */ 
    312302    protected $_isIdentifierComposite = false; 
     303     
     304    protected $_customAssociationAccessors = array(); 
     305    protected $_customAssociationMutators = array(); 
    313306 
    314307    /** 
     
    316309     * 
    317310     * @param string $entityName  Name of the entity class the metadata info is used for. 
     311     * @param Doctrine::ORM::Entitymanager $em 
    318312     */ 
    319313    public function __construct($entityName, Doctrine_EntityManager $em) 
     
    325319        $this->_parser = new Doctrine_Relation_Parser($this); 
    326320    } 
    327  
    328     /** 
    329      * @deprecated 
    330      */ 
    331     public function getConnection() 
    332     { 
    333         return $this->_em; 
    334     } 
    335      
     321     
     322    /** 
     323     * Gets the EntityManager that holds this ClassMetadata. 
     324     * 
     325     * @return Doctrine::ORM::EntityManager 
     326     */ 
    336327    public function getEntityManager() 
    337328    { 
     
    362353 
    363354    /** 
    364      * @deprecated 
    365      */ 
    366     public function getComponentName() 
    367     { 
    368         return $this->getClassName(); 
    369     } 
    370  
    371     /** 
    372355     * Checks whether a field is part of the identifier/primary key field(s). 
    373356     * 
     
    430413 
    431414    /** 
    432      * addIndex 
    433      * 
    434415     * adds an index to this table 
    435416     * 
     
    460441 
    461442    /** 
    462      * setOption 
    463      * sets an option and returns this object in order to 
    464      * allow flexible method chaining 
    465      * 
    466      * @see Doctrine_Table::$_options   for available options 
    467      * @param string $name              the name of the option to set 
    468      * @param mixed $value              the value of the option 
    469      * @return Doctrine_Table           this object 
    470      * @deprecated 
    471      */ 
    472     public function setOption($name, $value) 
    473     { 
    474         $this->_options[$name] = $value; 
    475     } 
    476  
    477     /** 
    478443     * Sets a table option. 
    479444     */ 
     
    496461 
    497462        return $this->_tableOptions[$name]; 
    498     } 
    499  
    500     /*public function getBehaviorForMethod($method) 
    501     { 
    502         return (isset($this->_invokedMethods[$method])) ? 
    503         $this->_invokedMethods[$method] : false; 
    504     } 
    505     public function addBehaviorMethod($method, $behavior) 
    506     { 
    507         $this->_invokedMethods[$method] = $class; 
    508     }*/ 
    509  
    510     /** 
    511      * returns the value of given option 
    512      * 
    513      * @param string $name  the name of the option 
    514      * @return mixed        the value of given option 
    515      */ 
    516     public function getOption($name) 
    517     { 
    518         if (isset($this->_options[$name])) { 
    519             return $this->_options[$name]; 
    520         } else if (isset($this->_tableOptions[$name])) { 
    521             return $this->_tableOptions[$name]; 
    522         } 
    523         return null; 
    524     } 
    525  
    526     /** 
    527      * getOptions 
    528      * returns all options of this table and the associated values 
    529      * 
    530      * @return array    all options and their values 
    531      */ 
    532     public function getOptions() 
    533     { 
    534         return $this->_options; 
    535463    } 
    536464 
     
    704632     * Validates & completes the field mapping. Default values are applied here. 
    705633     * 
    706      * @param array $mapping 
    707      * @return array 
     634     * @param array $mapping  The field mapping to validated & complete. 
     635     * @return array  The validated and completed field mapping. 
    708636     */ 
    709637    private function _validateAndCompleteFieldMapping(array $mapping) 
     
    802730 
    803731    /** 
    804      * Gets the names of all validators that are applied on a field. 
    805      * 
    806      * @param string  The field name. 
    807      * @return array  The names of all validators that are applied on the specified field. 
    808      */ 
    809     /*public function getFieldValidators($fieldName) 
    810     { 
    811         return isset($this->_fieldMappings[$fieldName]['validators']) ? 
    812                 $this->_fieldMappings[$fieldName]['validators'] : array(); 
    813     }*/ 
    814  
    815     /** 
    816732     * Gets the identifier (primary key) field names of the class. 
    817733     * 
     
    872788    public function getCustomAccessor($fieldName) 
    873789    { 
    874         return isset($this->_fieldMappings[$fieldName]['accessor']) ? 
    875                 $this->_fieldMappings[$fieldName]['accessor'] : null; 
     790        if (isset($this->_fieldMappings[$fieldName]['accessor'])) { 
     791            return $this->_fieldMappings[$fieldName]['accessor']; 
     792        } else if (isset($this->_customAssociationAccessors[$fieldName])) { 
     793            return $this->_customAssociationAccessors[$fieldName]; 
     794        } 
     795        return null; 
    876796    } 
    877797 
     
    884804    public function getCustomMutator($fieldName) 
    885805    { 
    886         return isset($this->_fieldMappings[$fieldName]['mutator']) ? 
    887                 $this->_fieldMappings[$fieldName]['mutator'] : null; 
     806        if (isset($this->_fieldMappings[$fieldName]['mutator'])) { 
     807            return $this->_fieldMappings[$fieldName]['mutator']; 
     808        } else if (isset($this->_customAssociationMutators[$fieldName])) { 
     809            return $this->_customAssociationMutators[$fieldName]; 
     810        } 
     811        return null; 
    888812    } 
    889813     
     
    1055979 
    1056980    /** 
    1057      * getBehaviors 
    1058      * returns all behaviors attached to the class. 
    1059      * 
    1060      * @return array     an array containing all templates 
    1061      * @todo Unify under 'Behaviors' 
    1062      */ 
    1063     /*public function getBehaviors() 
    1064     { 
    1065         return $this->_behaviors; 
    1066     }*/ 
    1067  
    1068     /** 
    1069981     * Gets the inheritance type used by the class. 
    1070982     * 
     
    11571069        } 
    11581070         
    1159         if ($type == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE || 
    1160                 $type == Doctrine::INHERITANCE_TYPE_JOINED) { 
     1071        if ($type == self::INHERITANCE_TYPE_SINGLE_TABLE || 
     1072                $type == self::INHERITANCE_TYPE_JOINED) { 
    11611073            $this->_checkRequiredDiscriminatorOptions($options); 
    11621074        } 
     
    12411153 
    12421154    /** 
    1243      * export 
    12441155     * exports this class to the database based on its mapping. 
    12451156     * 
     
    12481159     * @return boolean                          Whether or not the export operation was successful 
    12491160     *                                          false if table already existed in the database. 
     1161     * @todo Reimpl. & Placement. 
    12501162     */ 
    12511163    public function export() 
    12521164    { 
    1253         $this->_em->export->exportTable($this); 
    1254     } 
    1255  
    1256     /** 
    1257      * getExportableFormat 
     1165        //$this->_em->export->exportTable($this); 
     1166    } 
     1167 
     1168    /** 
    12581169     * Returns an array with all the information needed to create the main database table 
    12591170     * for the class. 
    12601171     * 
    12611172     * @return array 
     1173     * @todo Reimpl. & placement. 
    12621174     */ 
    12631175    public function getExportableFormat($parseForeignKeys = true) 
     
    12691181        // If the class is part of a Single Table Inheritance hierarchy, collect the fields 
    12701182        // of all classes in the hierarchy. 
    1271         if ($this->_inheritanceType == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { 
     1183        if ($this->_inheritanceType == self::INHERITANCE_TYPE_SINGLE_TABLE) { 
    12721184            $parents = $this->getParentClasses(); 
    12731185            if ($parents) { 
     
    12811193                $allColumns = array_merge($allColumns, $subClassMetadata->getColumns()); 
    12821194            } 
    1283         } else if ($this->_inheritanceType == Doctrine::INHERITANCE_TYPE_JOINED) { 
     1195        } else if ($this->_inheritanceType == self::INHERITANCE_TYPE_JOINED) { 
    12841196            // Remove inherited, non-pk fields. They're not in the table of this class 
    12851197            foreach ($allColumns as $name => $definition) {