Trac

Changeset 4776 for trunk/lib

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

continued refactorings.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 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) { 
     
    12941206                } 
    12951207            } 
    1296         } else if ($this->_inheritanceType == Doctrine::INHERITANCE_TYPE_TABLE_PER_CLASS) { 
     1208        } else if ($this->_inheritanceType == self::INHERITANCE_TYPE_TABLE_PER_CLASS) { 
    12971209            // If this is a subclass, just remove existing autoincrement options on the pk 
    12981210            if ($this->getParentClasses()) { 
     
    14241336     
    14251337    /** 
    1426      * Checks whether the given name identifies an entity type. 
     1338     * Checks whether the given type identifies an entity type. 
    14271339     * 
    14281340     * @param string $type 
     
    14371349     
    14381350    /** 
    1439      * Checks whether the given name identifies an inheritance type. 
     1351     * Checks whether the given type identifies an inheritance type. 
    14401352     * 
    14411353     * @param string $type 
     
    14511363     
    14521364    /** 
    1453      * Checks whether the given name identifies an id generator type. 
     1365     * Checks whether the given type identifies an id generator type. 
    14541366     * 
    14551367     * @param string $type 
     
    14641376                $type == self::GENERATOR_TYPE_NONE; 
    14651377    } 
    1466  
     1378     
     1379    /** 
     1380     * Makes some automatic additions to the association mapping to make the life 
     1381     * easier for the user. 
     1382     * 
     1383     * @param array $mapping 
     1384     * @return unknown 
     1385     * @todo Pass param by ref? 
     1386     */ 
     1387    private function _completeAssociationMapping(array $mapping) 
     1388    { 
     1389        $mapping['sourceEntity'] = $this->_entityName; 
     1390        return $mapping; 
     1391    } 
     1392     
     1393    /** 
     1394     * Registers any custom accessors/mutators in the given association mapping in 
     1395     * an internal cache for fast lookup. 
     1396     * 
     1397     * @param Doctrine_Association $assoc 
     1398     * @param unknown_type $fieldName 
     1399     */ 
     1400    private function _registerCustomAssociationAccessors(Doctrine_Association $assoc, $fieldName) 
     1401    { 
     1402        if ($acc = $assoc->getCustomAccessor()) { 
     1403            $this->_customAssociationAccessors[$fieldName] = $acc; 
     1404        } 
     1405        if ($mut = $assoc->getCustomMutator()) { 
     1406            $this->_customAssociationMutators[$fieldName] = $mut; 
     1407        } 
     1408    } 
     1409     
    14671410    /** 
    14681411     * Adds a one-to-one association mapping. 
     
    14721415    public function mapOneToOne(array $mapping) 
    14731416    { 
     1417        $mapping = $this->_completeAssociationMapping($mapping); 
    14741418        $oneToOneMapping = new Doctrine_Association_OneToOne($mapping); 
    1475         if (isset($this->_associationMappings[$oneToOneMapping->getSourceFieldName()])) { 
     1419        $sourceFieldName = $oneToOneMapping->getSourceFieldName(); 
     1420        if (isset($this->_associationMappings[$sourceFieldName])) { 
    14761421            throw Doctrine_MappingException::duplicateFieldMapping(); 
    14771422        } 
    1478         $this->_associationMappings[$oneToOneMapping->getSourceFieldName()] = $oneToOneMapping; 
     1423        $this->_associationMappings[$sourceFieldName] = $oneToOneMapping; 
     1424        $this->_registerCustomAssociationAccessors($oneToOneMapping, $sourceFieldName); 
    14791425    } 
    14801426 
     
    14841430    public function mapOneToMany(array $mapping) 
    14851431    { 
    1486  
     1432        $mapping = $this->_completeAssociationMapping($mapping); 
     1433        $oneToManyMapping = new Doctrine_Association_OneToMany($mapping); 
     1434        $sourceFieldName = $oneToManyMapping->getSourceFieldName(); 
     1435        if (isset($this->_associationMappings[$sourceFieldName])) { 
     1436            throw Doctrine_MappingException::duplicateFieldMapping(); 
     1437        } 
     1438        $this->_associationMappings[$sourceFieldName] = $oneToManyMapping; 
     1439        $this->_registerCustomAssociationAccessors($oneToManyMapping, $sourceFieldName); 
    14871440    } 
    14881441 
     
    15021455 
    15031456    } 
    1504  
    1505     /** 
    1506      * actAs 
    1507      * loads the given plugin 
    1508      * 
    1509      * @param mixed $tpl 
    1510      * @param array $options 
    1511      * @todo Unify under 'Behaviors'. 
    1512      */ 
    1513     /*public function actAs($tpl, array $options = array()) 
    1514     { 
    1515         if ( ! is_object($tpl)) { 
    1516             if (class_exists($tpl, true)) { 
    1517                 $tpl = new $tpl($options); 
    1518             } else { 
    1519                 $className = 'Doctrine_Template_' . $tpl; 
    1520                 if ( ! class_exists($className, true)) { 
    1521                     throw new Doctrine_Record_Exception("Couldn't load plugin."); 
    1522                 } 
    1523                 $tpl = new $className($options); 
    1524             } 
    1525         } 
    1526  
    1527         if ( ! ($tpl instanceof Doctrine_Template)) { 
    1528             throw new Doctrine_Record_Exception('Loaded plugin class is not an instance of Doctrine_Template.'); 
    1529         } 
    1530  
    1531         $className = get_class($tpl); 
    1532  
    1533         $this->addBehavior($className, $tpl); 
    1534  
    1535         $tpl->setTable($this); 
    1536         $tpl->setUp(); 
    1537         $tpl->setTableDefinition(); 
    1538  
    1539         return $this; 
    1540     }*/ 
    1541  
    1542     /** 
    1543      * check 
    1544      * adds a check constraint 
    1545      * 
    1546      * @param mixed $constraint     either a SQL constraint portion or an array of CHECK constraints 
    1547      * @param string $name          optional constraint name 
    1548      * @return Doctrine_Entity      this object 
    1549      * @todo Should be done through $_tableOptions 
    1550      * @deprecated 
    1551      */ 
    1552     /*public function check($constraint, $name = null) 
    1553     { 
    1554         if (is_array($constraint)) { 
    1555             foreach ($constraint as $name => $def) { 
    1556                 $this->_addCheckConstraint($def, $name); 
    1557             } 
    1558         } else { 
    1559             $this->_addCheckConstraint($constraint, $name); 
    1560         } 
    1561  
    1562         return $this; 
    1563     } 
    1564     protected function _addCheckConstraint($definition, $name) 
    1565     { 
    1566         if (is_string($name)) { 
    1567             $this->_tableOptions['checks'][$name] = $definition; 
    1568         } else { 
    1569             $this->_tableOptions['checks'][] = $definition; 
    1570         } 
    1571     }*/ 
    15721457     
    15731458    /** 
     
    15751460     * 
    15761461     * @param string $mapperClassName  The class name of the custom mapper. 
    1577      * @deprecated 
    15781462     */ 
    15791463    public function setCustomRepositoryClass($repositoryClassName) 
     
    16081492 
    16091493    /** 
    1610      * Binds the entity instance of this class to a specific EntityManager. 
     1494     * Binds the entity instances of this class to a specific EntityManager. 
    16111495     *  
    16121496     * @todo Implementation. Replaces the bindComponent() methods on the old Doctrine_Manager. 
     
    16981582        }  
    16991583    } 
    1700  
    1701     /** 
    1702      * @todo Implementation. Immutable entities can not be updated or deleted once 
    1703      *       they are created. This means the entity can only be modified as long as it's 
    1704      *       in transient state (TCLEAN, TDIRTY). 
    1705      */ 
    1706     public function isImmutable() 
    1707     { 
    1708         return false; 
    1709     } 
    1710  
    1711     public function isDiscriminatorColumn($columnName) 
    1712     { 
    1713         return $columnName === $this->_inheritanceOptions['discriminatorColumn']; 
    1714     } 
    1715  
    1716     /** 
    1717      * hasOne 
    1718      * binds One-to-One aggregate relation 
    1719      * 
    1720      * @param string $componentName     the name of the related component 
    1721      * @param string $options           relation options 
    1722      * @see Doctrine_Relation::_$definition 
    1723      * @return Doctrine_Entity          this object 
    1724      */ 
    1725     public function hasOne() 
    1726     { 
    1727         $this->bind(func_get_args(), Doctrine_Relation::ONE_AGGREGATE); 
    1728  
    1729         return $this; 
    1730     } 
    1731  
    1732     /** 
    1733      * hasMany 
    1734      * binds One-to-Many / Many-to-Many aggregate relation 
    1735      * 
    1736      * @param string $componentName     the name of the related component 
    1737      * @param string $options           relation options 
    1738      * @see Doctrine_Relation::_$definition 
    1739      * @return Doctrine_Entity          this object 
    1740      */ 
    1741     public function hasMany() 
    1742     { 
    1743         $this->bind(func_get_args(), Doctrine_Relation::MANY_AGGREGATE); 
    1744  
    1745         return $this; 
    1746     } 
    1747  
    1748     public function hasAttribute($name) 
    1749     { 
    1750         return isset($this->_attributes[$name]); 
    1751     } 
    1752      
    1753     public function getAttribute($name) 
    1754     { 
    1755         if ($this->hasAttribute($name)) { 
    1756             return $this->_attributes[$name]; 
    1757         } 
    1758     } 
    1759      
    1760     public function setAttribute($name, $value) 
    1761     { 
    1762         if ($this->hasAttribute($name)) { 
    1763             $this->_attributes[$name] = $value; 
    1764         } 
    1765     } 
    1766      
    1767     /* The following stuff needs to be touched for the association mapping rewrite */ 
    1768      
    1769     public function bindRelation($args, $type) 
    1770     { 
    1771         return $this->bind($args, $type); 
    1772     } 
    1773  
    1774     /** 
    1775      * @todo Relation mapping rewrite. 
    1776      */ 
    1777     public function bind($args, $type) 
    1778     { 
    1779         $options = array(); 
    1780         $options['type'] = $type; 
    1781  
    1782         if ( ! isset($args[1])) { 
    1783             $args[1] = array(); 
    1784         } 
    1785         if ( ! is_array($args[1])) { 
    1786             try { 
    1787                 throw new Exception(); 
    1788             } catch (Exception $e) { 
    1789                 echo $e->getTraceAsString(); 
    1790             } 
    1791         } 
    1792         $options = array_merge($args[1], $options); 
    1793         $this->_parser->bind($args[0], $options); 
    1794     } 
    1795  
    1796     /** 
    1797      * hasRelation 
    1798      * 
    1799      * @param string $alias      the relation to check if exists 
    1800      * @return boolean           true if the relation exists otherwise false 
    1801      */ 
    1802     public function hasRelation($alias) 
    1803     { 
    1804         return $this->_parser->hasRelation($alias); 
    1805     } 
    1806  
    1807     /** 
    1808      * getRelation 
    1809      * 
    1810      * @param string $alias      relation alias 
    1811      */ 
    1812     public function getRelation($alias, $recursive = true) 
    1813     { 
    1814         return $this->_parser->getRelation($alias, $recursive); 
    1815     } 
    1816  
    1817     public function getRelationParser() 
    1818     { 
    1819         return $this->_parser; 
    1820     } 
    1821  
    1822     /** 
    1823      * getRelations 
    1824      * returns an array containing all relation objects 
    1825      * 
    1826      * @return array        an array of Doctrine_Relation objects 
    1827      */ 
    1828     public function getRelations() 
    1829     { 
    1830         return $this->_parser->getRelations(); 
    1831     } 
    1832      
    1833     /** 
    1834      * @todo Set by the factory if type is AUTO. Not pretty. Find sth. better. 
    1835      */ 
    1836     public function setIdGeneratorType($type) 
    1837     { 
    1838         $this->_generatorType = $type; 
    1839     } 
    1840      
     1584     
     1585    /** 
     1586     * Completes the identifier mapping of the class. 
     1587     * NOTE: Should only be called by the ClassMetadataFactory! 
     1588     */ 
    18411589    public function completeIdentifierMapping() 
    18421590    { 
     
    18541602 
    18551603    /** 
     1604     * @todo Implementation. Immutable entities can not be updated or deleted once 
     1605     *       they are created. This means the entity can only be modified as long as it's 
     1606     *       in transient state (TCLEAN, TDIRTY). 
     1607     */ 
     1608    public function isImmutable() 
     1609    { 
     1610        return false; 
     1611    } 
     1612 
     1613    public function isDiscriminatorColumn($columnName) 
     1614    { 
     1615        return $columnName === $this->_inheritanceOptions['discriminatorColumn']; 
     1616    } 
     1617 
     1618    public function hasAttribute($name) 
     1619    { 
     1620        return isset($this->_attributes[$name]); 
     1621    } 
     1622     
     1623    public function getAttribute($name) 
     1624    { 
     1625        if ($this->hasAttribute($name)) { 
     1626            return $this->_attributes[$name]; 
     1627        } 
     1628    } 
     1629     
     16