/** * @see Command * * @throws \InvalidArgumentException When namespace doesn't end with Bundle * @throws \RuntimeException When bundle can't be executed */ protected function execute(InputInterface $input, OutputInterface $output) { $dialog = $this->getDialogHelper(); if ($input->isInteractive()) { if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) { $output->writeln('<error>Command aborted</error>'); return 1; } } foreach (array('plugin-name', 'namespace', 'dir') as $option) { if (null === $input->getOption($option)) { throw new \RuntimeException(sprintf('The "%s" option must be provided.', $option)); } } // validate the namespace $vendor = Validators::validateVendor($input->getOption('vendor')); $pluginName = Validators::validatePluginName($input->getOption('plugin-name')); $namespace = Validators::validateBundleNamespace($input->getOption('namespace'), false); if (!($bundle = $input->getOption('bundle-name'))) { $bundle = strtr($namespace, array('\\' => '')); } $bundle = Validators::validateBundleName($bundle); $dir = Validators::validateTargetDir($input->getOption('dir')); if (null === $input->getOption('format')) { $input->setOption('format', 'annotation'); } $format = Validators::validateFormat($input->getOption('format')); $structure = $input->getOption('structure'); $admin = $input->getOption('admin'); $zip = $input->getOption('zip'); $dialog->writeSection($output, 'Bundle generation'); if (!$this->getContainer()->get('filesystem')->isAbsolutePath($dir)) { $dir = getcwd() . '/' . $dir; } $generator = $this->getGenerator(); $generator->generate($vendor, $pluginName, $namespace, $bundle, $dir, $format, $structure, $admin, $zip); $output->writeln('Generating the bundle code: <info>OK</info>'); $errors = array(); $dialog->writeGeneratorSummary($output, $errors); $output->writeln('You must run the plugin install command manually: <comment>php application/console plugins:install ' . strtolower($vendor) . '/' . strtolower($pluginName) . '-plugin-bundle</comment>'); }