diff --git a/src/Propel/Generator/Command/AbstractCommand.php b/src/Propel/Generator/Command/AbstractCommand.php index 5d688d90f8..2b18001a29 100644 --- a/src/Propel/Generator/Command/AbstractCommand.php +++ b/src/Propel/Generator/Command/AbstractCommand.php @@ -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, '='); diff --git a/src/Propel/Generator/Command/ConfigConvertXmlCommand.php b/src/Propel/Generator/Command/ConfigConvertXmlCommand.php index 644241ae6f..e581ed9c9d 100644 --- a/src/Propel/Generator/Command/ConfigConvertXmlCommand.php +++ b/src/Propel/Generator/Command/ConfigConvertXmlCommand.php @@ -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))) { diff --git a/src/Propel/Generator/Command/DatabaseReverseCommand.php b/src/Propel/Generator/Command/DatabaseReverseCommand.php index 529c9b70de..28c215ef94 100644 --- a/src/Propel/Generator/Command/DatabaseReverseCommand.php +++ b/src/Propel/Generator/Command/DatabaseReverseCommand.php @@ -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); diff --git a/src/Propel/Generator/Command/GraphvizGenerateCommand.php b/src/Propel/Generator/Command/GraphvizGenerateCommand.php index f4f6148b05..d270535186 100644 --- a/src/Propel/Generator/Command/GraphvizGenerateCommand.php +++ b/src/Propel/Generator/Command/GraphvizGenerateCommand.php @@ -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); diff --git a/src/Propel/Generator/Command/MigrationDiffCommand.php b/src/Propel/Generator/Command/MigrationDiffCommand.php index de765b918a..5142555042 100644 --- a/src/Propel/Generator/Command/MigrationDiffCommand.php +++ b/src/Propel/Generator/Command/MigrationDiffCommand.php @@ -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); diff --git a/src/Propel/Generator/Command/MigrationDownCommand.php b/src/Propel/Generator/Command/MigrationDownCommand.php index e6735cde38..259775ce0f 100644 --- a/src/Propel/Generator/Command/MigrationDownCommand.php +++ b/src/Propel/Generator/Command/MigrationDownCommand.php @@ -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); diff --git a/src/Propel/Generator/Command/MigrationMigrateCommand.php b/src/Propel/Generator/Command/MigrationMigrateCommand.php index 0d572cc90f..ba061cc790 100644 --- a/src/Propel/Generator/Command/MigrationMigrateCommand.php +++ b/src/Propel/Generator/Command/MigrationMigrateCommand.php @@ -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); diff --git a/src/Propel/Generator/Command/MigrationStatusCommand.php b/src/Propel/Generator/Command/MigrationStatusCommand.php index 22b8c2f3d9..4a7ad94f90 100644 --- a/src/Propel/Generator/Command/MigrationStatusCommand.php +++ b/src/Propel/Generator/Command/MigrationStatusCommand.php @@ -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); diff --git a/src/Propel/Generator/Command/MigrationUpCommand.php b/src/Propel/Generator/Command/MigrationUpCommand.php index 67331306bd..8d8debca9d 100644 --- a/src/Propel/Generator/Command/MigrationUpCommand.php +++ b/src/Propel/Generator/Command/MigrationUpCommand.php @@ -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); diff --git a/src/Propel/Generator/Command/ModelBuildCommand.php b/src/Propel/Generator/Command/ModelBuildCommand.php index ae58638c05..ae2b7f74ea 100644 --- a/src/Propel/Generator/Command/ModelBuildCommand.php +++ b/src/Propel/Generator/Command/ModelBuildCommand.php @@ -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) { diff --git a/src/Propel/Generator/Command/SqlBuildCommand.php b/src/Propel/Generator/Command/SqlBuildCommand.php index 0d687da777..600be7cc27 100644 --- a/src/Propel/Generator/Command/SqlBuildCommand.php +++ b/src/Propel/Generator/Command/SqlBuildCommand.php @@ -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')); diff --git a/src/Propel/Generator/Manager/ModelManager.php b/src/Propel/Generator/Manager/ModelManager.php index 2e09fa7a30..0193d398f5 100644 --- a/src/Propel/Generator/Manager/ModelManager.php +++ b/src/Propel/Generator/Manager/ModelManager.php @@ -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) {