diff --git a/Command/FormGenerateCommand.php b/Command/FormGenerateCommand.php index 2f09cc3..89d45e0 100644 --- a/Command/FormGenerateCommand.php +++ b/Command/FormGenerateCommand.php @@ -35,6 +35,7 @@ class FormGenerateCommand extends PropelGeneratorAwareCommand $this ->setDescription('Generate Form types stubs based on the schema.xml') ->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to use to generate Form types') + ->addArgument('models', InputArgument::IS_ARRAY, 'Model classes to generate Form Types from') ->addOption('force', 'f', InputOption::VALUE_NONE, 'Overwrite existing Form types') ->setHelp(<<%command.name% command allows you to quickly generate Form Type stubs for a given bundle. @@ -65,7 +66,7 @@ EOT if ($schemas) { foreach ($schemas as $fileName => $array) { foreach ($this->getDatabasesFromSchema($array[1]) as $database) { - $this->createFormTypeFromDatabase($bundle, $database, $output, $input->getOption('force')); + $this->createFormTypeFromDatabase($bundle, $database, $input->getArgument('models'), $output, $input->getOption('force')); } } } else { @@ -74,11 +75,15 @@ EOT } } - private function createFormTypeFromDatabase(BundleInterface $bundle, \Database $database, OutputInterface $output, $force = false) + private function createFormTypeFromDatabase(BundleInterface $bundle, \Database $database, $models, OutputInterface $output, $force = false) { $dir = $this->createDirectory($bundle, $output); foreach ($database->getTables() as $table) { + if (0 < count($models) && !in_array($table->getPhpName(), $models)) { + continue; + } + $file = new \SplFileInfo(sprintf('%s/%sType.php', $dir, $table->getPhpName())); if (!file_exists($file) || true === $force) { diff --git a/Resources/doc/README.markdown b/Resources/doc/README.markdown index 81f125c..81f22fe 100644 --- a/Resources/doc/README.markdown +++ b/Resources/doc/README.markdown @@ -319,10 +319,14 @@ Note that the `--force` option is needed to actually execute the deletion. You can generate stub classes based on your `schema.xml` in a given bundle: - > php app/console propel:form:generate [-f|--force] bundle + > php app/console propel:form:generate [-f|--force] bundle [models1] ... [modelsN] It will write Form Type classes in `src/YourVendor/YourBundle/Form/Type`. +You can choose which Form Type to build by specifing Model names: + + > php app/console propel:form:generate @MySuperBundle Book Author + ## PropelParamConverter ##