Permalink
Browse files

Added a better way to use a bundle argument in commands

Added bundle argument to propel:model:build command
  • Loading branch information...
1 parent cb9d790 commit a30747ed09029be85270e553bc38a80b415b8abd @willdurand willdurand committed Apr 20, 2012
@@ -51,6 +51,11 @@
protected $buffer = null;
/**
+ * @var Symfony\Component\HttpKernel\Bundle\BundleInterface
+ */
+ protected $bundle = null;
+
+ /**
* Return the package prefix for a given bundle.
*
* @param Bundle $bundle
@@ -81,6 +86,13 @@ protected function initialize(InputInterface $input, OutputInterface $output)
parent::initialize($input, $output);
$this->checkConfiguration();
+
+ if ($input->hasArgument('bundle') && '@' === substr($input->getArgument('bundle'), 0, 1)) {
+ $this->bundle = $this
+ ->getContainer()
+ ->get('kernel')
+ ->getBundle(substr($input->getArgument('bundle'), 1));
+ }
}
/**
@@ -177,7 +189,7 @@ protected function copySchemas(KernelInterface $kernel, $cacheDir)
$base = ltrim(realpath($kernel->getRootDir().'/..'), DIRECTORY_SEPARATOR);
- $finalSchemas = $this->getFinalSchemas($kernel);
+ $finalSchemas = $this->getFinalSchemas($kernel, $this->bundle);
foreach ($finalSchemas as $schema) {
list($bundle, $finalSchema) = $schema;
$packagePrefix = self::getPackagePrefix($bundle, $base);
@@ -231,8 +243,12 @@ protected function copySchemas(KernelInterface $kernel, $cacheDir)
*
* @return array
*/
- protected function getFinalSchemas(KernelInterface $kernel)
+ protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bundle = null)
{
+ if (null !== $bundle) {
+ return $this->getSchemasFromBundle($bundle);
+ }
+
$finalSchemas = array();
foreach ($kernel->getBundles() as $bundle) {
$finalSchemas = array_merge($finalSchemas, $this->getSchemasFromBundle($bundle));
@@ -541,7 +557,11 @@ protected function getFileLocator()
private function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle)
{
- $schemaPath = str_replace($bundle->getPath(). DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR, '', $schema->getRealPath());
+ $schemaPath = str_replace(
+ $bundle->getPath(). DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR,
+ '',
+ $schema->getRealPath()
+ );
return sprintf('@%s/Resources/config/%s', $bundle->getName(), $schemaPath);
}
@@ -11,12 +11,11 @@
namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\AbstractPropelCommand;
+use Propel\PropelBundle\DataFixtures\Dumper\YamlDataDumper;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
-use Propel\PropelBundle\DataFixtures\Dumper\YamlDataDumper;
-
/**
* FixturesDumpCommand.
*
@@ -48,12 +48,6 @@ class FixturesLoadCommand extends AbstractPropelCommand
private $filesystem = null;
/**
- * Bundle the fixtures are being loaded from
- * @var Symfony\Component\HttpKernel\Bundle\BundleInterface
- */
- private $bundle;
-
- /**
* @see Command
*/
protected function configure()
@@ -128,12 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->filesystem = new Filesystem();
- if ('@' === substr($input->getArgument('bundle'), 0, 1)) {
- $this->bundle = $this
- ->getContainer()
- ->get('kernel')
- ->getBundle(substr($input->getArgument('bundle'), 1));
-
+ if (null !== $this->bundle) {
$this->absoluteFixturesPath = $this->getFixturesPath($this->bundle);
} else {
$this->absoluteFixturesPath = realpath($this->getApplication()->getKernel()->getRootDir() . '/../' . $input->getOption('dir'));
@@ -293,7 +282,7 @@ protected function insertSql($config, $sqlDir, $schemaDir, $output)
if (true === $ret) {
$this->writeSection($output, array(
- '', 'All SQL statements have been executed.'
+ '', 'All SQL statements have been inserted.'
), 'fg=green;bg=black');
} else {
$this->writeTaskError($output, 'insert-sql', false);
@@ -325,7 +314,6 @@ protected function getFixtureFiles($type = 'sql', $in = null)
}
$finalFixtureFiles = array();
-
foreach ($files as $file) {
$fixtureFilePath = str_replace($this->getFixturesPath($this->bundle) . DIRECTORY_SEPARATOR, '', $file->getRealPath());
$logicalName = sprintf('@%s/Resources/fixtures/%s', $this->bundle->getName(), $fixtureFilePath);
@@ -342,6 +330,6 @@ protected function getFixtureFiles($type = 'sql', $in = null)
*/
protected function getFixturesPath(BundleInterface $bundle)
{
- return $bundle->getPath().DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'fixtures';
+ return $bundle->getPath() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'fixtures';
}
}
@@ -55,23 +55,14 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- if ('@' === substr($input->getArgument('bundle'), 0, 1)) {
- $bundle = $this
- ->getContainer()
- ->get('kernel')
- ->getBundle(substr($input->getArgument('bundle'), 1));
-
- $schemas = $this->getSchemasFromBundle($bundle);
-
- if ($schemas) {
- foreach ($schemas as $fileName => $array) {
- foreach ($this->getDatabasesFromSchema($array[1]) as $database) {
- $this->createFormTypeFromDatabase($bundle, $database, $input->getArgument('models'), $output, $input->getOption('force'));
- }
+ if ($schemas = $this->getSchemasFromBundle($this->bundle)) {
+ foreach ($schemas as $fileName => $array) {
+ foreach ($this->getDatabasesFromSchema($array[1]) as $database) {
+ $this->createFormTypeFromDatabase($this->bundle, $database, $input->getArgument('models'), $output, $input->getOption('force'));
}
- } else {
- $output->writeln(sprintf('No <comment>*schemas.xml</comment> files found in bundle <comment>%s</comment>.', $bundle->getName()));
}
+ } else {
+ $output->writeln(sprintf('No <comment>*schemas.xml</comment> files found in bundle <comment>%s</comment>.', $this->bundle->getName()));
}
}
@@ -10,13 +10,14 @@
namespace Propel\PropelBundle\Command;
-use Symfony\Component\Filesystem\Filesystem;
-use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Console\Input\InputArgument;
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\Filesystem\Filesystem;
+use Symfony\Component\HttpKernel\Bundle\BundleInterface;
+use Symfony\Component\HttpKernel\KernelInterface;
/**
* @author Toni Uebernickel <tuebernickel@gmail.com>
@@ -82,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return parent::execute($input, $output);
}
- protected function getFinalSchemas(KernelInterface $kernel)
+ protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bundle = null)
{
$aclSchema = new \SplFileInfo($kernel->locateResource('@PropelBundle/Resources/acl_schema.xml'));
@@ -12,6 +12,7 @@
use Propel\PropelBundle\Command\AbstractPropelCommand;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
/**
@@ -29,6 +30,7 @@ protected function configure()
{
$this
->setDescription('Build the Propel Object Model classes based on XML schemas')
+ ->addArgument('bundle', InputArgument::OPTIONAL, 'The bundle to generate model classes from')
->setHelp(<<<EOT
The <info>%command.name%</info> command builds the Propel runtime model classes (ActiveRecord, Query, Peer, and TableMap classes) based on the XML schemas defined in all Bundles.

0 comments on commit a30747e

Please sign in to comment.