Permalink
Browse files

Merge pull request #100 from willdurand/console

Introducing new commands
  • Loading branch information...
2 parents 476c9c2 + ff0e679 commit 4bd3d5e8c8b053f78e297e2e7a4788595f58f976 @willdurand willdurand committed Dec 22, 2011
Showing with 1,258 additions and 502 deletions.
  1. +17 −3 bin/propel.php
  2. +2 −1 composer.json
  3. +1 −1 composer.lock
  4. +1 −1 src/Propel/Generator/Behavior/{ → AlternativeCodingStandards}/AlternativeCodingStandardsBehavior.php
  5. +1 −1 src/Propel/Generator/Behavior/{ → AutoAddPk}/AutoAddPkBehavior.php
  6. +1 −1 src/Propel/Generator/Behavior/{ → Delegate}/DelegateBehavior.php
  7. +1 −1 src/Propel/Generator/Behavior/{ → QueryCache}/QueryCacheBehavior.php
  8. +1 −1 src/Propel/Generator/Behavior/{ → Sluggable}/SluggableBehavior.php
  9. +1 −1 src/Propel/Generator/Behavior/{ → Timestampable}/TimestampableBehavior.php
  10. +76 −0 src/Propel/Generator/Command/AbstractCommand.php
  11. +146 −0 src/Propel/Generator/Command/ModelBuild.php
  12. +81 −0 src/Propel/Generator/Command/SqlBuild.php
  13. +28 −4 src/Propel/Generator/Command/TestPrepare.php
  14. +6 −9 src/Propel/Generator/Config/GeneratorConfig.php
  15. +18 −0 src/Propel/Generator/Exception/BehaviorNotFoundException.php
  16. +15 −0 src/Propel/Generator/Exception/BuildException.php
  17. +18 −0 src/Propel/Generator/Exception/ClassNotFoundException.php
  18. +18 −0 src/Propel/Generator/Exception/ExceptionInterface.php
  19. +15 −0 src/Propel/Generator/Exception/InvalidArgumentException.php
  20. +15 −0 src/Propel/Generator/Exception/RuntimeException.php
  21. +1 −2 src/Propel/Generator/Exception/SchemaException.php
  22. +414 −0 src/Propel/Generator/Manager/AbstractManager.php
  23. +62 −112 src/Propel/Generator/{Task/PropelOMTask.php → Manager/ModelManager.php}
  24. +5 −92 src/Propel/Generator/{Util → Manager}/SqlManager.php
  25. +15 −10 src/Propel/Generator/Model/XmlElement.php
  26. +0 −9 src/Propel/Generator/Task/PropelOMTaskCompat.php
  27. +0 −34 src/Propel/Generator/Task/PropelSqlBuildTask.php
  28. +0 −9 src/Propel/Generator/Task/PropelSqlBuildTaskCompat.php
  29. +275 −0 src/Propel/Generator/Util/Filesystem.php
  30. +1 −1 tests/Fixtures/bookstore/behavior-add-class-schema.xml
  31. +2 −2 tests/Fixtures/bookstore/behavior-schema.xml
  32. +0 −5 tests/Fixtures/bookstore/build.properties.dist
  33. +1 −1 tests/Propel/Tests/Generator/Behavior/{ → AddClass}/AddClassBehaviorTest.php
  34. +2 −2 ...sts/Generator/Behavior/{ → AlternativeCodingStandards}/AlternativeCodingStandardsBehaviorTest.php
  35. +1 −1 tests/Propel/Tests/Generator/Behavior/{ → AutoAddPk}/AutoAddPkBehaviorTest.php
  36. +2 −2 tests/Propel/Tests/Generator/Behavior/{ → Delegate}/DelegateBehaviorTest.php
  37. +1 −1 tests/Propel/Tests/Generator/Behavior/{ → Sluggable}/SluggableBehaviorTest.php
  38. +5 −5 tests/Propel/Tests/Generator/Behavior/{ → Timestampable}/TimestampableBehaviorTest.php
  39. +1 −1 tests/Propel/Tests/Generator/Config/GeneratorConfigTest.php
  40. +1 −1 tests/Propel/Tests/Generator/Model/BehaviorTest.php
  41. +1 −1 tests/Propel/Tests/Generator/Model/TableTest.php
  42. +6 −149 tools/generator/build-propel.xml
  43. +0 −18 tools/generator/build.xml
  44. +0 −20 tools/generator/default.properties
View
@@ -8,8 +8,22 @@
}
}
-use \Symfony\Component\Console\Application;
+use Symfony\Component\Console\Application;
+use Symfony\Component\Finder\Finder;
+
+use Propel\Runtime\Propel;
+
+$finder = new Finder();
+$finder->files()->name('*.php')->in(__DIR__.'/../src/Propel/Generator/Command');
+
+$app = new Application('Propel', Propel::VERSION);
+
+foreach ($finder as $file) {
+ $ns = '\\Propel\\Generator\\Command';
+ $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
+ if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
+ $app->add($r->newInstance());
+ }
+}
-$app = new Application('Propel', '2.0 (dev)');
-$app->add(new \Propel\Generator\Command\TestPrepare());
$app->run();
View
@@ -20,7 +20,8 @@
"php": ">=5.3.2",
"symfony/yaml": ">=2.0",
"symfony/console": ">=2.0",
- "monolog/monolog": ">=1.0.2"
+ "monolog/monolog": ">=1.0.2",
+ "symfony/finder": ">=2.0"
},
"autoload": {
"psr-0": {
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -8,7 +8,7 @@
* @license MIT License
*/
-namespace Propel\Generator\Behavior;
+namespace Propel\Generator\Behavior\AlternativeCodingStandards;
use Propel\Generator\Model\Behavior;
@@ -8,7 +8,7 @@
* @license MIT License
*/
-namespace Propel\Generator\Behavior;
+namespace Propel\Generator\Behavior\AutoAddPk;
use Propel\Generator\Model\Behavior;
@@ -8,7 +8,7 @@
* @license MIT License
*/
-namespace Propel\Generator\Behavior;
+namespace Propel\Generator\Behavior\Delegate;
use Propel\Generator\Model\Behavior;
use Propel\Generator\Model\ForeignKey;
@@ -8,7 +8,7 @@
* @license MIT License
*/
-namespace Propel\Generator\Behavior;
+namespace Propel\Generator\Behavior\QueryCache;
use Propel\Generator\Model\Behavior;
@@ -8,7 +8,7 @@
* @license MIT License
*/
-namespace Propel\Generator\Behavior;
+namespace Propel\Generator\Behavior\Sluggable;
use Propel\Generator\Model\Behavior;
use Propel\Generator\Model\Unique;
@@ -8,7 +8,7 @@
* @license MIT License
*/
-namespace Propel\Generator\Behavior;
+namespace Propel\Generator\Behavior\Timestampable;
use Propel\Generator\Model\Behavior;
@@ -0,0 +1,76 @@
+<?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\Finder\Finder;
+
+use Propel\Generator\Exception\RuntimeException;
+
+/**
+ * @author William Durand <william.durand1@gmail.com>
+ */
+abstract class AbstractCommand extends Command
+{
+ const DEFAULT_INPUT_DIRECTORY = '.';
+
+ const DEFAULT_PLATFORM = 'MysqlPlatform';
+
+ const DEFAULT_MYSQL_ENGINE = 'InnoDB';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function configure()
+ {
+ $this
+ ->addOption('input-dir', null, InputOption::VALUE_REQUIRED, 'The input directory', self::DEFAULT_INPUT_DIRECTORY)
+ ->addOption('platform', null, InputOption::VALUE_REQUIRED, 'The platform', self::DEFAULT_PLATFORM)
+ // MySQL specific
+ ->addOption('mysql-engine', null, InputOption::VALUE_REQUIRED, 'MySQL engine (MyISAM, InnoDB, ...)', self::DEFAULT_MYSQL_ENGINE)
+ ;
+ }
+
+ protected function getBuildProperties($file)
+ {
+ $properties = array();
+
+ if (false === $lines = @file($file)) {
+ throw new RuntimeException(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;
+ }
+
+ protected function getSchemas(InputInterface $input)
+ {
+ $finder = new Finder();
+ return $finder
+ ->name('*schema.xml')
+ ->in($input->getOption('input-dir'))
+ ->depth(0)
+ ->files()
+ ;
+ }
+}
@@ -0,0 +1,146 @@
+<?php
+
+namespace Propel\Generator\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\ModelManager;
+use Propel\Generator\Util\Filesystem;
+
+/**
+ * @author Florian Klein <florian.klein@free.fr>
+ * @author William Durand <william.durand1@gmail.com>
+ */
+class ModelBuild extends AbstractCommand
+{
+ const DEFAULT_OUTPUT_DIRECTORY = 'generated-classes';
+
+ const DEFAULT_PEER_BUILDER = '\Propel\Generator\Builder\Om\PeerBuilder';
+
+ const DEFAULT_PEER_STUB_BUILDER = '\Propel\Generator\Builder\Om\ExtensionPeerBuilder';
+
+ const DEFAULT_OBJECT_BUILDER = '\Propel\Generator\Builder\Om\ObjectBuilder';
+
+ const DEFAULT_OBJECT_STUB_BUILDER = '\Propel\Generator\Builder\Om\ExtensionObjectBuilder';
+
+ const DEFAULT_MULTIEXTEND_OBJECT_BUILDER = '\Propel\Generator\Builder\Om\MultiExtendObjectBuilder';
+
+ const DEFAULT_QUERY_BUILDER = '\Propel\Generator\Builder\Om\QueryBuilder';
+
+ const DEFAULT_QUERY_STUB_BUILDER = '\Propel\Generator\Builder\Om\ExtensionQueryBuilder';
+
+ const DEFAULT_QUERY_INHERITANCE_BUILDER = '\Propel\Generator\Builder\Om\QueryInheritanceBuilder';
+
+ const DEFAULT_QUERY_INHERITANCE_STUB_BUILDER = '\Propel\Generator\Builder\Om\ExtensionQueryInheritanceBuilder';
+
+ const DEFAULT_TABLEMAP_BUILDER = '\Propel\Generator\Builder\Om\TableMapBuilder';
+
+ const DEFAULT_PLURALIZER = '\Propel\Generator\Builder\Util\StandardEnglishPluralizer';
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function configure()
+ {
+ parent::configure();
+
+ $this
+ ->addOption('output-dir', null, InputOption::VALUE_REQUIRED, 'The output directory', self::DEFAULT_OUTPUT_DIRECTORY)
+ ->addOption('peer-class', null, InputOption::VALUE_REQUIRED,
+ 'The peer class generator name', self::DEFAULT_PEER_BUILDER)
+ ->addOption('peer-stub-class', null, InputOption::VALUE_REQUIRED,
+ 'The peer stub class generator name', self::DEFAULT_PEER_STUB_BUILDER)
+ ->addOption('object-class', null, InputOption::VALUE_REQUIRED,
+ 'The object class generator name', self::DEFAULT_OBJECT_BUILDER)
+ ->addOption('object-stub-class', null, InputOption::VALUE_REQUIRED,
+ 'The object stub class generator name', self::DEFAULT_OBJECT_STUB_BUILDER)
+ ->addOption('object-multiextend-class', null, InputOption::VALUE_REQUIRED,
+ 'The object multiextend class generator name', self::DEFAULT_MULTIEXTEND_OBJECT_BUILDER)
+ ->addOption('query-class', null, InputOption::VALUE_REQUIRED,
+ 'The query class generator name', self::DEFAULT_QUERY_BUILDER)
+ ->addOption('query-stub-class', null, InputOption::VALUE_REQUIRED,
+ 'The query stub class generator name', self::DEFAULT_QUERY_STUB_BUILDER)
+ ->addOption('query-inheritance-class', null, InputOption::VALUE_REQUIRED,
+ 'The query inheritance class generator name', self::DEFAULT_QUERY_INHERITANCE_BUILDER)
+ ->addOption('query-inheritance-stub-class', null, InputOption::VALUE_REQUIRED,
+ 'The query inheritance stub class generator name', self::DEFAULT_QUERY_INHERITANCE_STUB_BUILDER)
+ ->addOption('tablemap-class', null, InputOption::VALUE_REQUIRED,
+ 'The tablemap class generator name', self::DEFAULT_TABLEMAP_BUILDER)
+ ->addOption('pluralizer-class', null, InputOption::VALUE_REQUIRED,
+ 'The pluralizer class name', self::DEFAULT_PLURALIZER)
+ ->addOption('enable-identifier-quoting', null, InputOption::VALUE_NONE,
+ 'Identifier quoting may result in undesired behavior (especially in Postgres)')
+ ->addOption('target-package', null, InputOption::VALUE_REQUIRED,
+ '', '')
+ ->addOption('enable-package-object-model', null, InputOption::VALUE_NONE,
+ '')
+ ->addOption('disable-namespace-auto-package', null, InputOption::VALUE_NONE,
+ 'Disable namespace auto-packaging')
+ ->addOption('base-prefix', null, InputOption::VALUE_REQUIRED,
+ 'Prefix for base classes', 'Base')
+ ->setName('model:build')
+ ->setDescription('Build the model classes based on Propel XML schemas')
+ ;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $generatorConfig = new GeneratorConfig(array(
+ 'propel.platform.class' => $input->getOption('platform'),
+ 'propel.builder.peer.class' => $input->getOption('peer-class'),
+ 'propel.builder.peerstub.class' => $input->getOption('peer-stub-class'),
+ 'propel.builder.object.class' => $input->getOption('object-class'),
+ 'propel.builder.objectstub.class' => $input->getOption('object-stub-class'),
+ 'propel.builder.objectmultiextend.class' => $input->getOption('object-multiextend-class'),
+ 'propel.builder.query.class' => $input->getOption('query-class'),
+ 'propel.builder.querystub.class' => $input->getOption('query-stub-class'),
+ 'propel.builder.queryinheritance.class' => $input->getOption('query-inheritance-class'),
+ 'propel.builder.queryinheritancestub.class' => $input->getOption('query-inheritance-stub-class'),
+ 'propel.builder.tablemap.class' => $input->getOption('tablemap-class'),
+ 'propel.builder.pluralizer.class' => $input->getOption('pluralizer-class'),
+ 'propel.disableIdentifierQuoting' => !$input->getOption('enable-identifier-quoting'),
+ 'propel.targetPackage' => $input->getOption('target-package'),
+ 'propel.packageObjectModel' => $input->getOption('enable-package-object-model'),
+ 'propel.namespace.autoPackage' => !$input->getOption('disable-namespace-auto-package'),
+ 'propel.basePrefix' => $input->getOption('base-prefix'),
+ 'propel.addGenericAccessors' => true,
+ 'propel.addGenericMutators' => true,
+ 'propel.addSaveMethod' => true,
+ 'propel.addTimeStamp' => false,
+ 'propel.addValidateMethod' => true,
+ 'propel.addHooks' => true,
+ 'propel.namespace.om' => 'Om',
+ 'propel.namespace.map' => 'Map',
+ 'propel.useLeftJoinsInDoJoinMethods' => true,
+ 'propel.emulateForeignKeyConstraints' => false,
+ 'propel.schema.autoPrefix = false' => false,
+ 'propel.dateTimeClass' => '\DateTime',
+ // MySQL specific
+ 'propel.mysql.tableType' => $input->getOption('mysql-engine'),
+ 'propel.mysql.tableEngineKeyword' => 'ENGINE',
+ ));
+
+ $filesystem = new Filesystem();
+ $filesystem->mkdir($input->getOption('output-dir'));
+
+ $manager = new ModelManager();
+ $manager->setGeneratorConfig($generatorConfig);
+ $manager->setSchemas($this->getSchemas($input));
+ $manager->setLoggerClosure(function($message) use ($input, $output) {
+ if ($input->getOption('verbose')) {
+ $output->writeln($message);
+ }
+ });
+ $manager->setWorkingDirectory($input->getOption('output-dir'));
+
+ $manager->build();
+ }
+}
Oops, something went wrong.

0 comments on commit 4bd3d5e

Please sign in to comment.