Changeset 2943 for trunk/lib/Doctrine.php
- Timestamp:
- 10/20/07 03:30:15 (15 months ago)
- Files:
-
- 1 modified
-
trunk/lib/Doctrine.php (modified) (51 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Doctrine.php
r2942 r2943 116 116 const PARAM_STMT = 4; 117 117 const PARAM_STR = 2; 118 118 119 /** 119 120 * ATTRIBUTE CONSTANTS … … 181 182 const ATTR_THROW_EXCEPTIONS = 155; 182 183 183 184 184 /** 185 185 * LIMIT CONSTANTS … … 190 190 */ 191 191 const LIMIT_ROWS = 1; 192 192 193 193 /** 194 194 * constant for record limiting … … 205 205 */ 206 206 const FETCH_IMMEDIATE = 0; 207 207 208 208 /** 209 209 * BATCH FETCHING … … 211 211 */ 212 212 const FETCH_BATCH = 1; 213 213 214 214 /** 215 215 * LAZY FETCHING … … 217 217 */ 218 218 const FETCH_OFFSET = 3; 219 219 220 220 /** 221 221 * LAZY OFFSET FETCHING … … 233 233 */ 234 234 const FETCH_VHOLDER = 1; 235 235 236 236 /** 237 237 * FETCH RECORD … … 243 243 */ 244 244 const FETCH_RECORD = 2; 245 245 246 246 /** 247 247 * FETCH ARRAY 248 248 */ 249 249 const FETCH_ARRAY = 3; 250 250 251 251 /** 252 252 * PORTABILITY CONSTANTS … … 258 258 */ 259 259 const PORTABILITY_NONE = 0; 260 260 261 261 /** 262 262 * Portability: convert names of tables and fields to case defined in the … … 271 271 */ 272 272 const PORTABILITY_RTRIM = 2; 273 273 274 274 /** 275 275 * Portability: force reporting the number of rows deleted. … … 277 277 */ 278 278 const PORTABILITY_DELETE_COUNT = 4; 279 279 280 280 /** 281 281 * Portability: convert empty values to null strings in data output by … … 284 284 */ 285 285 const PORTABILITY_EMPTY_TO_NULL = 8; 286 286 287 287 /** 288 288 * Portability: removes database/table qualifiers from associative indexes … … 290 290 */ 291 291 const PORTABILITY_FIX_ASSOC_FIELD_NAMES = 16; 292 292 293 293 /** 294 294 * Portability: makes Doctrine_Expression throw exception for unportable RDBMS expressions … … 296 296 */ 297 297 const PORTABILITY_EXPR = 32; 298 298 299 299 /** 300 300 * Portability: turn on all portability features. … … 311 311 */ 312 312 const LOCK_OPTIMISTIC = 0; 313 313 314 314 /** 315 315 * mode for pessimistic locking 316 316 */ 317 317 const LOCK_PESSIMISTIC = 1; 318 318 319 319 /** 320 320 * EXPORT CONSTANTS … … 322 322 323 323 /** 324 * turns of exporting324 * EXPORT_NONE 325 325 */ 326 326 const EXPORT_NONE = 0; 327 328 /** 329 * export tables327 328 /** 329 * EXPORT_TABLES 330 330 */ 331 331 const EXPORT_TABLES = 1; 332 333 /** 334 * export constraints332 333 /** 334 * EXPORT_CONSTRAINTS 335 335 */ 336 336 const EXPORT_CONSTRAINTS = 2; 337 338 /** 339 * export plugins337 338 /** 339 * EXPORT_PLUGINS 340 340 */ 341 341 const EXPORT_PLUGINS = 4; 342 343 /** 344 * export all342 343 /** 344 * EXPORT_ALL 345 345 */ 346 346 const EXPORT_ALL = 7; 347 347 348 348 /** 349 349 * HYDRATION CONSTANTS … … 351 351 const HYDRATE_RECORD = 2; 352 352 353 /** 354 * HYDRATE_ARRAY 355 */ 353 356 const HYDRATE_ARRAY = 3; 354 357 … … 358 361 const VALIDATE_NONE = 0; 359 362 363 /** 364 * VALIDATE_LENGTHS 365 */ 360 366 const VALIDATE_LENGTHS = 1; 361 367 368 /** 369 * VALIDATE_TYPES 370 */ 362 371 const VALIDATE_TYPES = 2; 363 372 373 /** 374 * VALIDATE_CONSTRAINTS 375 */ 364 376 const VALIDATE_CONSTRAINTS = 4; 365 377 378 /** 379 * VALIDATE_ALL 380 */ 366 381 const VALIDATE_ALL = 7; 367 382 368 383 /** 384 * IDENTIFIER_AUTOINC 385 * 369 386 * constant for auto_increment identifier 370 387 */ 371 388 const IDENTIFIER_AUTOINC = 1; 372 373 /** 389 390 /** 391 * IDENTIFIER_SEQUENCE 392 * 374 393 * constant for sequence identifier 375 394 */ 376 395 const IDENTIFIER_SEQUENCE = 2; 377 378 /** 396 397 /** 398 * IDENTIFIER_NATURAL 399 * 379 400 * constant for normal identifier 380 401 */ 381 402 const IDENTIFIER_NATURAL = 3; 382 383 /** 403 404 /** 405 * IDENTIFIER_COMPOSITE 406 * 384 407 * constant for composite identifier 385 408 */ 386 409 const IDENTIFIER_COMPOSITE = 4; 387 388 /** 410 411 /** 412 * Path 413 * 389 414 * @var string $path doctrine root directory 390 415 */ 391 416 private static $_path; 392 393 /** 417 418 /** 419 * Debug 420 * 421 * Bool true/false 422 * 394 423 * @var boolean $_debug 395 424 */ 396 425 private static $_debug = false; 397 426 398 427 /** 399 428 * __construct … … 406 435 throw new Doctrine_Exception('Doctrine is static class. No instances can be created.'); 407 436 } 408 437 409 438 /** 410 439 * debug … … 421 450 return self::$_debug; 422 451 } 423 452 424 453 /** 425 454 * getPath … … 436 465 return self::$_path; 437 466 } 438 467 439 468 /** 440 469 * loadAll … … 447 476 return self::loadAllRuntimeClasses(); 448 477 } 449 478 450 479 /** 451 480 * importSchema … … 460 489 return self::generateModelsFromDb($directory, $databases); 461 490 } 462 491 463 492 /** 464 493 * exportSchema … … 472 501 return self::createTablesFromModels($directory); 473 502 } 474 503 475 504 /** 476 505 * exportSql … … 483 512 return self::generateSqlFromModels($directory); 484 513 } 485 514 486 515 /** 487 516 * loadAllRuntimeClasses … … 499 528 } 500 529 } 501 530 502 531 /** 503 532 * loadModels … … 506 535 * 507 536 * @param string $directory Path to directory of models or array of directory paths 508 * @return void537 * @return array $loadedModels 509 538 */ 510 539 public static function loadModels($directory) … … 530 559 return self::getLoadedModels($declared); 531 560 } 532 561 533 562 /** 534 563 * getLoadedModels … … 536 565 * Get all the loaded models, you can provide an array of classes or it will use get_declared_classes() 537 566 * 567 * Will filter through an array of classes and return the Doctrine_Records out of them. 568 * If you do not specify $classes it will return all of the currently loaded Doctrine_Records 569 * 538 570 * @param $classes Array of classes to filter through, otherwise uses get_declared_classes() 539 * @return void571 * @return array $loadedModels 540 572 */ 541 573 public static function getLoadedModels($classes = null) … … 549 581 $loadedModels = array(); 550 582 551 // we iterate trhough the diff of previously declared classes 552 // and currently declared classes 553 foreach ($classes as $name) { 583 foreach ((array) $classes as $name) { 554 584 $class = new ReflectionClass($name); 555 585 … … 569 599 return $loadedModels; 570 600 } 571 601 572 602 /** 573 603 * getConnectionByTableName … … 576 606 * 577 607 * @param string $tableName 578 * @return void608 * @return object Doctrine_Connection 579 609 */ 580 610 public static function getConnectionByTableName($tableName) … … 593 623 return Doctrine_Manager::connection(); 594 624 } 595 625 596 626 /** 597 627 * generateModelsFromDb … … 602 632 * @param array $databases Array of databases to generate models for 603 633 * @return boolean 634 * @throws Exception 604 635 */ 605 636 public static function generateModelsFromDb($directory, array $databases = array()) … … 607 638 return Doctrine_Manager::connection()->import->importSchema($directory, $databases); 608 639 } 609 640 610 641 /** 611 642 * generateYamlFromDb … … 631 662 return $result; 632 663 } 664 633 665 /** 634 666 * generateModelsFromYaml … … 647 679 return $import->importSchema($yamlPath, 'yml', $directory); 648 680 } 649 681 650 682 /** 651 683 * createTablesFromModels … … 660 692 return Doctrine_Manager::connection()->export->exportSchema($directory); 661 693 } 662 694 663 695 /** 664 696 * generateSqlFromModels 665 697 * 666 698 * @param string $directory 667 * @return void699 * @return string $build String of sql queries. One query per line 668 700 */ 669 701 public static function generateSqlFromModels($directory = null) … … 694 726 return $export->exportSchema($yamlPath, 'yml', $directory); 695 727 } 696 728 697 729 /** 698 730 * createDatabases … … 719 751 } 720 752 } 721 753 722 754 /** 723 755 * dropDatabases … … 744 776 } 745 777 } 746 778 747 779 /** 748 780 * dumpData … … 760 792 return $data->exportData($yamlPath, 'yml', array(), $individualFiles); 761 793 } 762 794 763 795 /** 764 796 * loadData … … 773 805 public static function loadData($yamlPath, $append = false) 774 806 { 775 $delete = isset($append) ? ($append ? false : true) : true;776 777 if ($delete)778 {779 $models = Doctrine::getLoadedModels();780 781 foreach ($models as $model)782 {783 $model = new $model();784 785 $model->getTable()->createQuery()->delete($model)->execute();786 }787 }788 789 807 $data = new Doctrine_Data(); 790 808 809 if (!$append) { 810 $data->purge(); 811 } 812 791 813 return $data->importData($yamlPath, 'yml'); 792 814 } 793 815 794 816 /** 795 817 * loadDummyData … … 803 825 public static function loadDummyData($append, $num = 5) 804 826 { 805 $delete = isset($append) ? ($append ? false : true) : true;806 807 if ($delete)808 {809 $models = Doctrine::getLoadedModels();810 811 foreach ($models as $model)812 {813 $model = new $model();814 815 $model->getTable()->createQuery()->delete($model)->execute();816 }817 }818 819 827 $data = new Doctrine_Data(); 828 829 if (!$append) { 830 $data->purge(); 831 } 820 832 821 833 return $data->importDummyData($num); … … 829 841 * @param string $migrationsPath Path to migrations directory which contains your migration classes 830 842 * @param string $to Version you wish to migrate to. 831 * @return void 843 * @return bool true 844 * @throws new Doctrine_Migration_Exception 832 845 */ 833 846 public static function migrate($migrationsPath, $to = null) … … 837 850 return $migration->migrate($to); 838 851 } 839 852 840 853 /** 841 854 * generateMigrationClass … … 845 858 * @param string $className Name of the Migration class to generate 846 859 * @param string $migrationsPath Path to directory which contains your migration classes 847 * @package default848 860 */ 849 861 public static function generateMigrationClass($className, $migrationsPath) … … 853 865 return $builder->generateMigrationClass($className); 854 866 } 855 867 856 868 /** 857 869 * generateMigrationsFromDb … … 859 871 * @param string $migrationsPath 860 872 * @return void 873 * @throws new Doctrine_Migration_Exception 861 874 */ 862 875 public static function generateMigrationsFromDb($migrationsPath) … … 866 879 return $builder->generateMigrationsFromDb(); 867 880 } 868 881 869 882 /** 870 883 * generateMigrationsFromModels … … 902 915 { 903 916 return Doctrine_Manager::connection($adapter, $name); 917 } 918 919 /** 920 * fileFinder 921 * 922 * @param string $type 923 * @return void 924 */ 925 public static function fileFinder($type) 926 { 927 return Doctrine_FileFinder::type($type); 904 928 } 905 929