Changeset 4718 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
07/27/08 20:38:56 (6 months ago)
Author:
romanb
Message:
 
Location:
trunk/lib/Doctrine
Files:
32 modified

Legend:

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

    r4456 r4718  
    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. 
    3739 */ 
    3840abstract class Doctrine_Access implements ArrayAccess 
  • trunk/lib/Doctrine/Association/ManyToMany.php

    r4699 r4718  
    3434     
    3535    /** The field in the source table that corresponds to the key in the relation table */ 
    36     protected $_sourceKeyFields; 
     36    protected $_sourceKeyColumns; 
    3737 
    3838    /**  The field in the target table that corresponds to the key in the relation table */ 
    39     protected $_targetKeyFields; 
     39    protected $_targetKeyColumns; 
    4040 
    4141    /** The field in the intermediate table that corresponds to the key in the source table */ 
    42     protected $_sourceRelationKeyFields; 
     42    protected $_sourceRelationKeyColumns; 
    4343 
    4444    /** The field in the intermediate table that corresponds to the key in the target table */ 
    45     protected $_targetRelationKeyFields; 
     45    protected $_targetRelationKeyColumns; 
    4646     
    4747     
  • trunk/lib/Doctrine/Association/OneToMany.php

    r4699 r4718  
    55class Doctrine_Association_OneToMany extends Doctrine_Association 
    66{ 
    7     /** The target foreign key fields that reference the sourceKeyFields. */ 
    8     protected $_targetForeignKeyFields; 
     7    /** The target foreign key columns that reference the sourceKeyColumns. */ 
     8    protected $_targetForeignKeyColumns; 
    99 
    10     /** The (typically primary) source key fields that are referenced by the targetForeignKeyFields. */ 
    11     protected $_sourceKeyFields; 
     10    /** The (typically primary) source key columns that are referenced by the targetForeignKeyColumns. */ 
     11    protected $_sourceKeyColumns; 
    1212 
    13     /** This maps the target foreign key fields to the corresponding (primary) source key fields. */ 
     13    /** This maps the target foreign key columns to the corresponding (primary) source key columns. */ 
    1414    protected $_targetForeignKeysToSourceKeys; 
    1515     
    16     /** This maps the (primary) source key fields to the corresponding target foreign key fields. */ 
     16    /** This maps the (primary) source key columns to the corresponding target foreign key columns. */ 
    1717    protected $_sourceKeysToTargetForeignKeys; 
    1818     
    1919    /** Whether to delete orphaned elements (removed from the collection) */ 
    20     protected $_isCascadeDeleteOrphan = false; 
     20    protected $_deleteOrphans = false; 
    2121     
    22     public function isCascadeDeleteOrphan() 
     22    public function shouldDeleteOrphans() 
    2323    { 
    24         return $this->_isCascadeDeleteOrphan; 
     24        return $this->_deleteOrphans; 
    2525    } 
    2626} 
  • trunk/lib/Doctrine/Association/OneToOne.php

    r4699 r4718  
    3535{ 
    3636    /** 
    37      * Maps the source foreign/primary key fields to the target primary/foreign key fields. 
     37     * Maps the source foreign/primary key columns to the target primary/foreign key columns. 
    3838     * i.e. source.id (pk) => target.user_id (fk). 
    39      * Reverse mapping of _targetToSourceKeyFields. 
     39     * Reverse mapping of _targetToSourceKeyColumns. 
    4040     */ 
    4141    protected $_sourceToTargetKeyColumns = array(); 
    4242 
    4343    /** 
    44      * Maps the target primary/foreign key fields to the source foreign/primary key fields. 
     44     * Maps the target primary/foreign key columns to the source foreign/primary key columns. 
    4545     * i.e. target.user_id (fk) => source.id (pk). 
    46      * Reverse mapping of _sourceToTargetKeyFields. 
     46     * Reverse mapping of _sourceToTargetKeyColumns. 
    4747     */ 
    4848    protected $_targetToSourceKeyColumns = array(); 
     49     
     50    /** Whether to delete orphaned elements (when nulled out, i.e. $foo->other = null) */ 
     51    protected $_deleteOrphans = false; 
    4952     
    5053    /** 
  • trunk/lib/Doctrine/ClassMetadata.php

    r4699 r4718  
    4141    const INHERITANCE_TYPE_TABLE_PER_CLASS = 'tablePerClass'; 
    4242     
    43     /** 
    44      * Inheritance types enumeration. 
    45      * 
    46      * @var array 
    47      */ 
    48     protected static $_inheritanceTypes = array( 
    49         self::INHERITANCE_TYPE_NONE, 
    50         self::INHERITANCE_TYPE_JOINED, 
    51         self::INHERITANCE_TYPE_SINGLE_TABLE, 
    52         self::INHERITANCE_TYPE_TABLE_PER_CLASS 
    53     ); 
    54      
    5543    /* The Id generator types. TODO: belongs more in a DBAL class */ 
    5644    const GENERATOR_TYPE_AUTO = 'auto'; 
     
    6048    const GENERATOR_TYPE_NONE = 'none'; 
    6149     
    62     /** 
    63      * Id Generator types enumeration. 
    64      * 
    65      * @var array 
    66      */ 
    67     protected static $_generatorTypes = array( 
    68         self::GENERATOR_TYPE_AUTO, 
    69         self::GENERATOR_TYPE_SEQUENCE, 
    70         self::GENERATOR_TYPE_TABLE, 
    71         self::GENERATOR_TYPE_IDENTITY, 
    72         self::GENERATOR_TYPE_NONE 
    73     ); 
     50    /* The Entity types */ 
     51    // A regular entity is assumed to have persistent state that Doctrine should manage. 
     52    const ENTITY_TYPE_REGULAR = 'regular'; 
     53    // A transient entity is ignored by Doctrine. 
     54    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. 
     57    const ENTITY_TYPE_MAPPED_SUPERCLASS = 'mappedSuperclass'; 
    7458     
    7559    /** 
     
    172156     * entity can have the id attribute, forming a composite key. 
    173157     *  
    174      * - <b>generatorType</b> (string, optional, requires: id) 
    175      * The generation type used for the field. Optional. Can only be applied on 
    176      * fields that are marked with the 'id' attribute. The possible values are: 
    177      * auto, identity, sequence, table. 
    178      *  
    179      * - <b>generator</b> (array, optional, requires: generationType=table|sequence) 
    180      * The generator options for a table or sequence generator. Can only be applied 
    181      * on fields that have a generationType of 'table' or 'sequence'. 
     158     * - <b>idGenerator</b> (string, optional) 
     159     * Either: idGenerator => 'nameOfGenerator', usually only for TABLE/SEQUENCE generators 
     160     * Or: idGenerator => 'identity' or 'auto' or 'table' or 'sequence' 
     161     * Note that 'auto', 'table', 'sequence' and 'identity' are reserved names and 
     162     * therefore cant be used as a generator name! 
    182163     *  
    183164     * - <b>nullable</b> (boolean, optional) 
     
    756737                $this->_identifier[] = $mapping['fieldName']; 
    757738            } 
    758             if (isset($mapping['generatorType'])) { 
    759                 if ( ! in_array($mapping['generatorType'], self::$_generatorTypes)) { 
     739            if (isset($mapping['idGenerator'])) { 
     740                if ( ! $this->_isIdGeneratorType($mapping['idGenerator'])) { 
     741                    //TODO: check if the idGenerator specifies an existing generator by name 
    760742                    throw Doctrine_MappingException::invalidGeneratorType($mapping['generatorType']); 
    761743                } else if (count($this->_identifier) > 1) { 
    762744                    throw Doctrine_MappingException::generatorNotAllowedWithCompositeId(); 
    763745                } 
    764                 $this->_generatorType = $mapping['generatorType']; 
     746                $this->_generatorType = $mapping['idGenerator']; 
    765747            } 
    766             // TODO: validate/complete 'generator' mapping 
     748            // TODO: validate/complete 'tableGenerator' and 'sequenceGenerator' mappings 
    767749             
    768750            // Check for composite key 
     
    11711153                . " in the root class of the hierarchy."); 
    11721154        } 
    1173         if ( ! in_array($type, self::$_inheritanceTypes)) { 
     1155        if ( ! $this->_isInheritanceType($type)) { 
    11741156            throw Doctrine_MappingException::invalidInheritanceType($type); 
    11751157        } 
     
    14111393    public function setTableName($tableName) 
    14121394    { 
    1413         $this->setTableOption('tableName', $this->_em->getConnection() 
    1414                 ->getFormatter()->getTableName($tableName)); 
     1395        $this->setTableOption('tableName', $tableName); 
    14151396    } 
    14161397 
     
    14401421    { 
    14411422        return true; 
     1423    } 
     1424     
     1425    /** 
     1426     * Checks whether the given name identifies an entity type. 
     1427     * 
     1428     * @param string $type 
     1429     * @return boolean 
     1430     */ 
     1431    private function _isEntityType($type) 
     1432    { 
     1433        return $type == self::ENTITY_TYPE_REGULAR || 
     1434                $type == self::ENTITY_TYPE_MAPPED_SUPERCLASS || 
     1435                $type == self::ENTITY_TYPE_TRANSIENT; 
     1436    } 
     1437     
     1438    /** 
     1439     * Checks whether the given name identifies an inheritance type. 
     1440     * 
     1441     * @param string $type 
     1442     * @return boolean 
     1443     */ 
     1444    private function _isInheritanceType($type) 
     1445    { 
     1446        return $type == self::INHERITANCE_TYPE_NONE || 
     1447                $type == self::INHERITANCE_TYPE_SINGLE_TABLE || 
     1448                $type == self::INHERITANCE_TYPE_JOINED || 
     1449                $type == self::INHERITANCE_TYPE_TABLE_PER_CLASS; 
     1450    } 
     1451     
     1452    /** 
     1453     * Checks whether the given name identifies an id generator type. 
     1454     * 
     1455     * @param string $type 
     1456     * @return boolean 
     1457     */ 
     1458    private function _isIdGeneratorType($type) 
     1459    { 
     1460        return $type == self::GENERATOR_TYPE_AUTO || 
     1461                $type == self::GENERATOR_TYPE_IDENTITY || 
     1462                $type == self::GENERATOR_TYPE_SEQUENCE || 
     1463                $type == self::GENERATOR_TYPE_TABLE || 
     1464                $type == self::GENERATOR_TYPE_NONE; 
    14421465    } 
    14431466 
  • trunk/lib/Doctrine/Compiler.php

    r4470 r4718  
    3333 * @since       1.0 
    3434 * @version     $Revision$ 
     35 * @todo Remove or put in a separate package and look for a maintainer. 
    3536 */ 
    3637class Doctrine_Compiler 
  • trunk/lib/Doctrine/Configuration.php

    r4628 r4718  
    4141     */ 
    4242    private $_attributes = array( 
    43             'quoteIdentifier' => false, 
     43            'quoteIdentifiers' => false, 
    4444            'indexNameFormat' => '%s_idx', 
    4545            'sequenceNameFormat' => '%s_seq', 
     
    8686    public function get($name) 
    8787    { 
    88         if ( ! $this->hasAttribute($name)) { 
     88        if ( ! $this->has($name)) { 
    8989            throw Doctrine_Configuration_Exception::unknownAttribute($name); 
    9090        } 
     
    103103    public function set($name, $value) 
    104104    { 
    105         if ( ! $this->hasAttribute($name)) { 
     105        if ( ! $this->has($name)) { 
    106106            throw Doctrine_Configuration_Exception::unknownAttribute($name); 
    107107        } 
  • trunk/lib/Doctrine/Connection.php

    r4699 r4718  
    2222#namespace Doctrine::DBAL::Connections; 
    2323 
     24#use Doctrine::Common::Configuration; 
     25 
    2426/** 
    25  * Doctrine_Connection 
    26  * 
    27  * A wrapper layer on top of PDO / Doctrine_Adapter 
    28  * 
    29  * Doctrine_Connection is the heart of any Doctrine based application. 
     27 * A thin connection wrapper on top of PDO. 
    3028 * 
    3129 * 1. Event listeners 
     
    4240 *    Doctrine_Connection provides many convenience methods such as fetchAll(), fetchOne() etc. 
    4341 * 
    44  * 4. Modular structure 
    45  *    Higher level functionality such as schema importing, exporting, sequence handling etc. 
    46  *    is divided into modules. For a full list of connection modules see 
    47  *    Doctrine_Connection::$_modules 
    48  * 
    49  * @package     Doctrine 
    50  * @subpackage  Connection 
    5142 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL 
    5243 * @link        www.phpdoctrine.org 
     
    7162 *       'masterConnectionResolver' => new MyMasterConnectionResolver() 
    7263 *  
    73  * Doctrine::DBAL could ship with a simple standard resolver that uses a primitive 
     64 * Doctrine::DBAL could ship with a simple standard broker that uses a primitive 
    7465 * round-robin approach to distribution. User can provide its own resolvers. 
    7566 */ 
     
    8677     * The Configuration. 
    8778     * 
    88      * @var Configuration 
     79     * @var Doctrine::Common::Configuration 
    8980     */ 
    9081    protected $_config; 
     
    9384     * The EventManager. 
    9485     * 
    95      * @var EventManager 
     86     * @var Doctrine::Commom::EventManager 
    9687     */ 
    9788    protected $_eventManager; 
     
    126117     
    127118    /** 
    128      * An array containing all features this driver supports, keys representing feature 
    129      * names and values as one of the following (true, false, 'emulated'). 
    130      * 
    131      * @var array $supported                     
    132      */ 
    133     protected $supported = array(); 
     119     * Boolean flag that indicates whether identifiers should get quoted. 
     120     * 
     121     * @var boolean 
     122     */ 
     123    protected $_quoteIdentifiers; 
    134124     
    135125    /** 
     
    164154     * List of all available drivers. 
    165155     *  
    166      * @var array $availableDrivers          
     156     * @var array $availableDrivers 
     157     * @todo Move elsewhere.        
    167158     */ 
    168159    private static $_availableDrivers = array( 
     
    176167     */ 
    177168    protected $_queryCount = 0; 
    178  
    179      
    180     /* 
    181      * -----------   Mixed attributes (need to split up)    --------------- 
    182      */ 
    183     /** 
    184      * @var array $modules                      an array containing all modules 
    185      *              transaction                 Doctrine_Transaction driver, handles savepoint and transaction isolation abstraction 
    186      * 
    187      *              expression                  Doctrine_Expression driver, handles expression abstraction 
    188      * 
    189      *              dataDict                    Doctrine_DataDict driver, handles datatype abstraction 
    190      * 
    191      *              export                      Doctrine_Export driver, handles db structure modification abstraction (contains 
    192      *                                          methods such as alterTable, createConstraint etc.) 
    193      *              import                      Doctrine_Import driver, handles db schema reading 
    194      * 
    195      *              sequence                    Doctrine_Sequence driver, handles sequential id generation and retrieval 
    196      * 
    197      *              unitOfWork                  Doctrine_Connection_UnitOfWork handles many orm functionalities such as object 
    198      *                                          deletion and saving 
    199      * 
    200      *              formatter                   Doctrine_Formatter handles data formatting, quoting and escaping 
    201      * 
    202      * @see Doctrine_Connection::__get() 
    203      * @see Doctrine_DataDict 
    204      * @see Doctrine_Expression 
    205      * @see Doctrine_Export 
    206      * @see Doctrine_Transaction 
    207      * @see Doctrine_Sequence 
    208      * @see Doctrine_Connection_UnitOfWork 
    209      * @see Doctrine_Formatter 
    210      */ 
    211     private $modules = array('transaction' => false, 
    212                              'expression'  => false, 
    213                              'dataDict'    => false, 
    214                              'export'      => false, 
    215                              'import'      => false, 
    216                              'sequence'    => false, 
    217                              'formatter'   => false, 
    218                              'util'        => false, 
    219                              ); 
    220      
     169     
     170    /** 
     171     * The DatabasePlatform object that provides information about the 
     172     * database platform used by the connection. 
     173     * 
     174     * @var Doctrine::DBAL::Platforms::DatabasePlatform 
     175     */ 
     176    protected $_databasePlatform;     
    221177 
    222178    /** 
    223179     * Constructor. 
     180     * Creates a new Connection. 
    224181     * 
    225182     * @param array $params  The connection parameters. 
     
    237194     * Sets the Configuration used by the Connection. 
    238195     * 
    239      * @param Doctrine_Configuration $config 
     196     * @param Doctrine::Common::Configuration $config 
    240197     */ 
    241198    public function setConfiguration(Doctrine_Configuration $config) 
     
    260217     * Sets the EventManager used by the Connection. 
    261218     * 
    262      * @param Doctrine_EventManager $eventManager 
     219     * @param Doctrine::Common::EventManager $eventManager 
    263220     */ 
    264221    public function setEventManager(Doctrine_EventManager $eventManager) 
     
    270227     * Gets the EventManager used by the Connection. 
    271228     * 
    272      * @return EventManager 
     229     * @return Doctrine::Common::EventManager 
    273230     */ 
    274231    public function getEventManager() 
     
    280237    } 
    281238     
     239    /** 
     240     * Enter description here... 
     241     * 
     242     * @param unknown_type $name 
     243     * @return unknown 
     244     * @todo Remove. Move properties to DatabasePlatform. 
     245     */ 
    282246    public function getProperty($name) 
    283247    { 
     
    289253     
    290254    /** 
    291      * returns an array of available PDO drivers 
     255     * Returns an array of available PDO drivers 
     256     * @todo Move elsewhere. 
    292257     */ 
    293258    public static function getAvailableDrivers() 
     
    297262     
    298263    /** 
    299      * getName 
    300264     * returns the name of this driver 
    301265     * 
     
    308272     
    309273    /** 
    310      * setName 
    311      * 
    312274     * Sets the name of the connection 
    313275     * 
     
    328290    { 
    329291        return $this->_driverName; 
    330     } 
    331      
    332     /** 
    333      * returns the database handler which this connection uses 
    334      * 
    335      * @return PDO              the database handler 
    336      * @deprecated 
    337      */ 
    338     public function getDbh() 
    339     { 
    340         $this->connect(); 
    341         return $this->_pdo; 
    342292    } 
    343293     
     
    422372        $this->_queryCount++; 
    423373    } 
    424  
    425     /** 
    426      * Checks whether a certain feature is supported. 
    427      * 
    428      * @param string $feature   the name of the feature 
    429      * @return boolean          whether or not this drivers supports given feature 
    430      */ 
    431     public function supports($feature) 
    432     { 
    433         return (isset($this->supported[$feature]) && 
    434                 ($this->supported[$feature] === 'emulated' || $this->supported[$feature])); 
    435     } 
    436374     
    437375    /** 
     
    639577    public function quoteIdentifier($str, $checkOption = true) 
    640578    { 
     579        if (is_null($this->_quoteIdentifiers)) { 
     580            $this->_quoteIdentifiers = $this->_config->get('quoteIdentifiers'); 
     581        } 
     582        if ( ! $this->_quoteIdentifiers) { 
     583            return $str; 
     584        } 
     585 
    641586        // quick fix for the identifiers that contain a dot 
    642587        if (strpos($str, '.')) { 
    643588            $e = explode('.', $str); 
    644  
    645             return $this->getFormatter()->quoteIdentifier($e[0], $checkOption) . '.' 
    646                  . $this->getFormatter()->quoteIdentifier($e[1], $checkOption); 
    647         } 
    648         return $this->getFormatter()->quoteIdentifier($str, $checkOption); 
    649     } 
    650  
    651     /** 
    652      * convertBooleans 
    653      * some drivers need the boolean values to be converted into integers 
    654      * when using DQL API 
     589            return $this->quoteIdentifier($e[0]) . '.' 
     590                    . $this->quoteIdentifier($e[1]); 
     591        } 
     592         
     593        $q = $this->properties['identifier_quoting']; 
     594        $str = str_replace($q['end'], $q['escape'] . $q['end'], $str); 
     595 
     596        return $q['start'] . $str . $q['end']; 
     597    } 
     598 
     599    /** 
     600     * Some drivers need the boolean values to be converted into integers 
     601     * when using DQL API. 
    655602     * 
    656603     * This method takes care of that conversion 
     
    661608    public function convertBooleans($item) 
    662609    { 
    663         return $this->getFormatter()->convertBooleans($item); 
     610        if (is_array($item)) { 
     611            foreach ($item as $k => $value) { 
     612                if (is_bool($value)) { 
     613                    $item[$k] = (int) $value; 
     614                } 
     615            } 
     616        } else { 
     617            if (is_bool($item)) { 
     618                $item = (int) $item; 
     619            } 
     620        } 
     621        return $item; 
    664622    } 
    665623 
     
    675633        return $this->_pdo->quote($input, $type); 
    676634    } 
     635    /** 
     636     * quote 
     637     * quotes given input parameter 
     638     * 
     639     * @param mixed $input      parameter to be quoted 
     640     * @param string $type 
     641     * @return mixed 
     642     */ 
     643    /*public function quote($input, $type = null) 
     644    { 
     645