diff --git a/Command/AbstractPropelCommand.php b/Command/AbstractPropelCommand.php index 9c4f8b2..f373787 100644 --- a/Command/AbstractPropelCommand.php +++ b/Command/AbstractPropelCommand.php @@ -50,6 +50,11 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand */ protected $buffer = null; + /** + * @var Symfony\Component\HttpKernel\Bundle\BundleInterface + */ + protected $bundle = null; + /** * Return the package prefix for a given bundle. * @@ -81,6 +86,13 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand 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 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand $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 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand * * @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 @@ EOT; 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); } diff --git a/Command/FixturesDumpCommand.php b/Command/FixturesDumpCommand.php index cc5c5e7..7f3b939 100644 --- a/Command/FixturesDumpCommand.php +++ b/Command/FixturesDumpCommand.php @@ -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. * diff --git a/Command/FixturesLoadCommand.php b/Command/FixturesLoadCommand.php index f1cb9f5..afe16e2 100644 --- a/Command/FixturesLoadCommand.php +++ b/Command/FixturesLoadCommand.php @@ -47,12 +47,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 */ @@ -128,12 +122,7 @@ EOT $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 @@ EOT 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 @@ EOT } $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 @@ EOT */ protected function getFixturesPath(BundleInterface $bundle) { - return $bundle->getPath().DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'fixtures'; + return $bundle->getPath() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'fixtures'; } } diff --git a/Command/FormGenerateCommand.php b/Command/FormGenerateCommand.php index 89d45e0..8e8d08c 100644 --- a/Command/FormGenerateCommand.php +++ b/Command/FormGenerateCommand.php @@ -55,23 +55,14 @@ EOT */ 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 *schemas.xml files found in bundle %s.', $bundle->getName())); } + } else { + $output->writeln(sprintf('No *schemas.xml files found in bundle %s.', $this->bundle->getName())); } } diff --git a/Command/InitAclCommand.php b/Command/InitAclCommand.php index cec1daf..68ac4ef 100644 --- a/Command/InitAclCommand.php +++ b/Command/InitAclCommand.php @@ -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 @@ -82,7 +83,7 @@ EOT 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')); diff --git a/Command/ModelBuildCommand.php b/Command/ModelBuildCommand.php index 88a2ec2..31126bd 100644 --- a/Command/ModelBuildCommand.php +++ b/Command/ModelBuildCommand.php @@ -12,6 +12,7 @@ namespace Propel\PropelBundle\Command; 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 @@ class ModelBuildCommand extends AbstractPropelCommand { $this ->setDescription('Build the Propel Object Model classes based on XML schemas') + ->addArgument('bundle', InputArgument::OPTIONAL, 'The bundle to generate model classes from') ->setHelp(<<%command.name% command builds the Propel runtime model classes (ActiveRecord, Query, Peer, and TableMap classes) based on the XML schemas defined in all Bundles.