Changeset 3787
- Timestamp:
- 02/15/08 16:50:08 (17 months ago)
- Location:
- branches/0.9
- Files:
-
- 17 modified
-
lib/Doctrine.php (modified) (11 diffs)
-
lib/Doctrine/Configurable.php (modified) (2 diffs)
-
lib/Doctrine/Connection.php (modified) (4 diffs)
-
lib/Doctrine/Connection/Sqlite.php (modified) (1 diff)
-
lib/Doctrine/Connection/UnitOfWork.php (modified) (1 diff)
-
lib/Doctrine/Export.php (modified) (1 diff)
-
lib/Doctrine/Export/Sqlite.php (modified) (1 diff)
-
lib/Doctrine/Manager.php (modified) (14 diffs)
-
lib/Doctrine/Query.php (modified) (1 diff)
-
lib/Doctrine/Task/CreateDb.php (modified) (1 diff)
-
lib/Doctrine/Task/DropDb.php (modified) (1 diff)
-
manual/docs/en/facade.txt (modified) (1 diff)
-
tests/Export/SqliteTestCase.php (modified) (1 diff)
-
tests/ManagerTestCase.php (modified) (1 diff)
-
tests/TreeStructureTestCase.php (modified) (1 diff)
-
tools/sandbox/config.php.dist (modified) (2 diffs)
-
tools/sandbox/sandbox.db (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/lib/Doctrine.php
r3672 r3787 188 188 const ATTR_THROW_EXCEPTIONS = 155; 189 189 const ATTR_DEFAULT_PARAM_NAMESPACE = 156; 190 const ATTR_MODEL_LOADING = 167; 190 191 191 192 /** … … 422 423 423 424 /** 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 /** 424 446 * Path 425 447 * … … 444 466 * @var array 445 467 */ 446 private static $_loadedModel s = array();468 private static $_loadedModelFiles = array(); 447 469 448 470 private static $_pathModels = array(); … … 469 491 public static function getLoadedModelFiles() 470 492 { 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 477 496 public static function getPathModels() 478 497 { … … 514 533 * 515 534 * 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 paths535 * 536 * @param string $directory Path to directory of models or array of directory paths 518 537 * @return array $loadedModels 519 538 */ 520 539 public static function loadModels($directory) 521 540 { 541 $loadedModels = array(); 542 522 543 if ($directory !== null) { 523 544 $manager = Doctrine_Manager::getInstance(); … … 526 547 $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), 527 548 RecursiveIteratorIterator::LEAVES_ONLY); 528 529 549 foreach ($it as $file) { 530 550 $e = explode('.', $file->getFileName()); 531 551 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 } 534 575 } 535 576 } … … 537 578 } 538 579 539 return self:: getLoadedModels(array_keys(self::$_loadedModels));580 return self::filterInvalidModels($loadedModels); 540 581 } 541 582 … … 544 585 * 545 586 * Get all the loaded models, you can provide an array of classes or it will use get_declared_classes() 546 * 587 * 547 588 * Will filter through an array of classes and return the Doctrine_Records out of them. 548 589 * If you do not specify $classes it will return all of the currently loaded Doctrine_Records 549 590 * 550 * @param $classes Array of classes to filter through, otherwise uses get_declared_classes() 551 * @return array $loadedModels 591 * @return array $loadedModels 552 592 */ 553 593 public static function getLoadedModels($classes = null) 554 594 { 555 if ($classes === null) { 595 if ($classes == null) 596 { 556 597 $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 564 616 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) { 567 644 // Skip the following classes 568 645 // - abstract classes 569 // - not a subclass of Doctrine_Record 646 // - not a subclass of Doctrine_Record 570 647 // - 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; 575 653 } 576 577 $loadedModels[] = $name; 578 } 579 580 return $loadedModels; 654 } 655 656 return false; 581 657 } 582 658 … … 732 808 public static function createDatabases($specifiedConnections = array()) 733 809 { 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); 775 811 } 776 812 … … 785 821 public static function dropDatabases($specifiedConnections = array()) 786 822 { 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); 812 824 } 813 825 … … 975 987 } 976 988 977 $loadedModels = self::$_loadedModel s;978 989 $loadedModels = self::$_loadedModelFiles; 990 979 991 if (isset($loadedModels[$className]) && file_exists($loadedModels[$className])) { 980 require_once ($loadedModels[$className]);981 992 require_once $loadedModels[$className]; 993 982 994 return true; 983 995 } -
branches/0.9/lib/Doctrine/Configurable.php
r3678 r3787 140 140 case Doctrine::ATTR_THROW_EXCEPTIONS: 141 141 case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE: 142 case Doctrine::ATTR_MODEL_LOADING: 142 143 143 144 break; … … 379 380 public function getAttribute($attribute) 380 381 { 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 381 395 $attribute = (int) $attribute; 382 396 -
branches/0.9/lib/Doctrine/Connection.php
r3131 r3787 68 68 69 69 /** 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 71 82 */ 72 83 protected $driverName; … … 289 300 public function getName() 290 301 { 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 { 291 327 return $this->driverName; 292 328 } … … 323 359 break; 324 360 default: 325 $class = 'Doctrine_' . ucwords($name) . '_' . $this->get Name();361 $class = 'Doctrine_' . ucwords($name) . '_' . $this->getDriverName(); 326 362 $this->modules[$name] = new $class($this); 327 363 } … … 1262 1298 } 1263 1299 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 1264 1358 /** 1265 1359 * returns a string representation of this object -
branches/0.9/lib/Doctrine/Connection/Sqlite.php
r3032 r3787 99 99 100 100 /** 101 * getDatabaseFile101 * createDatabase 102 102 * 103 * @param string $name the name of the database 104 * @return string 103 * @return void 105 104 */ 106 public function getDatabaseFile($name)105 public function createDatabase() 107 106 { 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 } 109 142 } 110 143 } -
branches/0.9/lib/Doctrine/Connection/UnitOfWork.php
r3131 r3787 674 674 $table->getIdentifierType() != Doctrine::IDENTIFIER_NATURAL) { 675 675 676 if (strtolower($this->conn->get Name()) == 'pgsql') {676 if (strtolower($this->conn->getDriverName()) == 'pgsql') { 677 677 $seq = $table->getTableName() . '_' . $keys[0]; 678 678 } -
branches/0.9/lib/Doctrine/Export.php
r3769 r3787 1059 1059 * @return void 1060 1060 */ 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 } 1115 1124 1116 1125 /** -
branches/0.9/lib/Doctrine/Export/Sqlite.php
r3048 r3787 35 35 { 36 36 /** 37 * dropDatabase 38 * 37 39 * drop an existing database 38 40 * 39 * @param string $ name nameof the database that should be dropped41 * @param string $databaseFile Path of the database that should be dropped 40 42 * @throws Doctrine_Export_Exception if the database file does not exist 41 43 * @throws Doctrine_Export_Exception if something failed during the removal of the database file 42 44 * @return void 43 45 */ 44 public function dropDatabase($name) 45 { 46 $databaseFile = $this->conn->getDatabaseFile($name); 46 public function dropDatabase($databaseFile) 47 { 47 48 if ( ! @file_exists($databaseFile)) { 48 49 throw new Doctrine_Export_Exception('database does not exist'); 49 50 } 51 50 52 $result = @unlink($databaseFile); 53 51 54 if ( ! $result) { 52 55 throw new Doctrine_Export_Exception('could not remove the database file'); 53 56 } 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); 54 70 } 55 71 -
branches/0.9/lib/Doctrine/Manager.php
r3071 r3787 253 253 254 254 $driverName = $adapter->getAttribute(Doctrine::ATTR_DRIVER_NAME); 255 } else if (is_array($adapter)) {255 } else if (is_array($adapter)) { 256 256 if ( ! isset($adapter[0])) { 257 257 throw new Doctrine_Manager_Exception('Empty data source name given.'); … … 267 267 $parts['user'] = (isset($adapter[1])) ? $adapter[1] : null; 268 268 $parts['pass'] = (isset($adapter[2])) ? $adapter[2] : null; 269 269 270 270 $driverName = $e[0]; 271 271 $adapter = $parts; 272 272 } else { 273 273 $parts = $this->parseDsn($adapter); 274 275 274 $driverName = $parts['scheme']; 276 277 275 $adapter = $parts; 278 276 } … … 284 282 $name = (string) $name; 285 283 if (isset($this->_connections[$name])) { 284 if ($setCurrent) { 285 $this->_currIndex = $name; 286 } 286 287 return $this->_connections[$name]; 287 288 } … … 290 291 $this->_index++; 291 292 } 292 293 293 294 294 $drivers = array('mysql' => 'Doctrine_Connection_Mysql', … … 303 303 'informix' => 'Doctrine_Connection_Informix', 304 304 'mock' => 'Doctrine_Connection_Mock'); 305 305 306 if ( ! isset($drivers[$driverName])) { 306 307 throw new Doctrine_Manager_Exception('Unknown driver ' . $driverName); 307 308 } 308 309 309 310 $className = $drivers[$driverName]; 310 311 $conn = new $className($this, $adapter); 312 $conn->setName($name); 311 313 312 314 $this->_connections[$name] = $conn; … … 318 320 } 319 321 322 /** 323 * parsePdoDsn 324 * 325 * @param array $dsn An array of dsn information 326 * @return array The array parsed 327 * @todo package:dbal 328 */ 320 329 public function parsePdoDsn($dsn) 321 330 { 322 331 $parts = array(); 323 332 324 333 $names = array('dsn', 'scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'); 325 334 … … 329 338 } 330 339 } 331 340 332 341 $e = explode(':', $dsn); 333 342 $parts['scheme'] = $e[0]; 334 343 $parts['dsn'] = $dsn; 335 344 336 345 $e = explode(';', $e[1]); 337 346 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 342 357 return $parts; 343 358 } … … 348 363 * @param string $dsn 349 364 * @return array Parsed contents of DSN 365 * @todo package:dbal 350 366 */ 351 367 public function parseDsn($dsn) 352 368 { 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); 357 372 358 373 // silence any warnings … … 389 404 390 405 break; 391 406 392 407 case 'mssql': 393 408 case 'dblib': … … 401 416 throw new Doctrine_Manager_Exception('No hostname set in data source name'); 402 417 } 403 418 404 419 if (isset(self::$driverMap[$parts['scheme']])) { 405 420 $parts['scheme'] = self::$driverMap[$parts['scheme']]; … … 409 424 . $parts['host'] . (isset($parts['port']) ? ':' . $parts['port']:null) . ';dbname=' 410 425 . $parts['database']; 411 426 412 427 break; 413 428 … … 430 445 throw new Doctrine_Manager_Exception('No hostname set in data source name'); 431 446 } 432 447 433 448 if (isset(self::$driverMap[$parts['scheme']])) { 434 449 $parts['scheme'] = self::$driverMap[$parts['scheme']]; … … 438 453 . $parts['host'] . (isset($parts['port']) ? ';port=' . $parts['port']:null) . ';dbname=' 439 454 . $parts['database']; 440 455 441 456 break; 442 457 default: 443 458 throw new Doctrine_Manager_Exception('Unknown driver '.$parts['scheme']); 444 459 } 445 446 460 447 461 return $parts; … … 663 677 } 664 678 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; 665 735 } 666 736 -
branches/0.9/lib/Doctrine/Query.php
r3782 r3787 1196 1196 1197 1197 1198 switch (strtolower($this->_conn->get Name())) {1198 switch (strtolower($this->_conn->getDriverName())) { 1199 1199 case 'mysql': 1200 1200 // mysql doesn't support LIMIT in subqueries -
branches/0.9/lib/Doctrine/Task/CreateDb.php
r3128 r3787 40 40 $results = Doctrine::createDatabases(); 41 41 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; 44 44 45 45 $this->notify($msg); -
branches/0.9/lib/Doctrine/Task/DropDb.php
r3679 r3787 51 51 $results = Doctrine::dropDatabases(); 52 52 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; 55 55 56 56 $this->notify($msg); -
branches/0.9/manual/docs/en/facade.txt
r3129 r3787 29 29 30 30 // 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')); 32 32 print_r($models); // would return array('User') because Formatter and Doctrine_Record are not Doctrine_Records 33 33 -
branches/0.9/tests/Export/SqliteTestCase.php
r2963 r3787 33 33 class Doctrine_Export_Sqlite_TestCase extends Doctrine_UnitTestCase 34 34 { 35 public function testCreateDatabaseDoesNotExecuteSql ()35 public function testCreateDatabaseDoesNotExecuteSqlAndCreatesSqliteFile() 36 36 { 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')); 43 40 } 44 public function testDropDatabaseDoesNotExecuteSql ()41 public function testDropDatabaseDoesNotExecuteSqlAndDeletesSqliteFile() 45 42 { 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')); 52 46 } 53 47 public function testCreateTableSupportsAutoincPks() -
branches/0.9/tests/ManagerTestCase.php
r3071 r3787 66 66 // It expects only // since it thinks it is parsing a url 67 67 // 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'; 70 70 71 71 $manager = Doctrine_Manager::getInstance(); -
branches/0.9/tests/TreeStructureTestCase.php
r2353 r3787 104 104 $o4->save(); 105 105 106 $o1->Children;107 106 $this->assertFalse(isset($o1->Parent)); 107 $this->assertTrue(isset($o2->Parent)); 108 $this->assertTrue($o2->Parent === $o1); 109 $this->assertFalse(isset($o4->Parent)); 110 108 111 $this->assertTrue(count($o1->Children) == 2); 109 112 $this->assertTrue(count($o1->get('Children')) == 2); 110 113 111 $this->assertTrue(isset($o2->Parent));112 $this->assertTrue($o2->Parent === $o1);113 114 114 $this->assertTrue(count($o4->Children) == 0); 115 $this->assertFalse(isset($o4->Parent));116 115 } 117 116 public function testTreeStructureFetchingWorksWithDql() -
branches/0.9/tools/sandbox/config.php.dist
r2994 r3787 43 43 define('YAML_SCHEMA_PATH', SANDBOX_PATH . DIRECTORY_SEPARATOR . 'schema'); 44 44 define('DB_PATH', SANDBOX_PATH . DIRECTORY_SEPARATOR . 'sandbox.db'); 45 define('DSN', 'sqlite: ' . DB_PATH);45 define('DSN', 'sqlite:///' . DB_PATH); 46 46 47 47 require_once(DOCTRINE_PATH . DIRECTORY_SEPARATOR . 'Doctrine.php'); … … 49 49 spl_autoload_register(array('Doctrine', 'autoload')); 50 50 51 $pdo = new PDO(DSN); 52 Doctrine_Manager::connection($pdo, 'sandbox'); 51 Doctrine_Manager::connection(DSN, 'sandbox'); 52 53 Doctrine_Manager::getInstance()->setAttribute('model_loading', 'conservative');