Changeset 4789 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
08/22/08 10:05:14 (5 months ago)
Author:
romanb
Message:

refactorings. made basic one-one, one-many joins work.

Location:
trunk/lib/Doctrine
Files:
44 modified

Legend:

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

    r4776 r4789  
    160160        $this->_customMutator = isset($mapping['mutator']) ? $mapping['mutator'] : null; 
    161161        $this->_isOptional = isset($mapping['isOptional']) ? (bool)$mapping['isOptional'] : true; 
     162        $this->_cascades = isset($mapping['cascade']) ? (array)$mapping['cascade'] : array(); 
    162163 
    163164        return $mapping; 
  • trunk/lib/Doctrine/Association/OneToMany.php

    r4718 r4789  
    11<?php 
     2/* 
     3 *  $Id$ 
     4 * 
     5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
     6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
     7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
     8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
     9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
     10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
     11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
     12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
     13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
     14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
     15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     16 * 
     17 * This software consists of voluntary contributions made by many individuals 
     18 * and is licensed under the LGPL. For more information, see 
     19 * <http://www.phpdoctrine.org>. 
     20 */ 
    221 
    322#namespace Doctrine::ORM::Mappings; 
    423 
     24/** 
     25 * Represents a one-to-many mapping. 
     26 *  
     27 * NOTE: One-to-many mappings can currently not be uni-directional (one -> many). 
     28 * They must either be bidirectional (one <-> many) or unidirectional (many -> one). 
     29 * In other words, the many-side MUST be the owning side and the one-side MUST be 
     30 * the inverse side. 
     31 * 
     32 * @author Roman Borschel <roman@code-factory.org> 
     33 * @since 2.0 
     34 * @todo Rename to OneToManyMapping 
     35 */ 
    536class Doctrine_Association_OneToMany extends Doctrine_Association 
    637{ 
    738    /** The target foreign key columns that reference the sourceKeyColumns. */ 
    8     protected $_targetForeignKeyColumns; 
     39    /* NOTE: Currently not used because uni-directional one-many not supported atm.  */ 
     40    //protected $_targetForeignKeyColumns; 
    941 
    1042    /** The (typically primary) source key columns that are referenced by the targetForeignKeyColumns. */ 
    11     protected $_sourceKeyColumns; 
     43    /* NOTE: Currently not used because uni-directional one-many not supported atm.  */ 
     44    //protected $_sourceKeyColumns; 
    1245 
    1346    /** This maps the target foreign key columns to the corresponding (primary) source key columns. */ 
    14     protected $_targetForeignKeysToSourceKeys; 
     47    /* NOTE: Currently not used because uni-directional one-many not supported atm.  */ 
     48    //protected $_targetForeignKeysToSourceKeys; 
    1549     
    1650    /** This maps the (primary) source key columns to the corresponding target foreign key columns. */ 
    17     protected $_sourceKeysToTargetForeignKeys; 
     51    /* NOTE: Currently not used because uni-directional one-many not supported atm.  */ 
     52    //protected $_sourceKeysToTargetForeignKeys; 
    1853     
    1954    /** Whether to delete orphaned elements (removed from the collection) */ 
    2055    protected $_deleteOrphans = false; 
    2156     
     57    /** 
     58     * Constructor. 
     59     * Creates a new OneToManyMapping. 
     60     * 
     61     * @param array $mapping  The mapping info. 
     62     */ 
     63    public function __construct(array $mapping) 
     64    { 
     65        parent::__construct($mapping); 
     66        // one side in one-many can currently never be owning side, we may support that later 
     67        $this->_isOwningSide = false; 
     68    } 
     69     
     70    /** 
     71     * Whether orphaned elements (removed from the collection) should be deleted. 
     72     * 
     73     * @return boolean TRUE if orphaned elements should be deleted, FALSE otherwise. 
     74     */ 
    2275    public function shouldDeleteOrphans() 
    2376    { 
    2477        return $this->_deleteOrphans; 
    2578    } 
     79     
     80    /** 
     81     * Whether the association is one-to-many. 
     82     * 
     83     * @return boolean TRUE if the association is one-to-many, FALSE otherwise. 
     84     * @override 
     85     */ 
     86    public function isOneToMany() 
     87    { 
     88        return true; 
     89    } 
     90     
     91     
    2692} 
    2793 
  • trunk/lib/Doctrine/Cache/Apc.php

    r4723 r4789  
    8484    public function save($id, $data, $lifeTime = false) 
    8585    { 
    86         $lifeTime = $this->getLifeTime($lifeTime); 
    87  
    88         return (bool) apc_store($id, array($data, time()), $lifeTime); 
     86        return (bool) apc_store($id, $data, $lifeTime); 
    8987    } 
    9088 
  • trunk/lib/Doctrine/Cache/Memcache.php

    r3931 r4789  
    1919 * <http://www.phpdoctrine.org>. 
    2020 */ 
    21 Doctrine::autoload('Doctrine_Cache_Driver'); 
     21 
    2222/** 
    2323 * Doctrine_Cache_Memcache 
     
    8181    public function fetch($id, $testCacheValidity = true)  
    8282    { 
    83         $tmp = $this->_memcache->get($id); 
    84  
    85         if (is_array($tmp)) { 
    86             return $tmp[0]; 
    87         } else if (is_string($tmp)) { 
    88             return $tmp; 
    89         } 
    90  
    91         return false; 
     83        return $this->_memcache->get($id); 
    9284    } 
    9385 
  • trunk/lib/Doctrine/Cache/Xcache.php

    r3931 r4789  
    1919 * <http://www.phpdoctrine.org>. 
    2020 */ 
    21 Doctrine::autoload('Doctrine_Cache_Driver'); 
     21 
    2222/** 
    2323 * Doctrine_Cache_Xcache 
  • trunk/lib/Doctrine/ClassMetadata.php

    r4776 r4789  
    2626/** 
    2727 * A <tt>ClassMetadata</tt> instance holds all the information (metadata) of an entity and 
    28  * it's associations and how they're mapped to the relational database. 
     28 * it's associations and how they're mapped to a relational database. 
    2929 * It is the backbone of Doctrine's metadata mapping. 
    3030 * 
    3131 * @author Roman Borschel <roman@code-factory.org> 
    3232 * @since 2.0 
    33  * @todo Rename to ClassDescriptor? 
     33 * @todo Rename to ClassDescriptor. 
    3434 */ 
    3535class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable 
    3636{ 
    3737    /* The inheritance mapping types */ 
     38    /** 
     39     * NONE means the class does not participate in an inheritance hierarchy 
     40     * and therefore does not need an inheritance mapping type. 
     41     */ 
    3842    const INHERITANCE_TYPE_NONE = 'none'; 
     43    /** 
     44     * JOINED means the class will be persisted according to the rules of 
     45     * <tt>Class Table Inheritance</tt>. 
     46     */ 
    3947    const INHERITANCE_TYPE_JOINED = 'joined'; 
     48    /** 
     49     * SINGLE_TABLE means the class will be persisted according to the rules of 
     50     * <tt>Single Table Inheritance</tt>. 
     51     */ 
    4052    const INHERITANCE_TYPE_SINGLE_TABLE = 'singleTable'; 
     53    /** 
     54     * TABLE_PER_CLASS means the class will be persisted according to the rules 
     55     * of <tt>Concrete Table Inheritance</tt>. 
     56     */ 
    4157    const INHERITANCE_TYPE_TABLE_PER_CLASS = 'tablePerClass'; 
    4258     
    43     /* The Id generator types. TODO: belongs more in a DBAL class */ 
     59    /* The Id generator types. */ 
     60    /** 
     61     * AUTO means the generator type will depend on what the used platform prefers. 
     62     * Offers full portability. 
     63     */ 
    4464    const GENERATOR_TYPE_AUTO = 'auto'; 
     65    /** 
     66     * SEQUENCE means a separate sequence object will be used. Platforms that do 
     67     * not have native sequence support may emulate it. Full portability is currently 
     68     * not guaranteed. 
     69     */ 
    4570    const GENERATOR_TYPE_SEQUENCE = 'sequence'; 
     71    /** 
     72     * TABLE means a separate table is used for id generation. 
     73     * Offers full portability. 
     74     */ 
    4675    const GENERATOR_TYPE_TABLE = 'table'; 
     76    /** 
     77     * IDENTITY means an identity column is used for id generation. The database 
     78     * will fill in the id column on insertion. Platforms that do not support 
     79     * native identity columns may emulate them. Full portability is currently 
     80     * not guaranteed. 
     81     */ 
    4782    const GENERATOR_TYPE_IDENTITY = 'identity'; 
     83    /** 
     84     * NONE means the class does not have a generated id. That means the class 
     85     * must have a natural id. 
     86     */ 
    4887    const GENERATOR_TYPE_NONE = 'none'; 
    4988     
     
    5493    const ENTITY_TYPE_REGULAR = 'regular'; 
    5594    /** 
    56      * A transient entity is ignored by Doctrine. 
     95     * A transient entity is ignored by Doctrine (so ... it's not an entity really). 
    5796     */ 
    5897    const ENTITY_TYPE_TRANSIENT = 'transient'; 
     
    216255     */ 
    217256    protected $_lcColumnToFieldNames = array(); 
    218  
    219     /** 
    220      * Relation parser object. Manages the relations for the class. 
    221      * 
    222      * @var Doctrine_Relation_Parser $_parser 
    223      * @todo Remove. 
    224      */ 
    225     protected $_parser; 
    226257 
    227258    /** 
     
    316347        $this->_rootEntityName = $entityName; 
    317348        $this->_em = $em; 
    318          
    319         $this->_parser = new Doctrine_Relation_Parser($this); 
    320349    } 
    321350     
     
    504533    } 
    505534     
     535    public function addFieldMapping($fieldName, array $mapping) 
     536    { 
     537        $this->_fieldMappings[$fieldName] = $mapping; 
     538    } 
     539     
    506540    /** 
    507541     * Gets the mapping of an association. 
     
    518552         
    519553        return $this->_associationMappings[$fieldName]; 
     554    } 
     555     
     556    public function addAssociationMapping($fieldName, Doctrine_Association $assoc) 
     557    { 
     558        $this->_associationMappings[$fieldName] = $assoc; 
    520559    } 
    521560     
     
    880919    } 
    881920     
     921    public function isInheritanceTypeJoined() 
     922    { 
     923        return $this->_inheritanceType == self::INHERITANCE_TYPE_JOINED; 
     924    } 
     925     
     926    public function isInheritanceTypeSingleTable() 
     927    { 
     928        return $this->_inheritanceType == self::INHERITANCE_TYPE_SINGLE_TABLE; 
     929    } 
     930     
     931    public function isInheritanceTypeTablePerClass() 
     932    { 
     933        return $this->_inheritanceType == self::INHERITANCE_TYPE_TABLE_PER_CLASS; 
     934    } 
     935     
    882936    /** 
    883937     * Checks whether the class uses an identity column for the Id generation. 
     
    10081062    { 
    10091063        return $this->_subClasses; 
     1064    } 
     1065     
     1066    /** 
     1067     * Gets the name of the class in the entity hierarchy that owns the field with 
     1068     * the given name. The owning class is the one that defines the field. 
     1069     * 
     1070     * @param string $fieldName 
     1071     * @return string 
     1072     * @todo Consider using 'inherited' => 'ClassName' to make the lookup simpler. 
     1073     */ 
     1074    public function getOwningClass($fieldName) 
     1075    { 
     1076        if ($this->_inheritanceType == self::INHERITANCE_TYPE_NONE) { 
     1077            return $this; 
     1078        } else { 
     1079            foreach ($this->_parentClasses as $parentClass) { 
     1080                if ( ! $this->_em->getClassMetadata($parentClass)->isInheritedField($fieldName)) { 
     1081                    return $parentClass; 
     1082                } 
     1083            } 
     1084        } 
     1085         
     1086        throw new Doctrine_ClassMetadata_Exception("Unable to find defining class of field '$fieldName'."); 
    10101087    } 
    10111088 
     
    14091486     
    14101487    /** 
    1411      * Adds a one-to-one association mapping. 
    1412      *  
    1413      * @todo Implementation. 
     1488     * Adds a one-to-one mapping. 
     1489     *  
     1490     * @param array $mapping The mapping. 
    14141491     */ 
    14151492    public function mapOneToOne(array $mapping) 
     
    14261503 
    14271504    /** 
    1428      * @todo Implementation. 
     1505     * Adds a one-to-many mapping. 
     1506     *  
     1507     * @param array $mapping The mapping. 
    14291508     */ 
    14301509    public function mapOneToMany(array $mapping) 
     
    14411520 
    14421521    /** 
    1443      * @todo Implementation. 
     1522     * Adds a many-to-one mapping. 
     1523     *  
     1524     * @param array $mapping The mapping. 
    14441525     */ 
    14451526    public function mapManyToOne(array $mapping) 
    14461527    { 
    1447          
     1528        // A many-to-one mapping is simply a one-one backreference 
     1529        $this->mapOneToOne($mapping); 
    14481530    } 
    14491531 
     
    15861668     * Completes the identifier mapping of the class. 
    15871669     * NOTE: Should only be called by the ClassMetadataFactory! 
     1670     *  
     1671     * @return void 
    15881672     */ 
    15891673    public function completeIdentifierMapping() 
     
    16041688     * @todo Implementation. Immutable entities can not be updated or deleted once 
    16051689     *       they are created. This means the entity can only be modified as long as it's 
    1606      *       in transient state (TCLEAN, TDIRTY). 
     1690     *       new (STATE_NEW). 
    16071691     */ 
    16081692    public function isImmutable() 
     
    16351719    } 
    16361720     
    1637     /* The following stuff needs to be touched for the association mapping rewrite */ 
    1638      
    1639     /** 
    1640      * hasOne 
    1641      * binds One-to-One aggregate relation 
    1642      * 
    1643      * @param string $componentName     the name of the related component 
    1644      * @param string $options           relation options 
    1645      * @see Doctrine_Relation::_$definition 
    1646      * @return Doctrine_Entity          this object 
    1647      * @deprecated 
    1648      */ 
    1649     public function hasOne() 
    1650     { 
    1651         $this->bind(func_get_args(), Doctrine_Relation::ONE_AGGREGATE); 
    1652  
    1653         return $this; 
    1654     } 
    1655  
    1656     /** 
    1657      * hasMany 
    1658      * binds One-to-Many / Many-to-Many aggregate relation 
    1659      * 
    1660      * @param string $componentName     the name of the related component 
    1661      * @param string $options           relation options 
    1662      * @see Doctrine_Relation::_$definition 
    1663      * @return Doctrine_Entity          this object 
    1664      * @deprecated 
    1665      */ 
    1666     public function hasMany() 
    1667     { 
    1668         $this->bind(func_get_args(), Doctrine_Relation::MANY_AGGREGATE); 
    1669  
    1670         return $this; 
    1671     } 
    1672      
    1673     /** 
    1674      * @deprecated 
    1675      */ 
    1676     public function bindRelation($args, $type) 
    1677     { 
    1678         return $this->bind($args, $type); 
    1679     } 
    1680  
    1681     /** 
    1682      * @todo Relation mapping rewrite. 
    1683      * @deprecated 
    1684      */ 
    1685     public function bind($args, $type) 
    1686     { 
    1687         $options = array(); 
    1688         $options['type'] = $type; 
    1689  
    1690         if ( ! isset($args[1])) { 
    1691             $args[1] = array(); 
    1692         } 
    1693         if ( ! is_array($args[1])) { 
    1694             try { 
    1695                 throw new Exception(); 
    1696             } catch (Exception $e) { 
    1697                 echo $e->getTraceAsString(); 
    1698             } 
    1699         } 
    1700         $options = array_merge($args[1], $options); 
    1701         $this->_parser->bind($args[0], $options); 
    1702     } 
    1703  
    1704     /** 
    1705      * hasRelation 
    1706      * 
    1707      * @param string $alias      the relation to check if exists 
    1708      * @return boolean           true if the relation exists otherwise false 
    1709      * @deprecated 
    1710      */ 
    1711     public function hasRelation($alias) 
    1712     { 
    1713         return $this->_parser->hasRelation($alias); 
    1714     } 
    1715      
    17161721    public function hasAssociation($fieldName) 
    17171722    { 
     
    17201725 
    17211726    /** 
    1722      * getRelation 
    1723      * 
    1724      * @param string $alias      relation alias 
    1725      * @deprecated 
    1726      */ 
    1727     public function getRelation($alias, $recursive = true) 
    1728     { 
    1729         return $this->_parser->getRelation($alias, $recursive); 
    1730     } 
    1731      
    1732     /** 
    1733      * @deprecated 
    1734      */ 
    1735     public function getRelationParser() 
    1736     { 
    1737         return $this->_parser; 
    1738     } 
    1739  
    1740     /** 
    1741      * getRelations 
    1742      * returns an array containing all relation objects 
    1743      * 
    1744      * @return array        an array of Doctrine_Relation objects 
    1745      * @deprecated 
    1746      */ 
    1747     public function getRelations() 
    1748     { 
    1749         return $this->_parser->getRelations(); 
    1750     } 
    1751  
    1752     /** 
    17531727     * 
    17541728     */ 
  • trunk/lib/Doctrine/ClassMetadata/Factory.php

    r4776 r4789  
    3232 * @link        www.phpdoctrine.org 
    3333 * @since       2.0 
    34  * @todo Rename to ClassMetadataFactory. 
     34 * @todo Rename to ClassDescriptorFactory. 
    3535 */ 
    3636class Doctrine_ClassMetadata_Factory 
     
    115115        // -> child1 -> child2 -> $name 
    116116         
     117        // Move down the hierarchy of parent classes, starting from the topmost class 
    117118        $parent = $class; 
    118119        foreach ($parentClasses as $subclassName) { 
     
    122123            $this->_addInheritedRelations($subClass, $parent); 
    123124            $this->_loadMetadata($subClass, $subclassName); 
    124             if ($parent->getInheritanceType() == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { 
     125            if ($parent->isInheritanceTypeSingleTable()) { 
    125126                $subClass->setTableName($parent->getTableName()); 
    126127            } 
     
    133134     * Adds inherited fields to the subclass mapping. 
    134135     * 
     136     * @param Doctrine::ORM::Mapping::ClassMetadata $subClass 
     137     * @param Doctrine::ORM::Mapping::ClassMetadata $parentClass 
     138     * @return void 
     139     */ 
     140    protected function _addInheritedFields($subClass, $parentClass) 
     141    { 
     142        foreach ($parentClass->getFieldMappings() as $fieldName => $mapping) { 
     143            if ( ! isset($mapping['inherited'])) { 
     144                $mapping['inherited'] = $parentClass->getClassName(); 
     145            } 
     146            $subClass->addFieldMapping($fieldName, $mapping); 
     147        } 
     148    } 
     149     
     150    /** 
     151     * Adds inherited associations to the subclass mapping. 
     152     * 
    135153     * @param unknown_type $subClass 
    136154     * @param unknown_type $parentClass 
    137155     */ 
    138     protected function _addInheritedFields($subClass, $parentClass) 
    139     { 
    140         foreach ($parentClass->getFieldMappings() as $fieldName => $mapping) { 
    141             $fullName = "$name as " . $parentClass->getFieldName($name); 
    142             $mapping['inherited'] = true; 
    143             $subClass->mapField($mapping); 
    144         } 
    145     } 
    146      
    147     /** 
    148      * Adds inherited associations to the subclass mapping. 
    149      * 
    150      * @param unknown_type $subClass 
    151      * @param unknown_type $parentClass 
    152      */ 
    153156    protected function _addInheritedRelations($subClass, $parentClass)  
    154157    { 
    155         foreach ($parentClass->getRelationParser()->getRelationDefinitions() as $name => $definition) { 
    156             $subClass->getRelationParser()->addRelationDefinition($name, $definition); 
     158        foreach ($parentClass->getAssociationMappings() as $fieldName => $mapping) { 
     159            $subClass->addAssociationMapping($name, $mapping); 
    157160        } 
    158161    } 
  • trunk/lib/Doctrine/Collection.php

    r4776 r4789  
    8484     * @var Doctrine::ORM::Mapping::AssociationMapping              
    8585     */ 
    86     protected $_associationMapping; 
     86    protected $_association; 
    8787 
    8888    /** 
     
    9999     */ 
    100100    //protected static $null; 
    101      
    102     protected $_mapping; 
    103101     
    104102    /** 
     
    262260     * @return void 
    263261     */ 
    264     public function setReference(Doctrine_Entity $entity, $relation) 
     262    public function setReference(Doctrine_Entity $entity, Doctrine_Association $relation) 
    265263    { 
    266264        $this->_owner = $entity; 
    267         //$this->relation = $relation; 
     265        $this->_association = $relation; 
    268266 
    269267        /*if