1
0
mirror of synced 2025-01-31 04:21:44 +03:00

[2.0] Bug fix for convert mapping to yaml and annotation directory iterating not being recursive

This commit is contained in:
jwage 2009-10-05 18:19:00 +00:00
parent d0bb8ab2e4
commit e4e1291b6a
4 changed files with 30 additions and 11 deletions

View File

@ -90,7 +90,7 @@ class ConvertMappingTask extends AbstractTask
$printer->writeln('You must include a value for all four options: --from, --to and --dest', 'ERROR'); $printer->writeln('You must include a value for all four options: --from, --to and --dest', 'ERROR');
return false; 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.'); $printer->writeln('You can only use the --extend argument when converting to annoations.');
return false; return false;
} }
@ -133,7 +133,12 @@ class ConvertMappingTask extends AbstractTask
{ {
throw new \InvalidArgumentException(sprintf('No schema mapping files found in "%s"', $path)); throw new \InvalidArgumentException(sprintf('No schema mapping files found in "%s"', $path));
} }
$info = pathinfo($files[0]); $contents = file_get_contents($files[0]);
return $info['extension']; if (preg_match("/class (.*)/", $contents)) {
return 'annotation';
} else {
$info = pathinfo($files[0]);
return $info['extension'];
}
} }
} }

View File

@ -142,12 +142,13 @@ class SchemaToolTask extends AbstractTask
$classes = array(); $classes = array();
if ($driver instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver) { 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(); $declared = get_declared_classes();
foreach ($iter as $item) { foreach ($iter as $item) {
$baseName = $item->getBaseName(); $info = pathinfo($item->getPathName());
if ($baseName[0] == '.') { if (! isset($info['extension']) || $info['extension'] != 'php') {
continue; continue;
} }
require_once $item->getPathName(); require_once $item->getPathName();

View File

@ -96,9 +96,14 @@ class ClassMetadataExporter
foreach ($this->_mappingDirectories as $d) { foreach ($this->_mappingDirectories as $d) {
list($dir, $driver) = $d; list($dir, $driver) = $d;
if ($driver == 'php') { if ($driver == 'php') {
$iter = new \FilesystemIterator($dir); $iter = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir),
\RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($iter as $item) { foreach ($iter as $item) {
$info = pathinfo($item->getPathName());
if (! isset($info['extension']) || $info['extension'] != 'php') {
continue;
}
include $item->getPathName(); include $item->getPathName();
$vars = get_defined_vars(); $vars = get_defined_vars();
foreach ($vars as $var) { foreach ($vars as $var) {
@ -111,12 +116,13 @@ class ClassMetadataExporter
$classes = array_values($classes); $classes = array_values($classes);
} else { } else {
if ($driver instanceof \Doctrine\ORM\Mapping\Driver\AnnotationDriver) { 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(); $declared = get_declared_classes();
foreach ($iter as $item) { foreach ($iter as $item) {
$baseName = $item->getBaseName(); $info = pathinfo($item->getPathName());
if ($baseName[0] == '.') { if (! isset($info['extension']) || $info['extension'] != 'php') {
continue; continue;
} }
require_once $item->getPathName(); require_once $item->getPathName();
@ -125,7 +131,7 @@ class ClassMetadataExporter
foreach ($declared as $className) { foreach ($declared as $className) {
if ( ! $driver->isTransient($className)) { if ( ! $driver->isTransient($className)) {
$metadata = new ClassMetadataInfo($className); $metadata = new ClassMetadata($className);
$driver->loadMetadataForClass($className, $metadata); $driver->loadMetadataForClass($className, $metadata);
$classes[] = $metadata; $classes[] = $metadata;
} }

View File

@ -27,6 +27,13 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo,
Doctrine\ORM\Mapping\OneToManyMapping, Doctrine\ORM\Mapping\OneToManyMapping,
Doctrine\ORM\Mapping\ManyToManyMapping; 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 * ClassMetadata exporter for Doctrine YAML mapping files
* *