forked from propelorm/Propel2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a `Filesystem` class (thanks to Symfony2), added `Finder` (Symfony2 component) as a dependency, added a bunch of new named exceptions
- Loading branch information
1 parent
476c9c2
commit b141fdd
Showing
13 changed files
with
826 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Propel package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Propel\Generator\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Output\Output; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
use Propel\Generator\Config\GeneratorConfig; | ||
use Propel\Generator\Manager\SqlManager; | ||
use Propel\Generator\Util\Filesystem; | ||
|
||
/** | ||
* @author William Durand <william.durand1@gmail.com> | ||
*/ | ||
class SqlBuild extends Command | ||
{ | ||
const DEFAULT_INPUT_DIRECTORY = '.'; | ||
|
||
const DEFAULT_OUTPUT_DIRECTORY = 'generated-sql'; | ||
|
||
const DEFAULT_PLATFORM = 'MysqlPlatform'; | ||
|
||
/** | ||
* @var \Symfony\Component\Console\Output\OutputInterface | ||
*/ | ||
private $output; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setDefinition(array( | ||
new InputOption('input-dir', null, InputOption::VALUE_REQUIRED, 'The input directory', self::DEFAULT_INPUT_DIRECTORY), | ||
new InputOption('output-dir', null, InputOption::VALUE_REQUIRED, 'The output directory', self::DEFAULT_OUTPUT_DIRECTORY), | ||
new InputOption('platform', null, InputOption::VALUE_REQUIRED, 'The platform', self::DEFAULT_PLATFORM), | ||
new InputOption('validate', null, InputOption::VALUE_NONE, '') | ||
)) | ||
->setName('sql:build') | ||
->setDescription('Build SQL files') | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$manager = new SqlManager(); | ||
|
||
$buildProperties = realpath($input->getOption('input-dir') . DIRECTORY_SEPARATOR . 'build.properties'); | ||
$defaultProperties = realpath(__DIR__.'/../../../../tools/generator/default.properties'); | ||
|
||
$generatorConfig = new GeneratorConfig(array_merge( | ||
$this->getBuildProperties($defaultProperties), | ||
$this->getBuildProperties($buildProperties), | ||
array( | ||
'propel.platform.class' => $input->getOption('platform'), | ||
) | ||
)); | ||
|
||
$finder = new Finder(); | ||
$files = $finder | ||
->name('*schema.xml') | ||
->in($input->getOption('input-dir')) | ||
->depth(0) | ||
->files() | ||
; | ||
|
||
$filesystem = new Filesystem(); | ||
$filesystem->mkdir($input->getOption('output-dir')); | ||
|
||
$manager->setValidate($input->getOption('validate')); | ||
$manager->setGeneratorConfig($generatorConfig); | ||
$manager->setIncludedFiles($files); | ||
$manager->setLoggerClosure(function($message) use ($output) { | ||
$output->writeln($message); | ||
}); | ||
$manager->setWorkingDirectory($input->getOption('output-dir')); | ||
|
||
$manager->buildSql(); | ||
} | ||
|
||
protected function getBuildProperties($file) | ||
{ | ||
$properties = array(); | ||
|
||
if (false === $lines = @file($file)) { | ||
throw new \Exception(sprintf('Unable to parse contents of "%s".', $file)); | ||
} | ||
|
||
foreach ($lines as $line) { | ||
$line = trim($line); | ||
|
||
if ('' == $line || in_array($line[0], array('#', ';'))) { | ||
continue; | ||
} | ||
|
||
$pos = strpos($line, '='); | ||
$properties[trim(substr($line, 0, $pos))] = trim(substr($line, $pos + 1)); | ||
} | ||
|
||
return $properties; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Propel package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Propel\Generator\Exception; | ||
|
||
class BuildException extends RuntimeException implements ExceptionInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Propel package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Propel\Generator\Exception; | ||
|
||
/** | ||
* @author William Durand <william.durand1@gmail.com> | ||
*/ | ||
interface ExceptionInterface | ||
{ | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Propel/Generator/Exception/InvalidArgumentException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Propel package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Propel\Generator\Exception; | ||
|
||
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Propel package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Propel\Generator\Exception; | ||
|
||
class RuntimeException extends \RuntimeException implements ExceptionInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.