Changeset 4523 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
06/15/08 16:56:28 (7 months ago)
Author:
romanb
Message:

Added getters to AST. Removed Production::call. Added visitor support to AST. (guilherme: dont shoot me yet :-). visitor support doesnt hurt even if we do not use it for SQL generation). Lots of other things.

Location:
trunk/lib/Doctrine
Files:
80 modified

Legend:

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

    r4456 r4523  
    3030 * @since       1.0 
    3131 * @version     $Revision$ 
     32 * @todo Can this be removed? 
    3233 */ 
    3334class Doctrine_Cache extends Doctrine_EventListener implements Countable, IteratorAggregate 
  • trunk/lib/Doctrine/ClassMetadata.php

    r4456 r4523  
    6161     * @var Doctrine_Connection 
    6262     */ 
    63     protected $_conn; 
     63    protected $_em; 
    6464 
    6565    /** 
     
    114114     */ 
    115115    protected $_generators = array(); 
    116  
    117     /** 
    118      * An array containing all filters attached to the class. 
    119      * 
    120      * @see Doctrine_Record_Filter 
    121      * @var array $_filters 
    122      */ 
    123     protected $_filters = array(); 
    124116 
    125117    /** 
     
    157149     */ 
    158150    protected $_fieldNames = array(); 
     151     
     152    /** 
     153     * Enter description here... 
     154     * 
     155     * @var unknown_type 
     156     */ 
     157    protected $_attributes = array('loadReferences' => true); 
    159158 
    160159    /** 
     
    166165     */ 
    167166    protected $_columnNames = array(); 
     167     
     168    /** 
     169     * Enter description here... 
     170     * 
     171     * @var unknown_type 
     172     */ 
     173    protected $_subclassFieldNames = array(); 
    168174 
    169175    /** 
     
    279285        $this->_entityName = $entityName; 
    280286        $this->_rootEntityName = $entityName; 
    281         $this->_conn = $em; 
     287        $this->_em = $em; 
    282288        $this->_parser = new Doctrine_Relation_Parser($this); 
    283289    } 
     
    288294    public function getConnection() 
    289295    { 
    290         return $this->_conn; 
     296        return $this->_em; 
    291297    } 
    292298     
    293299    public function getEntityManager() 
    294300    { 
    295         return $this->_conn; 
     301        return $this->_em; 
    296302    } 
    297303 
     
    349355    public function isIdentifierComposite() 
    350356    { 
    351         return ($this->_identifierType == Doctrine::IDENTIFIER_COMPOSITE); 
    352     } 
    353  
    354     /** 
    355      * Check if the field is unique 
     357        return $this->_identifierType == Doctrine::IDENTIFIER_COMPOSITE; 
     358    } 
     359 
     360    /** 
     361     * Check if the field is unique. 
    356362     * 
    357363     * @param string $fieldName  The field name 
     
    370376 
    371377    /** 
    372      * Check if the field is not null 
     378     * Check if the field is not null. 
    373379     * 
    374380     * @param string $fieldName  The field name 
     
    392398     * 
    393399     * @return void 
     400     * @deprecated 
     401     * @todo Should be done through setTableOption(). 
    394402     */ 
    395403    public function addIndex($index, array $definition) 
     
    402410     * 
    403411     * @return array|boolean        array on success, FALSE on failure 
     412     * @todo Should be done through getTableOption(). 
     413     * @deprecated 
    404414     */ 
    405415    public function getIndex($index) 
     
    425435    public function setOption($name, $value) 
    426436    { 
    427         /*switch ($name) { 
    428          case 'tableName': 
    429          case 'index': 
    430          case 'sequenceName': 
    431          case 'type': 
    432          case 'charset': 
    433          case 'collation': 
    434          case 'collate': 
    435          return $this->setTableOption($name, $value); 
    436          case 'enumMap': 
    437          $this->_enumMap = $value; 
    438          return; 
    439          }*/ 
    440437        $this->_options[$name] = $value; 
    441438    } 
     
    469466        $this->_invokedMethods[$method] : false; 
    470467    } 
    471  
    472468    public function addBehaviorMethod($method, $behavior) 
    473469    { 
     
    541537    { 
    542538        return isset($this->_mappedColumns[$columnName]) ? 
    543         $this->_mappedColumns[$columnName] : false; 
     539                $this->_mappedColumns[$columnName] : false; 
    544540    } 
    545541 
     
    556552    { 
    557553        return isset($this->_fieldNames[$columnName]) ? 
    558         $this->_fieldNames[$columnName] : $columnName; 
    559     } 
    560      
    561     private $_subclassFieldNames = array(); 
     554                $this->_fieldNames[$columnName] : $columnName; 
     555    } 
    562556     
    563557    /** 
     
    573567         
    574568        $classMetadata = $this; 
    575         $conn = $this->_conn; 
     569        $conn = $this->_em; 
    576570         
    577571        foreach ($classMetadata->getSubclasses() as $subClass) { 
     
    883877 
    884878        $columnName = $this->getColumnName($fieldName); 
    885         if ( ! $this->_conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM) && 
     879        if ( ! $this->_em->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM) && 
    886880        isset($this->_mappedColumns[$columnName]['values'][$index])) { 
    887881            $enumValue = $this->_mappedColumns[$columnName]['values'][$index]; 
     
    905899        $values = $this->getEnumValues($fieldName); 
    906900        $index = array_search($value, $values); 
    907         if ($index === false || ! $this->_conn->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) { 
     901        if ($index === false || ! $this->_em->getAttribute(Doctrine::ATTR_USE_NATIVE_ENUM)) { 
    908902            return $index; 
    909903        } 
     
    12891283    { 
    12901284        if ($parentClassNames = $this->getParentClasses()) { 
    1291             if ($this->_conn->getClassMetadata($parentClassNames[0])->getInheritanceType() != $type) { 
     1285            if ($this->_em->getClassMetadata($parentClassNames[0])->getInheritanceType() != $type) { 
    12921286                throw new Doctrine_ClassMetadata_Exception("All classes in an inheritance hierarchy" 
    12931287                . " must share the same inheritance mapping type. Mixing is not allowed."); 
     
    13891383    public function export() 
    13901384    { 
    1391         $this->_conn->export->exportTable($this); 
     1385        $this->_em->export->exportTable($this); 
    13921386    } 
    13931387 
     
    14101404            $parents = $this->getParentClasses(); 
    14111405            if ($parents) { 
    1412                 $rootClass = $this->_conn->getClassMetadata(array_pop($parents)); 
     1406                $rootClass = $this->_em->getClassMetadata(array_pop($parents)); 
    14131407            } else { 
    14141408                $rootClass = $this; 
     
    14161410            $subClasses = $rootClass->getSubclasses(); 
    14171411            foreach ($subClasses as $subClass) { 
    1418                 $subClassMetadata = $this->_conn->getClassMetadata($subClass); 
     1412                $subClassMetadata = $this->_em->getClassMetadata($subClass); 
    14191413                $allColumns = array_merge($allColumns, $subClassMetadata->getColumns()); 
    14201414            } 
     
    14551449                case 'boolean': 
    14561450                    if (isset($definition['default'])) { 
    1457                         $definition['default'] = $this->_conn->convertBooleans($definition['default']); 
     1451                        $definition['default'] = $this->_em->convertBooleans($definition['default']); 
    14581452                    } 
    14591453                    break; 
     
    16101604 
    16111605    /** 
    1612      * unshiftFilter 
    1613      * 
    1614      * @param  object Doctrine_Record_Filter $filter 
    1615      * @return object $this 
    1616      * @todo Remove filters, if possible. 
    1617      */ 
    1618     public function unshiftFilter(Doctrine_Record_Filter $filter) 
    1619     { 
    1620         $filter->setTable($this); 
    1621         array_unshift($this->_filters, $filter); 
    1622  
    1623         return $this; 
    1624     } 
    1625  
    1626     /** 
    16271606     * getTree 
    16281607     * 
     
    16591638 
    16601639    /** 
    1661      * getFilters 
    1662      * 
    1663      * @return array $filters 
    1664      * @todo Remove filters, if possible. 
    1665      */ 
    1666     public function getFilters() 
    1667     { 
    1668         return $this->_filters; 
    1669     } 
    1670  
    1671     /** 
    16721640     * Checks whether a persistent field is inherited from a superclass. 
    16731641     * 
     
    17271695    public function setTableName($tableName) 
    17281696    { 
    1729         $this->setTableOption('tableName', $this->_conn->getConnection() 
    1730                 ->formatter->getTableName($tableName)); 
     1697        $this->setTableOption('tableName', $this->_em->getConnection() 
     1698                ->getFormatter()->getTableName($tableName)); 
    17311699    } 
    17321700 
     
    17411709    { 
    17421710        //$contents = get_object_vars($this); 
    1743         /* @TODO How to handle $this->_conn and $this->_parser ? */ 
     1711        /* @TODO How to handle $this->_em and $this->_parser ? */ 
    17441712        //return serialize($contents); 
    17451713        return ""; 
     
    18351803     * @return Doctrine_Entity      this object 
    18361804     * @todo Should be done through $_tableOptions 
     1805     * @deprecated 
    18371806     */ 
    18381807    public function check($constraint, $name = null) 
     
    18481817        return $this; 
    18491818    } 
    1850  
    18511819    protected function _addCheckConstraint($definition, $name) 
    18521820    { 
     
    18571825        } 
    18581826    } 
    1859  
    1860     /** 
    1861      * Registers a custom mapper for the entity class. 
    1862      * 
    1863      * @param string $mapperClassName  The class name of the custom mapper. 
    1864      * @deprecated 
    1865      */ 
    1866     public function setCustomMapperClass($mapperClassName) 
    1867     { 
    1868         if ( ! is_subclass_of($mapperClassName, 'Doctrine_Mapper')) { 
    1869             throw new Doctrine_ClassMetadata_Exception("The custom mapper must be a subclass" 
    1870             . " of Doctrine_Mapper."); 
    1871         } 
    1872         $this->_customRepositoryClassName = $mapperClassName; 
    1873     } 
    18741827     
    18751828    /** 
     
    18871840        $this->_customRepositoryClassName = $repositoryClassName; 
    18881841    } 
    1889  
    1890     /** 
    1891      * Gets the name of the custom mapper class used for the entity class. 
    1892      * 
    1893      * @return string|null  The name of the custom mapper class or NULL if the entity 
    1894      *                      class does not have a custom mapper class. 
    1895      * @deprecated 
    1896      */ 
    1897     public function getCustomMapperClass() 
    1898     { 
    1899         return $this->_customRepositoryClassName; 
    1900     } 
    19011842     
     1843    /** 
     1844     * Gets the name of the custom repository class used for the entity class. 
     1845     * 
     1846     * @return string|null  The name of the custom repository class or NULL if the entity 
     1847     *                      class does not have a custom repository class. 
     1848     */ 
    19021849    public function getCustomRepositoryClass() 
    19031850    { 
     
    19101857    public function setEntityType($type) 
    19111858    { 
    1912         //Doctrine::CLASSTYPE_ENTITY 
    1913         //Doctrine::CLASSTYPE_MAPPED_SUPERCLASS 
    1914         //Doctrine::CLASSTYPE_TRANSIENT 
    1915     } 
    1916  
    1917     /** 
    1918      * 
     1859        //Entity::TYPE_ENTITY 
     1860        //Entity::TYPE_MAPPED_SUPERCLASS 
     1861        //Entity::TYPE_TRANSIENT 
     1862    } 
     1863 
     1864    /** 
     1865     * Binds the entity instance of this class to a specific EntityManager. 
     1866     *  
    19191867     * @todo Implementation. Replaces the bindComponent() methods on the old Doctrine_Manager. 
    19201868     *       Binding an Entity to a specific EntityManager in 2.0 is the same as binding 
     
    19751923    public function hasAttribute($name) 
    19761924    { 
    1977         return false; 
     1925        return isset($this->_attributes[$name]); 
    19781926    } 
    19791927     
    19801928    public function getAttribute($name) 
    19811929    { 
    1982         return null; 
     1930        if ($this->hasAttribute($name)) { 
     1931            return $this->_attributes[$name]; 
     1932        } 
    19831933    } 
    19841934     
    19851935    public function setAttribute($name, $value) 
    19861936    { 
    1987         ; 
     1937        if ($this->hasAttribute($name)) { 
     1938            $this->_attributes[$name] = $value; 
     1939        } 
    19881940    } 
    19891941 
  • trunk/lib/Doctrine/Collection.php

    r4470 r4523  
    9898    /** 
    9999     * Constructor. 
    100      * Creates a new collection that will hold instances of the type that is 
    101      * specified through the mapper. That means if the mapper is a mapper for 
    102      * the entity "User", then the resulting collection will be a collection of 
    103      * user objects. 
    104100     * 
    105101     * @param Doctrine_Mapper|string $mapper   The mapper used by the collection. 
     
    121117 
    122118        if ($keyField === null) { 
    123                 $keyField = $mapper->getClassMetadata()->getAttribute(Doctrine::ATTR_COLL_KEY); 
     119                //$keyField = $mapper->getClassMetadata()->getAttribute(Doctrine::ATTR_COLL_KEY); 
    124120        } 
    125121 
     
    367363     * @param mixed $key                    the key of the element 
    368364     * @return boolean 
     365     * @todo Rename to containsKey(). 
    369366     */ 
    370367    public function contains($key) 
     
    433430     * 
    434431     * @return array   An array containing all primary keys. 
     432     * @todo Rename. 
    435433     */ 
    436434    public function getPrimaryKeys() 
     
    627625                foreach ($coll as $k => $related) { 
    628626                    if ($related[$foreign] == $record[$local]) { 
    629                         $this->data[$key]->setRelated($name, $related); 
     627                        $this->data[$key]->_setRelated($name, $related); 
    630628                    } 
    631629                } 
     
    645643                } 
    646644 
    647                 $this->data[$key]->setRelated($name, $sub); 
     645                $this->data[$key]->_setRelated($name, $sub); 
    648646            } 
    649647        } else if ($rel instanceof Doctrine_Relation_Association) { 
     
    664662                    } 
    665663                } 
    666                 $this->data[$key]->setRelated($name, $sub); 
     664                $this->data[$key]->_setRelated($name, $sub); 
    667665 
    668666            } 
     
    800798     * @param string $deep  
    801799     * @return void 
     800     * @todo Move elsewhere. 
    802801     */ 
    803802    public function exportTo($type, $deep = false) 
     
    818817     * @param string $data  
    819818     * @return void 
     819     * @todo Move elsewhere. 
    820820     */ 
    821821    public function importFrom($type, $data) 
     
    869869     * @return Doctrine_Collection 
    870870     */ 
    871     public function save(Doctrine_Connection $conn = null) 
    872     { 
    873         if ($conn == null) { 
    874             $conn = $this->_mapper->getConnection(); 
    875         } 
     871    public function save() 
     872    { 
     873        $conn = $this->_mapper->getConnection(); 
    876874         
    877875        try { 
     
    894892 
    895893    /** 
    896      * delete 
    897      * single shot delete 
    898      * deletes all records from this collection 
    899      * and uses only one database query to perform this operation 
    900      * 
    901      * @return Doctrine_Collection 
    902      */ 
    903     public function delete(Doctrine_Connection $conn = null) 
    904     { 
    905         if ($conn == null) { 
    906             $conn = $this->_mapper->getConnection(); 
    907         } 
     894     * Deletes all records from the collection. 
     895     * 
     896     * @return void 
     897     */ 
     898    public function delete($clearColl = false) 
     899    {   
     900        $conn = $this->_mapper->getConnection(); 
    908901 
    909902        try { 
     
    920913            throw $e; 
    921914        }