Permalink
Browse files

[Generator] [Command|Manager] fixed regression introduced in #cd22336.

  • Loading branch information...
1 parent a24f5fe commit 0b5438a6c66f435ad28a316100270a618ed2e230 Hugo Hamon committed Aug 22, 2012
@@ -13,6 +13,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Finder\Finder;
+use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Propel\Generator\Exception\RuntimeException;
@@ -87,6 +88,17 @@ protected function getFilesystem()
return $this->filesystem;
}
+ protected function createDirectory($directory)
+ {
+ $filesystem = $this->getFilesystem();
+
+ try {
+ $filesystem->mkdir($directory);
+ } catch (IOException $e) {
+ throw new \RuntimeException(sprintf('Unable to write the "%s" directory', $directory), 0, $e);
+ }
+ }
+
protected function parseConnection($connection)
{
$pos = strpos($connection, '=');
@@ -49,10 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new \RuntimeException(sprintf('Unable to find the "%s" configuration file', $inputFilePath));
}
- $filesystem = $this->getFilesystem();
- if (!$filesystem->mkdir($input->getOption('output-dir'))) {
- throw new \RuntimeException(sprintf('Unable to write the "%s" output directory', $input->getOption('output-dir')));
- };
+ $this->createDirectory($input->getOption('output-dir'));
$outputFilePath = $input->getOption('output-dir') . DIRECTORY_SEPARATOR .$input->getOption('output-file');
if (!is_writable(dirname($outputFilePath))) {
@@ -60,8 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.reverse.parser.class' => sprintf('\\Propel\\Generator\\Reverse\\%sSchemaParser', $vendor),
));
- $filesystem = $this->getFilesystem();
- $filesystem->mkdir($input->getOption('output-dir'));
+ $this->createDirectory($input->getOption('output-dir'));
$manager = new ReverseManager();
$manager->setGeneratorConfig($generatorConfig);
@@ -48,8 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.packageObjectModel' => true,
));
- $filesystem = $this->getFilesystem();
- $filesystem->mkdir($input->getOption('output-dir'));
+ $this->createDirectory($input->getOption('output-dir'));
$manager = new GraphvizManager();
$manager->setGeneratorConfig($generatorConfig);
@@ -54,8 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'),
));
- $filesystem = $this->getFilesystem();
- $filesystem->mkdir($input->getOption('output-dir'));
+ $this->createDirectory($input->getOption('output-dir'));
$manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig);
@@ -51,8 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'),
));
- $filesystem = $this->getFilesystem();
- $filesystem->mkdir($input->getOption('output-dir'));
+ $this->createDirectory($input->getOption('output-dir'));
$manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig);
@@ -51,8 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'),
));
- $filesystem = $this->getFilesystem();
- $filesystem->mkdir($input->getOption('output-dir'));
+ $this->createDirectory($input->getOption('output-dir'));
$manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig);
@@ -51,8 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'),
));
- $filesystem = $this->getFilesystem();
- $filesystem->mkdir($input->getOption('output-dir'));
+ $this->createDirectory($input->getOption('output-dir'));
$manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig);
@@ -51,8 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.platform.class' => $input->getOption('platform'),
));
- $filesystem = $this->getFilesystem();
- $filesystem->mkdir($input->getOption('output-dir'));
+ $this->createDirectory($input->getOption('output-dir'));
$manager = new MigrationManager();
$manager->setGeneratorConfig($generatorConfig);
@@ -132,10 +132,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.mysql.tableEngineKeyword' => 'ENGINE',
), $this->getBuildProperties($input->getOption('input-dir') . '/build.properties')));
- $filesystem = $this->getFilesystem();
- $filesystem->mkdir($input->getOption('output-dir'));
+ $this->createDirectory($input->getOption('output-dir'));
$manager = new ModelManager();
+ $manager->setFilesystem($this->getFilesystem());
$manager->setGeneratorConfig($generatorConfig);
$manager->setSchemas($this->getSchemas($input->getOption('input-dir')));
$manager->setLoggerClosure(function($message) use ($input, $output) {
@@ -63,8 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'propel.mysql.tableEngineKeyword' => 'ENGINE',
), $this->getBuildProperties($input->getOption('input-dir') . '/build.properties')));
- $filesystem = $this->getFilesystem();
- $filesystem->mkdir($input->getOption('output-dir'));
+ $this->createDirectory($input->getOption('output-dir'));
$manager = new SqlManager();
$manager->setValidate($input->getOption('validate'));
@@ -10,8 +10,8 @@
namespace Propel\Generator\Manager;
+use Symfony\Component\Filesystem\Filesystem;
use Propel\Generator\Builder\Om\AbstractOMBuilder;
-use Propel\Generator\Util\Filesystem;
/**
* This manager creates the Object Model classes based on the XML schema file.
@@ -20,6 +20,13 @@
*/
class ModelManager extends AbstractManager
{
+ private $filesystem;
+
+ public function setFilesystem(Filesystem $filesystem)
+ {
+ $this->filesystem = $filesystem;
+ }
+
public function build()
{
$this->validate();
@@ -140,8 +147,7 @@ protected function doBuild(AbstractOMBuilder $builder, $overwrite = true)
$path = $builder->getClassFilePath();
$file = new \SplFileInfo($this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $path);
- $filesystem = new Filesystem();
- $filesystem->mkdir($file->getPath());
+ $this->filesystem->mkdir($file->getPath());
// skip files already created once
if ($file->isFile() && !$overwrite) {

0 comments on commit 0b5438a

Please sign in to comment.