From e4e1291b6afa46369a1bbc261d041a2efed8b927 Mon Sep 17 00:00:00 2001 From: jwage Date: Mon, 5 Oct 2009 18:19:00 +0000 Subject: [PATCH] [2.0] Bug fix for convert mapping to yaml and annotation directory iterating not being recursive --- .../ORM/Tools/Cli/Tasks/ConvertMappingTask.php | 11 ++++++++--- .../ORM/Tools/Cli/Tasks/SchemaToolTask.php | 7 ++++--- .../ORM/Tools/Export/ClassMetadataExporter.php | 16 +++++++++++----- .../ORM/Tools/Export/Driver/YamlExporter.php | 7 +++++++ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Cli/Tasks/ConvertMappingTask.php b/lib/Doctrine/ORM/Tools/Cli/Tasks/ConvertMappingTask.php index ee9c1ac66..a695ef10f 100644 --- a/lib/Doctrine/ORM/Tools/Cli/Tasks/ConvertMappingTask.php +++ b/lib/Doctrine/ORM/Tools/Cli/Tasks/ConvertMappingTask.php @@ -90,7 +90,7 @@ class ConvertMappingTask extends AbstractTask $printer->writeln('You must include a value for all four options: --from, --to and --dest', 'ERROR'); return false; } - if ($args['to'] != 'annotation' && $args['extend']) { + if ($args['to'] != 'annotation' && isset($args['extend'])) { $printer->writeln('You can only use the --extend argument when converting to annoations.'); return false; } @@ -133,7 +133,12 @@ class ConvertMappingTask extends AbstractTask { throw new \InvalidArgumentException(sprintf('No schema mapping files found in "%s"', $path)); } - $info = pathinfo($files[0]); - return $info['extension']; + $contents = file_get_contents($files[0]); + if (preg_match("/class (.*)/", $contents)) { + return 'annotation'; + } else { + $info = pathinfo($files[0]); + return $info['extension']; + } } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php b/lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php index ddab5f68a..8f6929ecb 100644 --- a/lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php +++ b/lib/Doctrine/ORM/Tools/Cli/Tasks/SchemaToolTask.php @@ -142,12 +142,13 @@ class SchemaToolTask extends AbstractTask $classes = array(); if ($driver instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver) { - $iter = new \FilesystemIterator($args['classdir']); + $iter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($args['classdir']), + \RecursiveIteratorIterator::LEAVES_ONLY); $declared = get_declared_classes(); foreach ($iter as $item) { - $baseName = $item->getBaseName(); - if ($baseName[0] == '.') { + $info = pathinfo($item->getPathName()); + if (! isset($info['extension']) || $info['extension'] != 'php') { continue; } require_once $item->getPathName(); diff --git a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php index d1c5cf714..a6cf38602 100644 --- a/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/ClassMetadataExporter.php @@ -96,9 +96,14 @@ class ClassMetadataExporter foreach ($this->_mappingDirectories as $d) { list($dir, $driver) = $d; if ($driver == 'php') { - $iter = new \FilesystemIterator($dir); + $iter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), + \RecursiveIteratorIterator::LEAVES_ONLY); foreach ($iter as $item) { + $info = pathinfo($item->getPathName()); + if (! isset($info['extension']) || $info['extension'] != 'php') { + continue; + } include $item->getPathName(); $vars = get_defined_vars(); foreach ($vars as $var) { @@ -111,12 +116,13 @@ class ClassMetadataExporter $classes = array_values($classes); } else { if ($driver instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver) { - $iter = new \FilesystemIterator($dir); + $iter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), + \RecursiveIteratorIterator::LEAVES_ONLY); $declared = get_declared_classes(); foreach ($iter as $item) { - $baseName = $item->getBaseName(); - if ($baseName[0] == '.') { + $info = pathinfo($item->getPathName()); + if (! isset($info['extension']) || $info['extension'] != 'php') { continue; } require_once $item->getPathName(); @@ -125,7 +131,7 @@ class ClassMetadataExporter foreach ($declared as $className) { if ( ! $driver->isTransient($className)) { - $metadata = new ClassMetadataInfo($className); + $metadata = new ClassMetadata($className); $driver->loadMetadataForClass($className, $metadata); $classes[] = $metadata; } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php index c0519efd2..3b9a6bdc8 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/YamlExporter.php @@ -27,6 +27,13 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo, Doctrine\ORM\Mapping\OneToManyMapping, Doctrine\ORM\Mapping\ManyToManyMapping; +if ( ! class_exists('sfYaml', false)) { + require_once __DIR__ . '/../../../../../vendor/sfYaml/sfYaml.class.php'; + require_once __DIR__ . '/../../../../../vendor/sfYaml/sfYamlDumper.class.php'; + require_once __DIR__ . '/../../../../../vendor/sfYaml/sfYamlInline.class.php'; + require_once __DIR__ . '/../../../../../vendor/sfYaml/sfYamlParser.class.php'; +} + /** * ClassMetadata exporter for Doctrine YAML mapping files *