Changeset 3787

Show
Ignore:
Timestamp:
02/15/08 16:50:08 (17 months ago)
Author:
jwage
Message:

Merging r3565 to 0.9 branch.

Location:
branches/0.9
Files:
17 modified

Legend:

Unmodified
Added
Removed
  • branches/0.9/lib/Doctrine.php

    r3672 r3787  
    188188    const ATTR_THROW_EXCEPTIONS         = 155; 
    189189    const ATTR_DEFAULT_PARAM_NAMESPACE  = 156; 
     190    const ATTR_MODEL_LOADING            = 167; 
    190191 
    191192    /** 
     
    422423 
    423424    /** 
     425     * MODEL_LOADING_AGGRESSIVE 
     426     * 
     427     * Constant for agressive model loading 
     428     * Will require_once() all found model files 
     429     * 
     430     * @see self::ATTR_MODEL_LOADING 
     431     */ 
     432    const MODEL_LOADING_AGGRESSIVE   = 1; 
     433 
     434    /** 
     435     * MODEL_LOADING_CONSERVATIVE 
     436     * 
     437     * Constant for conservative model loading 
     438     * Will not require_once() found model files inititally instead it will build an array 
     439     * and reference it in autoload() when a class is needed it will require_once() it 
     440     * 
     441     * @see self::ATTR_MODEL_LOADING 
     442     */ 
     443    const MODEL_LOADING_CONSERVATIVE= 2; 
     444 
     445    /** 
    424446     * Path 
    425447     * 
     
    444466     * @var array 
    445467     */ 
    446     private static $_loadedModels = array(); 
     468    private static $_loadedModelFiles = array(); 
    447469 
    448470    private static $_pathModels = array(); 
     
    469491    public static function getLoadedModelFiles() 
    470492    { 
    471         // [TODO] This method is just a wrapper of _loadedModels 
    472         // (which has named changed to _loadedModelFiles). The next task is 
    473         // to rename the _loadedModels to _loadedModelFiles inside Doctrine 
    474         return self::$_loadedModels; 
    475     } 
    476  
     493        return self::$_loadedModelFiles; 
     494    } 
     495     
    477496    public static function getPathModels() 
    478497    { 
     
    514533     * 
    515534     * Recursively load all models from a directory or array of directories 
    516      *  
    517      * @param string $directory Path to directory of models or array of directory paths 
     535     * 
     536     * @param string $directory    Path to directory of models or array of directory paths 
    518537     * @return array $loadedModels 
    519538     */ 
    520539    public static function loadModels($directory) 
    521540    { 
     541        $loadedModels = array(); 
     542         
    522543        if ($directory !== null) { 
    523544            $manager = Doctrine_Manager::getInstance(); 
     
    526547                $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), 
    527548                                                        RecursiveIteratorIterator::LEAVES_ONLY); 
    528  
    529549                foreach ($it as $file) { 
    530550                    $e = explode('.', $file->getFileName()); 
    531551                    if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { 
    532                         self::$_loadedModels[$e[0]] = $file->getPathName(); 
    533                         self::$_pathModels[$file->getPathName()][$e[0]] = $e[0]; 
     552                         
     553                        if ($manager->getAttribute(Doctrine::ATTR_MODEL_LOADING) === Doctrine::MODEL_LOADING_CONSERVATIVE) { 
     554                            self::$_loadedModelFiles[$e[0]] = $file->getPathName(); 
     555                            self::$_pathModels[$file->getPathName()][$e[0]] = $e[0]; 
     556 
     557                            $loadedModels[] = $e[0]; 
     558                        } else { 
     559                            $declaredBefore = get_declared_classes(); 
     560                            require_once($file->getPathName()); 
     561                             
     562                            $declaredAfter = get_declared_classes(); 
     563                            // Using array_slice because array_diff is broken is some PHP versions 
     564                            $foundClasses = array_slice($declaredAfter, count($declaredBefore) - 1); 
     565                            if ($foundClasses) { 
     566                                foreach ($foundClasses as $className) { 
     567                                    if (self::isValidModelClass($className) && !in_array($className, $loadedModels)) { 
     568                                        $loadedModels[] = $className; 
     569 
     570                                        self::$_pathModels[$file->getPathName()][$className] = $className; 
     571                                    } 
     572                                } 
     573                            } 
     574                        } 
    534575                    } 
    535576                } 
     
    537578        } 
    538579 
    539         return self::getLoadedModels(array_keys(self::$_loadedModels)); 
     580        return self::filterInvalidModels($loadedModels); 
    540581    } 
    541582 
     
    544585     * 
    545586     * Get all the loaded models, you can provide an array of classes or it will use get_declared_classes() 
    546      *  
     587     * 
    547588     * Will filter through an array of classes and return the Doctrine_Records out of them. 
    548589     * If you do not specify $classes it will return all of the currently loaded Doctrine_Records 
    549590     * 
    550      * @param $classes Array of classes to filter through, otherwise uses get_declared_classes() 
    551      * @return array $loadedModels 
     591     * @return array   $loadedModels 
    552592     */ 
    553593    public static function getLoadedModels($classes = null) 
    554594    { 
    555         if ($classes === null) { 
     595        if ($classes == null) 
     596        { 
    556597            $classes = get_declared_classes(); 
    557             $classes = array_merge($classes, array_keys(self::$_loadedModels)); 
    558         } 
    559          
    560         $parent = new ReflectionClass('Doctrine_Record'); 
    561          
    562         $loadedModels = array(); 
    563          
     598            $classes = array_merge($classes, array_keys(self::$_loadedModelFiles)); 
     599        } 
     600         
     601        return self::filterInvalidModels($classes); 
     602    } 
     603 
     604    /** 
     605     * filterInvalidModels 
     606     * 
     607     * Filter through an array of classes and return all the classes that are valid models 
     608     * 
     609     * @param classes  Array of classes to filter through, otherwise uses get_declared_classes() 
     610     * @return array   $loadedModels 
     611     */ 
     612    public static function filterInvalidModels($classes) 
     613    { 
     614        $validModels = array(); 
     615 
    564616        foreach ((array) $classes as $name) { 
    565             $class = new ReflectionClass($name); 
    566              
     617            if (self::isValidModelClass($name) && !in_array($name, $validModels)) { 
     618                $validModels[] = $name; 
     619            } 
     620        } 
     621 
     622        return $validModels; 
     623    } 
     624 
     625    /** 
     626     * isValidModelClass 
     627     * 
     628     * Checks if what is passed is a valid Doctrine_Record 
     629     * 
     630     * @param   mixed   $class Can be a string named after the class, an instance of the class, or an instance of the class reflected 
     631     * @return  boolean 
     632     */ 
     633    public static function isValidModelClass($class) 
     634    { 
     635        if ($class instanceof Doctrine_Record) { 
     636            $class = get_class($class); 
     637        } 
     638 
     639        if (is_string($class) && class_exists($class)) { 
     640            $class = new ReflectionClass($class); 
     641        } 
     642 
     643        if ($class instanceof ReflectionClass) { 
    567644            // Skip the following classes 
    568645            // - abstract classes 
    569             // - not a subclass of Doctrine_Record  
     646            // - not a subclass of Doctrine_Record 
    570647            // - don't have a setTableDefinition method 
    571             if ($class->isAbstract() ||  
    572                 !$class->isSubClassOf($parent) ||  
    573                 !$class->hasMethod('setTableDefinition')) { 
    574                 continue; 
     648            if (!$class->isAbstract() && 
     649                $class->isSubClassOf('Doctrine_Record') && 
     650                $class->hasMethod('setTableDefinition')) { 
     651 
     652                return true; 
    575653            } 
    576              
    577             $loadedModels[] = $name; 
    578         } 
    579          
    580         return $loadedModels; 
     654        } 
     655 
     656        return false; 
    581657    } 
    582658 
     
    732808    public static function createDatabases($specifiedConnections = array()) 
    733809    { 
    734         if ( ! is_array($specifiedConnections)) { 
    735             $specifiedConnections = (array) $specifiedConnections; 
    736         } 
    737          
    738         $manager = Doctrine_Manager::getInstance(); 
    739         $connections = $manager->getConnections(); 
    740          
    741         $results = array(); 
    742          
    743         foreach ($connections as $name => $connection) { 
    744             if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) { 
    745                 continue; 
    746             } 
    747              
    748             $info = $manager->parsePdoDsn($connection->getOption('dsn')); 
    749             $username = $connection->getOption('username'); 
    750             $password = $connection->getOption('password'); 
    751              
    752             // Make connection without database specified so we can create it 
    753             $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false); 
    754              
    755             try { 
    756                 // Create database 
    757                 $connect->export->createDatabase($name); 
    758                  
    759                 // Close the tmp connection with no database 
    760                 $manager->closeConnection($connect); 
    761                  
    762                 // Close original connection 
    763                 $manager->closeConnection($connection); 
    764                  
    765                 // Reopen original connection with newly created database 
    766                 $manager->openConnection(new PDO($info['dsn'], $username, $password), $name, true); 
    767                  
    768                 $results[$name] = true; 
    769             } catch (Exception $e) { 
    770                 $results[$name] = false; 
    771             } 
    772         } 
    773          
    774         return $results; 
     810        return Doctrine_Manager::getInstance()->createDatabases($specifiedConnections); 
    775811    } 
    776812 
     
    785821    public static function dropDatabases($specifiedConnections = array()) 
    786822    { 
    787         if ( ! is_array($specifiedConnections)) { 
    788             $specifiedConnections = (array) $specifiedConnections; 
    789         } 
    790          
    791         $manager = Doctrine_Manager::getInstance(); 
    792          
    793         $connections = $manager->getConnections(); 
    794          
    795         $results = array(); 
    796          
    797         foreach ($connections as $name => $connection) { 
    798             if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) { 
    799                 continue; 
    800             } 
    801              
    802             try { 
    803                 $connection->export->dropDatabase($name); 
    804                  
    805                 $results[$name] = true; 
    806             } catch (Exception $e) { 
    807                 $results[$name] = false; 
    808             } 
    809         } 
    810          
    811         return $results; 
     823        return Doctrine_Manager::getInstance()->dropDatabases($specifiedConnections); 
    812824    } 
    813825 
     
    975987        } 
    976988         
    977         $loadedModels = self::$_loadedModels; 
    978          
     989        $loadedModels = self::$_loadedModelFiles; 
     990 
    979991        if (isset($loadedModels[$className]) && file_exists($loadedModels[$className])) { 
    980             require_once($loadedModels[$className]); 
    981              
     992            require_once $loadedModels[$className]; 
     993 
    982994            return true; 
    983995        } 
  • branches/0.9/lib/Doctrine/Configurable.php

    r3678 r3787  
    140140            case Doctrine::ATTR_THROW_EXCEPTIONS: 
    141141            case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE: 
     142            case Doctrine::ATTR_MODEL_LOADING: 
    142143 
    143144                break; 
     
    379380    public function getAttribute($attribute) 
    380381    { 
     382        if (is_string($attribute)) { 
     383            $upper = strtoupper($attribute); 
     384 
     385            $const = 'Doctrine::ATTR_' . $upper;  
     386 
     387            if (defined($const)) { 
     388                $attribute = constant($const); 
     389                $this->_state = $attribute; 
     390            } else { 
     391                throw new Doctrine_Exception('Unknown attribute: "' . $attribute . '"'); 
     392            } 
     393        } 
     394 
    381395        $attribute = (int) $attribute; 
    382396 
  • branches/0.9/lib/Doctrine/Connection.php

    r3131 r3787  
    6868 
    6969    /** 
    70      * @var string $driverName                  the name of this connection driver 
     70     * $_name 
     71     * 
     72     * Name of the connection 
     73     * 
     74     * @var string $_name 
     75     */ 
     76    protected $_name; 
     77 
     78    /** 
     79     * The name of this connection driver. 
     80     * 
     81     * @var string $driverName                   
    7182     */ 
    7283    protected $driverName; 
     
    289300    public function getName() 
    290301    { 
     302        return $this->_name; 
     303    } 
     304 
     305    /** 
     306     * setName 
     307     * 
     308     * Sets the name of the connection 
     309     * 
     310     * @param string $name  
     311     * @return void 
     312     */ 
     313    public function setName($name) 
     314    { 
     315        $this->_name = $name; 
     316    } 
     317 
     318    /** 
     319     * getDriverName 
     320     * 
     321     * Gets the name of the instance driver 
     322     * 
     323     * @return void 
     324     */ 
     325    public function getDriverName() 
     326    { 
    291327        return $this->driverName; 
    292328    } 
     
    323359                    break; 
    324360                default: 
    325                     $class = 'Doctrine_' . ucwords($name) . '_' . $this->getName(); 
     361                    $class = 'Doctrine_' . ucwords($name) . '_' . $this->getDriverName(); 
    326362                    $this->modules[$name] = new $class($this); 
    327363                } 
     
    12621298    } 
    12631299 
     1300    public function createDatabase() 
     1301    { 
     1302        try { 
     1303            if ( ! $dsn = $this->getOption('dsn')) { 
     1304                throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); 
     1305            } 
     1306 
     1307            $manager = $this->getManager(); 
     1308 
     1309            $info = $manager->parsePdoDsn($dsn); 
     1310            $username = $this->getOption('username'); 
     1311            $password = $this->getOption('password'); 
     1312 
     1313            // Make connection without database specified so we can create it 
     1314            $connect = $manager->openConnection(new PDO($info['scheme'] . ':host=' . $info['host'], $username, $password), 'tmp_connection', false); 
     1315 
     1316            // Create database 
     1317            $connect->export->createDatabase($info['dbname']); 
     1318 
     1319            // Close the tmp connection with no database 
     1320            $manager->closeConnection($connect); 
     1321 
     1322            // Close original connection 
     1323            $manager->closeConnection($this); 
     1324 
     1325            // Reopen original connection with newly created database 
     1326            $manager->openConnection(new PDO($info['dsn'], $username, $password), $this->getName(), true); 
     1327 
     1328            return 'Successfully created database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; 
     1329        } catch (Exception $e) { 
     1330            return $e; 
     1331        } 
     1332    } 
     1333 
     1334    /** 
     1335     * dropDatabase 
     1336     * 
     1337     * Method for dropping the database for the connection instance 
     1338     * 
     1339     * @return mixed Will return an instance of the exception thrown if the drop database fails, otherwise it returns a string detailing the success 
     1340     */ 
     1341    public function dropDatabase() 
     1342    { 
     1343      try { 
     1344          if ( ! $dsn = $this->getOption('dsn')) { 
     1345              throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); 
     1346          } 
     1347 
     1348          $info = $this->getManager()->parsePdoDsn($dsn); 
     1349 
     1350          $this->export->dropDatabase($info['dbname']); 
     1351 
     1352          return 'Successfully dropped database for connection "' . $this->getName() . '" named "' . $info['dbname'] . '"'; 
     1353      } catch (Exception $e) { 
     1354          return $e; 
     1355      } 
     1356    } 
     1357 
    12641358    /** 
    12651359     * returns a string representation of this object 
  • branches/0.9/lib/Doctrine/Connection/Sqlite.php

    r3032 r3787  
    9999 
    100100    /** 
    101      * getDatabaseFile 
     101     * createDatabase 
    102102     * 
    103      * @param string $name      the name of the database 
    104      * @return string 
     103     * @return void 
    105104     */ 
    106     public function getDatabaseFile($name) 
     105    public function createDatabase() 
    107106    { 
    108         return $name . '.db'; 
     107      try { 
     108          if ( ! $dsn = $this->getOption('dsn')) { 
     109              throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); 
     110          } 
     111 
     112          $info = $this->getManager()->parseDsn($dsn); 
     113 
     114          $this->export->createDatabase($info['database']); 
     115 
     116          return 'Successfully created database for connection "' . $this->getName() . '" at path "' . $info['database'] . '"'; 
     117      } catch (Exception $e) { 
     118          return $e; 
     119      } 
     120    } 
     121 
     122    /** 
     123     * dropDatabase 
     124     * 
     125     * @return void 
     126     */ 
     127    public function dropDatabase() 
     128    { 
     129      try { 
     130          if ( ! $dsn = $this->getOption('dsn')) { 
     131              throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); 
     132          } 
     133           
     134          $info = $this->getManager()->parseDsn($dsn); 
     135 
     136          $this->export->dropDatabase($info['database']); 
     137 
     138          return 'Successfully dropped database for connection "' . $this->getName() . '" at path "' . $info['database'] . '"'; 
     139      } catch (Exception $e) { 
     140          return $e; 
     141      } 
    109142    } 
    110143} 
  • branches/0.9/lib/Doctrine/Connection/UnitOfWork.php

    r3131 r3787  
    674674            $table->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) { 
    675675 
    676             if (strtolower($this->conn->getName()) == 'pgsql') { 
     676            if (strtolower($this->conn->getDriverName()) == 'pgsql') { 
    677677                $seq = $table->getTableName() . '_' . $keys[0]; 
    678678            } 
  • branches/0.9/lib/Doctrine/Export.php

    r3769 r3787  
    10591059     * @return void 
    10601060     */ 
    1061     public function exportClasses(array $classes) 
    1062     { 
    1063         $connections = array(); 
    1064         foreach ($classes as $class) { 
    1065             $record = new $class(); 
    1066             $connection = $record->getTable()->getConnection(); 
    1067             $connectionName = Doctrine_Manager::getInstance()->getConnectionName($connection); 
    1068              
    1069             if ( ! isset($connections[$connectionName])) { 
    1070                 $connections[$connectionName] = array(); 
    1071                 $connections[$connectionName]['creates'] = array(); 
    1072                 $connections[$connectionName]['alters'] = array(); 
    1073             } 
    1074              
    1075             $sql = $this->exportClassesSql(array($class)); 
    1076             // Build array of all the creates 
    1077             // We need these to happen first 
    1078             foreach ($sql as $key => $query) { 
    1079                 if (strstr($query, 'CREATE')) { 
    1080                     $connections[$connectionName]['creates'][] = $query; 
    1081                     // Unset the create from sql so we can have an array of everything else but creates 
    1082                     unset($sql[$key]); 
    1083                 } 
    1084             } 
    1085              
    1086             $connections[$connectionName]['alters'] = array_merge($connections[$connectionName]['alters'], $sql); 
    1087         } 
    1088  
    1089         // Loop over all the sql again to merge the creates and alters in to the same array, but so that the alters are at the bottom 
    1090         $build = array(); 
    1091         foreach ($connections as $connectionName => $sql) { 
    1092             $build[$connectionName] = array_merge($sql['creates'], $sql['alters']); 
    1093         } 
    1094  
    1095         foreach ($build as $connectionName => $sql) { 
    1096             $connection = Doctrine_Manager::getInstance()->getConnection($connectionName); 
    1097              
    1098             $connection->beginTransaction(); 
    1099              
    1100             foreach ($sql as $query) { 
    1101                 try { 
    1102                     $connection->exec($query); 
    1103                 } catch (Doctrine_Connection_Exception $e) { 
    1104                     // we only want to silence table already exists errors 
    1105                     if ($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) { 
    1106                         $connection->rollback(); 
    1107                         throw new Doctrine_Export_Exception($e->getMessage() . '. Failing Query: ' . $query); 
    1108                     } 
    1109                 } 
    1110             } 
    1111              
    1112             $connection->commit(); 
    1113         } 
    1114     } 
     1061     public function exportClasses(array $classes) 
     1062     {  
     1063         $connections = array(); 
     1064         foreach ($classes as $class) { 
     1065             $record = new $class(); 
     1066             $connection = $record->getTable()->getConnection(); 
     1067             $connectionName = Doctrine_Manager::getInstance()->getConnectionName($connection); 
     1068 
     1069             if ( ! isset($connections[$connectionName])) { 
     1070                 $connections[$connectionName] = array( 
     1071                     'create_tables' => array(), 
     1072                     'create_sequences' => array(), 
     1073                     'alters' => array() 
     1074                 ); 
     1075             } 
     1076 
     1077             $sql = $this->exportClassesSql(array($class)); 
     1078 
     1079             // Build array of all the creates 
     1080             // We need these to happen first 
     1081             foreach ($sql as $key => $query) { 
     1082                 if (strstr($query, 'CREATE TABLE')) { 
     1083                     $connections[$connectionName]['create_tables'][] = $query; 
     1084 
     1085                     unset($sql[$key]); 
     1086                 } 
     1087 
     1088                 if (strstr($query, 'CREATE SEQUENCE')) { 
     1089                     $connections[$connectionName]['create_sequences'][] = $query; 
     1090 
     1091                     unset($sql[$key]); 
     1092                 } 
     1093             } 
     1094 
     1095             $connections[$connectionName]['alters'] = array_merge($connections[$connectionName]['alters'], $sql); 
     1096         } 
     1097 
     1098         // Loop over all the sql again to merge the creates and alters in to the same array, but so that the alters are at the bottom 
     1099         $build = array(); 
     1100         foreach ($connections as $connectionName => $sql) { 
     1101             $build[$connectionName] = array_merge($sql['create_tables'], $sql['create_sequences'], $sql['alters']); 
     1102         } 
     1103 
     1104         foreach ($build as $connectionName => $sql) { 
     1105             $connection = Doctrine_Manager::getInstance()->getConnection($connectionName); 
     1106 
     1107             $connection->beginTransaction(); 
     1108 
     1109             foreach ($sql as $query) { 
     1110                 try { 
     1111                     $connection->exec($query); 
     1112                 } catch (Doctrine_Connection_Exception $e) { 
     1113                     // we only want to silence table already exists errors 
     1114                     if ($e->getPortableCode() !== Doctrine::ERR_ALREADY_EXISTS) { 
     1115                         $connection->rollback(); 
     1116                         throw new Doctrine_Export_Exception($e->getMessage() . '. Failing Query: ' . $query); 
     1117                     } 
     1118                 } 
     1119             } 
     1120 
     1121             $connection->commit(); 
     1122         } 
     1123     } 
    11151124 
    11161125    /** 
  • branches/0.9/lib/Doctrine/Export/Sqlite.php

    r3048 r3787  
    3535{ 
    3636    /** 
     37     * dropDatabase 
     38     * 
    3739     * drop an existing database 
    3840     * 
    39      * @param string $name                  name of the database that should be dropped 
     41     * @param string $databaseFile          Path of the database that should be dropped 
    4042     * @throws Doctrine_Export_Exception    if the database file does not exist 
    4143     * @throws Doctrine_Export_Exception    if something failed during the removal of the database file 
    4244     * @return void 
    4345     */ 
    44     public function dropDatabase($name) 
    45     { 
    46         $databaseFile = $this->conn->getDatabaseFile($name); 
     46    public function dropDatabase($databaseFile) 
     47    { 
    4748        if ( ! @file_exists($databaseFile)) { 
    4849            throw new Doctrine_Export_Exception('database does not exist'); 
    4950        } 
     51 
    5052        $result = @unlink($databaseFile); 
     53 
    5154        if ( ! $result) { 
    5255            throw new Doctrine_Export_Exception('could not remove the database file'); 
    5356        } 
     57    } 
     58 
     59    /** 
     60     * createDatabase 
     61     * 
     62     * Create sqlite database file 
     63     * 
     64     * @param string $databaseFile  Path of the database that should be dropped 
     65     * @return void 
     66     */ 
     67    public function createDatabase($databaseFile) 
     68    { 
     69        return new PDO('sqlite:' . $databaseFile); 
    5470    } 
    5571 
  • branches/0.9/lib/Doctrine/Manager.php

    r3071 r3787  
    253253 
    254254            $driverName = $adapter->getAttribute(Doctrine::ATTR_DRIVER_NAME); 
    255         } elseif (is_array($adapter)) { 
     255        } else if (is_array($adapter)) { 
    256256            if ( ! isset($adapter[0])) { 
    257257                throw new Doctrine_Manager_Exception('Empty data source name given.'); 
     
    267267            $parts['user']   = (isset($adapter[1])) ? $adapter[1] : null; 
    268268            $parts['pass']   = (isset($adapter[2])) ? $adapter[2] : null; 
    269              
     269 
    270270            $driverName = $e[0]; 
    271271            $adapter = $parts; 
    272272        } else { 
    273273            $parts = $this->parseDsn($adapter); 
    274              
    275274            $driverName = $parts['scheme']; 
    276              
    277275            $adapter = $parts; 
    278276        } 
     
    284282            $name = (string) $name; 
    285283            if (isset($this->_connections[$name])) { 
     284                if ($setCurrent) { 
     285                    $this->_currIndex = $name; 
     286                } 
    286287                return $this->_connections[$name]; 
    287288            } 
     
    290291            $this->_index++; 
    291292        } 
    292  
    293293 
    294294        $drivers = array('mysql'    => 'Doctrine_Connection_Mysql', 
     
    303303                         'informix' => 'Doctrine_Connection_Informix', 
    304304                         'mock'     => 'Doctrine_Connection_Mock'); 
     305 
    305306        if ( ! isset($drivers[$driverName])) { 
    306307            throw new Doctrine_Manager_Exception('Unknown driver ' . $driverName); 
    307308        } 
    308          
     309 
    309310        $className = $drivers[$driverName]; 
    310311        $conn = new $className($this, $adapter); 
     312        $conn->setName($name); 
    311313 
    312314        $this->_connections[$name] = $conn; 
     
    318320    } 
    319321     
     322    /** 
     323     * parsePdoDsn 
     324     * 
     325     * @param array $dsn An array of dsn information 
     326     * @return array The array parsed 
     327     * @todo package:dbal 
     328     */ 
    320329    public function parsePdoDsn($dsn) 
    321330    { 
    322331        $parts = array(); 
    323          
     332 
    324333        $names = array('dsn', 'scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'); 
    325334 
     
    329338            } 
    330339        } 
    331          
     340 
    332341        $e = explode(':', $dsn); 
    333342        $parts['scheme'] = $e[0]; 
    334343        $parts['dsn'] = $dsn; 
    335          
     344 
    336345        $e = explode(';', $e[1]); 
    337346        foreach ($e as $string) { 
    338             list($key, $value) = explode('=', $string); 
    339             $parts[$key] = $value; 
    340         } 
    341          
     347            if ($string) { 
     348                $e2 = explode('=', $string); 
     349 
     350                if (isset($e2[0]) && isset($e2[1])) { 
     351                    list($key, $value) = $e2; 
     352                    $parts[$key] = $value; 
     353                } 
     354            } 
     355        } 
     356 
    342357        return $parts; 
    343358    } 
     
    348363     * @param string $dsn 
    349364     * @return array Parsed contents of DSN 
     365     * @todo package:dbal 
    350366     */ 
    351367    public function parseDsn($dsn) 
    352368    { 
    353  
    354  
    355         //fix linux sqlite dsn so that it will parse correctly 
    356         $dsn = str_replace("///", "/", $dsn); 
     369        // fix sqlite dsn so that it will parse correctly 
     370        $dsn = str_replace("////", "/", $dsn); 
     371        $dsn = str_replace("///c:/", "//c:/", $dsn); 
    357372 
    358373        // silence any warnings 
     
    389404 
    390405                break; 
    391              
     406 
    392407            case 'mssql': 
    393408            case 'dblib': 
     
    401416                    throw new Doctrine_Manager_Exception('No hostname set in data source name'); 
    402417                } 
    403                  
     418 
    404419                if (isset(self::$driverMap[$parts['scheme']])) { 
    405420                    $parts['scheme'] = self::$driverMap[$parts['scheme']]; 
     
    409424                              . $parts['host'] . (isset($parts['port']) ? ':' . $parts['port']:null) . ';dbname=' 
    410425                              . $parts['database']; 
    411                  
     426 
    412427                break; 
    413428 
     
    430445                    throw new Doctrine_Manager_Exception('No hostname set in data source name'); 
    431446                } 
    432                  
     447 
    433448                if (isset(self::$driverMap[$parts['scheme']])) { 
    434449                    $parts['scheme'] = self::$driverMap[$parts['scheme']]; 
     
    438453                              . $parts['host'] . (isset($parts['port']) ? ';port=' . $parts['port']:null) . ';dbname=' 
    439454                              . $parts['database']; 
    440                  
     455 
    441456                break; 
    442457            default: 
    443458                throw new Doctrine_Manager_Exception('Unknown driver '.$parts['scheme']); 
    444459        } 
    445  
    446460 
    447461        return $parts; 
     
    663677        } 
    664678        return $this->_connections[$i]; 
     679    } 
     680 
     681    /** 
     682     * createDatabases 
     683     * 
     684     * Creates databases for connections 
     685     * 
     686     * @param string $specifiedConnections Array of connections you wish to create the database for 
     687     * @return void 
     688     * @todo package:dbal 
     689     */ 
     690    public function createDatabases($specifiedConnections = array()) 
     691    { 
     692        if ( ! is_array($specifiedConnections)) { 
     693            $specifiedConnections = (array) $specifiedConnections; 
     694        } 
     695 
     696        $results = array(); 
     697 
     698        foreach ($this as $name => $connection) { 
     699            if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) { 
     700                continue; 
     701            } 
     702 
     703            $results[$name] = $connection->createDatabase(); 
     704        } 
     705 
     706        return $results; 
     707    } 
     708 
     709    /** 
     710     * dropDatabases 
     711     * 
     712     * Drops databases for connections 
     713     * 
     714     * @param string $specifiedConnections Array of connections you wish to drop the database for 
     715     * @return void 
     716     * @todo package:dbal 
     717     */ 
     718    public function dropDatabases($specifiedConnections = array()) 
     719    { 
     720        if ( ! is_array($specifiedConnections)) { 
     721            $specifiedConnections = (array) $specifiedConnections; 
     722        } 
     723 
     724        $results = array(); 
     725 
     726        foreach ($this as $name => $connection) { 
     727            if ( ! empty($specifiedConnections) && !in_array($name, $specifiedConnections)) { 
     728                continue; 
     729            } 
     730 
     731            $results[$name] = $connection->dropDatabase(); 
     732        } 
     733 
     734        return $results; 
    665735    } 
    666736 
  • branches/0.9/lib/Doctrine/Query.php

    r3782 r3787  
    11961196 
    11971197 
    1198                 switch (strtolower($this->_conn->getName())) { 
     1198                switch (strtolower($this->_conn->getDriverName())) { 
    11991199                    case 'mysql': 
    12001200                        // mysql doesn't support LIMIT in subqueries 
  • branches/0.9/lib/Doctrine/Task/CreateDb.php

    r3128 r3787  
    4040        $results = Doctrine::createDatabases(); 
    4141         
    42         foreach ($results as $dbName => $bool) { 
    43             $msg = $bool ? 'Successfully created database named: "' . $dbName . '"':'Could not create database named: "' .$dbName . '"'; 
     42        foreach ($results as $name => $result) { 
     43            $msg = $result instanceof Exception ? 'Could not create database for connection: "' .$name . '." Failed with exception: ' . $result->getMessage():$result; 
    4444             
    4545            $this->notify($msg); 
  • branches/0.9/lib/Doctrine/Task/DropDb.php

    r3679 r3787  
    5151        $results = Doctrine::dropDatabases(); 
    5252 
    53         foreach ($results as $dbName => $bool) { 
    54             $msg = $bool ? 'Successfully dropped database named: "' . $dbName . '"':'Could not drop database named: "' .$dbName . '"'; 
     53        foreach ($results as $name => $result) { 
     54            $msg = $result instanceof Exception ? 'Could not drop database for connection: "' .$name . '." Failed with exception: ' . $result->getMessage():$result; 
    5555 
    5656            $this->notify($msg); 
  • branches/0.9/manual/docs/en/facade.txt

    r3129 r3787  
    2929 
    3030// Pass an array of classes to the above method and it will filter out the ones that are not Doctrine_Records 
    31 $models = Doctrine::getLoadedModels(array('User', 'Formatter', 'Doctrine_Record')); 
     31$models = Doctrine::filterInvalidModels(array('User', 'Formatter', 'Doctrine_Record')); 
    3232print_r($models); // would return array('User') because Formatter and Doctrine_Record are not Doctrine_Records 
    3333 
  • branches/0.9/tests/Export/SqliteTestCase.php

    r2963 r3787  
    3333class Doctrine_Export_Sqlite_TestCase extends Doctrine_UnitTestCase  
    3434{ 
    35     public function testCreateDatabaseDoesNotExecuteSql()  
     35    public function testCreateDatabaseDoesNotExecuteSqlAndCreatesSqliteFile() 
    3636    { 
    37         try { 
    38             $this->export->createDatabase('db'); 
    39             $this->fail(); 
    40         } catch(Doctrine_Export_Exception $e) { 
    41             $this->pass(); 
    42         } 
     37        $this->export->createDatabase('sqlite.db'); 
     38       
     39        $this->assertTrue(file_exists('sqlite.db')); 
    4340    } 
    44     public function testDropDatabaseDoesNotExecuteSql()  
     41    public function testDropDatabaseDoesNotExecuteSqlAndDeletesSqliteFile() 
    4542    { 
    46         try { 
    47             $this->export->dropDatabase('db'); 
    48             $this->fail(); 
    49         } catch(Doctrine_Export_Exception $e) { 
    50             $this->pass(); 
    51         } 
     43        $this->export->dropDatabase('sqlite.db'); 
     44 
     45        $this->assertFalse(file_exists('sqlite.db')); 
    5246    } 
    5347    public function testCreateTableSupportsAutoincPks()  
  • branches/0.9/tests/ManagerTestCase.php

    r3071 r3787  
    6666        // It expects only // since it thinks it is parsing a url 
    6767        // The problem after that is that the dns is not valid when being passed to PDO 
    68         $sqlite = 'sqlite:///full/unix/path/to/file.db'; 
    69         $sqlitewin = 'sqlite://c:/full/windows/path/to/file.db'; 
     68        $sqlite = 'sqlite:////full/unix/path/to/file.db'; 
     69        $sqlitewin = 'sqlite:///c:/full/windows/path/to/file.db'; 
    7070         
    7171        $manager = Doctrine_Manager::getInstance(); 
  • branches/0.9/tests/TreeStructureTestCase.php

    r2353 r3787  
    104104        $o4->save(); 
    105105 
    106         $o1->Children; 
    107106        $this->assertFalse(isset($o1->Parent)); 
     107        $this->assertTrue(isset($o2->Parent)); 
     108        $this->assertTrue($o2->Parent === $o1); 
     109        $this->assertFalse(isset($o4->Parent)); 
     110       
    108111        $this->assertTrue(count($o1->Children) == 2); 
    109112        $this->assertTrue(count($o1->get('Children')) == 2); 
    110113 
    111         $this->assertTrue(isset($o2->Parent)); 
    112         $this->assertTrue($o2->Parent === $o1); 
    113  
    114114        $this->assertTrue(count($o4->Children) == 0); 
    115         $this->assertFalse(isset($o4->Parent)); 
    116115    } 
    117116    public function testTreeStructureFetchingWorksWithDql() 
  • branches/0.9/tools/sandbox/config.php.dist

    r2994 r3787  
    4343define('YAML_SCHEMA_PATH', SANDBOX_PATH . DIRECTORY_SEPARATOR . 'schema'); 
    4444define('DB_PATH', SANDBOX_PATH . DIRECTORY_SEPARATOR . 'sandbox.db'); 
    45 define('DSN', 'sqlite:' . DB_PATH); 
     45define('DSN', 'sqlite:///' . DB_PATH); 
    4646 
    4747require_once(DOCTRINE_PATH . DIRECTORY_SEPARATOR . 'Doctrine.php'); 
     
    4949spl_autoload_register(array('Doctrine', 'autoload')); 
    5050 
    51 $pdo = new PDO(DSN); 
    52 Doctrine_Manager::connection($pdo, 'sandbox'); 
     51Doctrine_Manager::connection(DSN, 'sandbox'); 
     52 
     53Doctrine_Manager::getInstance()->setAttribute('model_loading', 'conservative');