Changeset 3889
- Timestamp:
- 02/23/08 21:43:57 (17 months ago)
- Location:
- branches/0.10
- Files:
-
- 2 removed
- 4 modified
- 1 copied
- 1 moved
-
lib/Doctrine/Import/Builder.php (modified) (26 diffs)
-
models/ModelLoadingTest/Aggressive (deleted)
-
models/ModelLoadingTest/Conservative (deleted)
-
tests/BaseTestCase.php (modified) (2 diffs)
-
tests/Import/BuilderTestCase.php (modified) (2 diffs)
-
tests/ModelLoadingTest (moved) (moved from branches/0.10/models/ModelLoadingTest)
-
tests/ModelLoadingTest/ModelLoadingTest (copied) (copied from branches/0.10/models/ModelLoadingTest)
-
tests/run.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.10/lib/Doctrine/Import/Builder.php
r3887 r3889 40 40 { 41 41 /** 42 * Path42 * _path 43 43 * 44 44 * the path where imported files are being generated … … 49 49 50 50 /** 51 * packagesPrefix51 * _packagesPrefix 52 52 * 53 53 * @var string … … 56 56 57 57 /** 58 * packagesPath58 * _packagesPath 59 59 * 60 60 * @var string … … 63 63 64 64 /** 65 * suffix65 * _suffix 66 66 * 67 67 * File suffix to use when writing class definitions … … 72 72 73 73 /** 74 * generateBaseClasses74 * _generateBaseClasses 75 75 * 76 76 * Bool true/false for whether or not to generate base classes … … 81 81 82 82 /** 83 * baseClassesDirectory 83 * _base 84 * 85 * Prefix to use for generated base classes 86 * 87 * @var string 88 */ 89 protected $_baseClassPrefix = 'Base'; 90 91 /** 92 * _baseClassesDirectory 84 93 * 85 94 * Directory to put the generate base classes in … … 90 99 91 100 /** 92 * baseClassName101 * _baseClassName 93 102 * 94 103 * @var string … … 97 106 98 107 /** 99 * tpl108 * _tpl 100 109 * 101 110 * Class template used for writing classes … … 123 132 public function setTargetPath($path) 124 133 { 125 if ( ! $this->_packagesPath) { 126 $this->setPackagesPath($path . DIRECTORY_SEPARATOR . 'packages'); 127 } 128 129 $this->_path = $path; 134 if ($path) { 135 if ( ! $this->_packagesPath) { 136 $this->setPackagesPath($path . DIRECTORY_SEPARATOR . 'packages'); 137 } 138 139 $this->_path = $path; 140 } 130 141 } 131 142 … … 149 160 public function setPackagesPath($packagesPath) 150 161 { 151 $this->_packagesPath = $packagesPath; 162 if ($packagesPath) { 163 $this->_packagesPath = $packagesPath; 164 } 152 165 } 153 166 … … 168 181 return $this->_generateBaseClasses; 169 182 } 170 183 184 /** 185 * setBaseClassPrefix 186 * 187 * @param string $prefix 188 * @return void 189 */ 190 public function setBaseClassPrefix($prefix) 191 { 192 $this->_baseClassPrefix = $prefix; 193 } 194 195 /** 196 * getBaseClassPrefix 197 * 198 * @return void 199 */ 200 public function getBaseClassPrefix() 201 { 202 return $this->_baseClassPrefix; 203 } 204 171 205 /** 172 206 * setBaseClassesDirectory … … 358 392 359 393 if (isset($relation['refClass'])) { 360 $a[] = '\'refClass\' => ' . var_export($relation['refClass'], true);394 $a[] = '\'refClass\' => ' . $this->varExport($relation['refClass']); 361 395 } 362 396 363 397 if (isset($relation['deferred']) && $relation['deferred']) { 364 $a[] = '\'default\' => ' . var_export($relation['deferred'], true);398 $a[] = '\'default\' => ' . $this->varExport($relation['deferred']); 365 399 } 366 400 367 401 if (isset($relation['local']) && $relation['local']) { 368 $a[] = '\'local\' => ' . var_export($relation['local'], true);402 $a[] = '\'local\' => ' . $this->varExport($relation['local']); 369 403 } 370 404 371 405 if (isset($relation['foreign']) && $relation['foreign']) { 372 $a[] = '\'foreign\' => ' . var_export($relation['foreign'], true);406 $a[] = '\'foreign\' => ' . $this->varExport($relation['foreign']); 373 407 } 374 408 375 409 if (isset($relation['onDelete']) && $relation['onDelete']) { 376 $a[] = '\'onDelete\' => ' . var_export($relation['onDelete'], true);410 $a[] = '\'onDelete\' => ' . $this->varExport($relation['onDelete']); 377 411 } 378 412 379 413 if (isset($relation['onUpdate']) && $relation['onUpdate']) { 380 $a[] = '\'onUpdate\' => ' . var_export($relation['onUpdate'], true);414 $a[] = '\'onUpdate\' => ' . $this->varExport($relation['onUpdate']); 381 415 } 382 416 383 417 if (isset($relation['equal']) && $relation['equal']) { 384 $a[] = '\'equal\' => ' . var_export($relation['equal'], true);418 $a[] = '\'equal\' => ' . $this->varExport($relation['equal']); 385 419 } 386 420 … … 446 480 447 481 if (is_array($options) && !empty($options)) { 448 $build .= ', ' . var_export($options, true);482 $build .= ', ' . $this->varExport($options); 449 483 } 450 484 … … 453 487 454 488 return $build; 489 } 490 491 /** 492 * varExport 493 * 494 * Special function for var_export() 495 * The normal code which is returned is malformed and does not follow Doctrine standards 496 * So we do some string replacing to clean it up 497 * 498 * @param string $var 499 * @return void 500 */ 501 public function varExport($var) 502 { 503 $export = var_export($var, true); 504 $export = str_replace("\n ", '', $export); 505 $export = str_replace('array ( ', 'array(', $export); 506 $export = str_replace(",\n", "", $export); 507 508 return $export; 455 509 } 456 510 … … 502 556 503 557 if (is_array($options) && !empty($options)) { 504 $optionsPhp = var_export($options, true);558 $optionsPhp = $this->varExport($options); 505 559 506 560 $build .= " \$this->loadTemplate('" . $name . "', " . $optionsPhp . ");\n"; … … 528 582 foreach ($actAs as $name => $options) { 529 583 if (is_array($options) && !empty($options)) { 530 $optionsPhp = var_export($options, true);584 $optionsPhp = $this->varExport($options); 531 585 532 586 $build .= " \$this->actAs('" . $name . "', " . $optionsPhp . ");\n"; … … 587 641 $build = ''; 588 642 foreach ($options as $name => $value) { 589 $build .= " \$this->option('$name', " . var_export($value, true) . ");\n";643 $build .= " \$this->option('$name', " . $this->varExport($value) . ");\n"; 590 644 } 591 645 … … 605 659 foreach ($indexes as $indexName => $definitions) { 606 660 $build .= "\n \$this->index('" . $indexName . "'"; 607 $build .= ', ' . var_export($definitions, true);661 $build .= ', ' . $this->varExport($definitions); 608 662 $build .= ');'; 609 663 } … … 665 719 throw new Doctrine_Import_Builder_Exception('Missing class name.'); 666 720 } 667 721 722 $definition['topLevelClassName'] = $definition['className']; 723 668 724 if ($this->generateBaseClasses()) { 669 725 $definition['is_package'] = (isset($definition['package']) && $definition['package']) ? true:false; … … 674 730 unset($e[0]); 675 731 676 $definition['package_path'] = implode(DIRECTORY_SEPARATOR, $e);732 $definition['package_path'] = ! empty($e) ? implode(DIRECTORY_SEPARATOR, $e):$definition['package_name']; 677 733 } 678 734 … … 701 757 $packageLevel['is_package_class'] = true; 702 758 unset($packageLevel['connection']); 759 760 $packageLevel['tableClassName'] = $packageLevel['className'] . 'Table'; 761 $packageLevel['inheritance']['tableExtends'] = isset($definition['inheritance']['extends']) ? $definition['inheritance']['extends'] . 'Table':'Doctrine_Table'; 762 763 $topLevel['tableClassName'] = $topLevel['topLevelClassName'] . 'Table'; 764 $topLevel['inheritance']['tableExtends'] = $packageLevel['className'] . 'Table'; 765 } else { 766 $topLevel['tableClassName'] = $topLevel['className'] . 'Table'; 767 $topLevel['inheritance']['tableExtends'] = isset($definition['inheritance']['extends']) ? $definition['inheritance']['extends'] . 'Table':'Doctrine_Table'; 703 768 } 704 769 … … 711 776 $this->writeDefinition($baseClass); 712 777 713 if ( !empty($packageLevel)) {778 if ( ! empty($packageLevel)) { 714 779 $this->writeDefinition($packageLevel); 715 780 } … … 718 783 } else { 719 784 $this->writeDefinition($definition); 785 } 786 } 787 788 /** 789 * writeTableDefinition 790 * 791 * @return void 792 */ 793 public function writeTableDefinition($className, $path, $options = array()) 794 { 795 $content = '<?php' . PHP_EOL; 796 $content .= sprintf(self::$_tpl, false, 797 $className, 798 isset($options['extends']) ? $options['extends']:'Doctrine_Table', 799 null, 800 null, 801 null 802 ); 803 804 Doctrine_Lib::makeDirectories($path); 805 806 $writePath = $path . DIRECTORY_SEPARATOR . $className . $this->_suffix; 807 808 if ( ! file_exists($writePath)) { 809 file_put_contents($writePath, $content); 720 810 } 721 811 } … … 750 840 $writePath = $this->_path; 751 841 } 752 } 753 842 843 $this->writeTableDefinition($definition['tableClassName'], $writePath, array('extends' => $definition['inheritance']['tableExtends'])); 844 } 754 845 // If is the package class then we need to make the path to the complete package 755 if (isset($definition['is_package_class']) && $definition['is_package_class']) { 756 $path = str_replace('.', DIRECTORY_SEPARATOR, trim($definition['package'])); 757 758 $writePath = $packagesPath . DIRECTORY_SEPARATOR . $path; 759 } 760 846 else if (isset($definition['is_package_class']) && $definition['is_package_class']) { 847 $writePath = $packagesPath . DIRECTORY_SEPARATOR . $definition['package_path']; 848 849 $this->writeTableDefinition($definition['tableClassName'], $writePath, array('extends' => $definition['inheritance']['tableExtends'])); 850 } 761 851 // If it is the base class of the doctrine record definition 762 if (isset($definition['is_base_class']) && $definition['is_base_class']) {852 else if (isset($definition['is_base_class']) && $definition['is_base_class']) { 763 853 // If it is a part of a package then we need to put it in a package subfolder 764 854 if (isset($definition['is_package']) && $definition['is_package']) { 765 $writePath = $this->_path . DIRECTORY_SEPARATOR . $definition['package_name'] . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory; 855 $basePath = $this->_path . DIRECTORY_SEPARATOR . $definition['package_name']; 856 $writePath = $basePath . DIRECTORY_SEPARATOR . $this->_baseClassesDirectory; 766 857 // Otherwise lets just put it in the root generated folder 767 858 } else { … … 770 861 } 771 862 863 // If we have a writePath from the if else conditionals above then use it 772 864 if (isset($writePath)) { 773 865 Doctrine_Lib::makeDirectories($writePath); 774 866 775 867 $writePath .= DIRECTORY_SEPARATOR . $fileName; 868 // Otherwise none of the conditions were met and we aren't generating base classes 776 869 } else { 777 870 Doctrine_Lib::makeDirectories($this->_path); 778 871 779 872 $writePath = $this->_path . DIRECTORY_SEPARATOR . $fileName; 780 873 } … … 789 882 $code .= PHP_EOL . $definitionCode; 790 883 884 $bytes = file_put_contents($writePath, $code); 885 return; 886 791 887 if (isset($definition['generate_once']) && $definition['generate_once'] === true) { 792 888 if ( ! file_exists($writePath)) { -
branches/0.10/tests/BaseTestCase.php
r3888 r3889 35 35 public function testAggressiveModelLoading() 36 36 { 37 $path = realpath(' ../models/ModelLoadingTest/Aggressive');37 $path = realpath('ModelLoadingTest/Aggressive'); 38 38 39 39 $models = Doctrine::loadModels($path, Doctrine::MODEL_LOADING_AGGRESSIVE); … … 55 55 public function testConservativeModelLoading() 56 56 { 57 $path = realpath(' ../models/ModelLoadingTest/Conservative');57 $path = realpath('ModelLoadingTest/Conservative'); 58 58 59 59 $models = Doctrine::loadModels($path, Doctrine::MODEL_LOADING_CONSERVATIVE); -
branches/0.10/tests/Import/BuilderTestCase.php
r3888 r3889 46 46 $schemaTestInheritanceChild2 = new ReflectionClass('SchemaTestInheritanceChild2'); 47 47 48 /*49 48 $schemaTestInheritanceParentTable = new ReflectionClass('SchemaTestInheritanceParentTable'); 50 49 $schemaTestInheritanceChild1Table = new ReflectionClass('SchemaTestInheritanceChild1Table'); 51 50 $schemaTestInheritanceChild2Table = new ReflectionClass('SchemaTestInheritanceChild2Table'); 52 */53 51 52 $this->assertTrue($schemaTestInheritanceParent->isSubClassOf('Doctrine_Record')); 54 53 $this->assertTrue($schemaTestInheritanceParent->isSubClassOf('BaseSchemaTestInheritanceParent')); 54 $this->assertTrue($schemaTestInheritanceParent->isSubClassOf('PackageSchemaTestInheritanceParent')); 55 55 $this->assertTrue($schemaTestInheritanceChild1->isSubClassOf('BaseSchemaTestInheritanceChild1')); 56 56 $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('BaseSchemaTestInheritanceChild2')); … … 63 63 $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('SchemaTestInheritanceChild1')); 64 64 $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('BaseSchemaTestInheritanceChild1')); 65 $this->assertTrue($schemaTestInheritanceChild2->isSubClassOf('PackageSchemaTestInheritanceParent')); 65 66 66 /*67 67 $this->assertTrue($schemaTestInheritanceParentTable->isSubClassOf('Doctrine_Table')); 68 68 $this->assertTrue($schemaTestInheritanceChild1Table->isSubClassOf('SchemaTestInheritanceParentTable')); 69 69 $this->assertTrue($schemaTestInheritanceChild1Table->isSubClassOf('PackageSchemaTestInheritanceParentTable')); 70 */ 71 70 71 $this->assertTrue($schemaTestInheritanceChild2Table->isSubClassOf('SchemaTestInheritanceParentTable')); 72 $this->assertTrue($schemaTestInheritanceChild2Table->isSubClassOf('PackageSchemaTestInheritanceParentTable')); 73 $this->assertTrue($schemaTestInheritanceChild2Table->isSubClassOf('SchemaTestInheritanceChild1Table')); 74 $this->assertTrue($schemaTestInheritanceChild2Table->isSubClassOf('PackageSchemaTestInheritanceChild1Table')); 75 72 76 Doctrine_Lib::removeDirectories($path); 73 77 } -
branches/0.10/tests/run.php
r3888 r3889 90 90 $export->addTestCase(new Doctrine_Export_Mysql_TestCase()); 91 91 $export->addTestCase(new Doctrine_Export_Sqlite_TestCase()); 92 $export->addTestCase(new Doctrine_Export_Schema_TestCase()); 92 93 $test->addTestCase($export); 93 94 … … 104 105 $import->addTestCase(new Doctrine_Import_Oracle_TestCase()); 105 106 $import->addTestCase(new Doctrine_Import_Sqlite_TestCase()); 107 $import->addTestCase(new Doctrine_Import_Builder_TestCase()); 108 $import->addTestCase(new Doctrine_Import_Schema_TestCase()); 106 109 $test->addTestCase($import); 107 110 … … 228 231 $record->addTestCase(new Doctrine_Record_Inheritance_TestCase()); 229 232 $record->addTestCase(new Doctrine_Record_Synchronize_TestCase()); 230 $record->addTestCase(new Doctrine_Import_Builder_TestCase());231 233 $test->addTestCase($record); 232 234 … … 279 281 $test->addTestCase($parser); 280 282 281 $schemaFiles = new GroupTest('Schema files', 'schema_files');282 $schemaFiles->addTestCase(new Doctrine_Import_Schema_TestCase());283 $schemaFiles->addTestCase(new Doctrine_Export_Schema_TestCase());284 $test->addTestCase($schemaFiles);285 286 283 $data = new GroupTest('Data exporting/importing fixtures', 'data_fixtures'); 287 284 $data->addTestCase(new Doctrine_Data_Import_TestCase());