Exemplo n.º 1
0
 private function getInteractiveParameters(BundleGenerator $generator, InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelper('dialog');
     $formatter = $this->getHelper('formatter');
     $output->writeln($formatter->formatBlock('Welcome to the Symfony2 bundle generator', 'bg=blue;fg=white', true));
     // namespace
     $output->writeln(array('', 'Each bundle is hosted under a namespace (like <comment>Acme/Bundle/BlogBundle</comment>).', 'The namespace should begin with a "vendor" name like your company name, your', 'project name, or your client name, followed by one or more optional category', 'sub-namespaces, and it should end with the bundle name itself', '(which must have <comment>Bundle</comment> as a suffix).', ''));
     $namespace = $dialog->askAndValidate($output, $this->getQuestion('Bundle namespace', $input->getOption('namespace')), array($generator, 'validateNamespace'), false, $input->getOption('namespace'));
     $namespace = $generator->validateNamespace($namespace);
     // bundle name
     $bundle = $input->getOption('bundleName') ?: strtr($namespace, array('\\' => ''));
     $output->writeln(array('', 'In your code, a bundle is often referenced by its name. It can be the', 'concatenation of all namespace parts but it\'s really up to you to come', 'up with a unique name (a good practice is to start with the vendor name).', 'Based on the namespace, we suggest <comment>' . $bundle . '</comment>.', ''));
     $bundle = $dialog->askAndValidate($output, $this->getQuestion('Bundle name', $bundle), array($generator, 'validateBundleName'), false, $bundle);
     $bundle = $generator->validateBundleName($bundle);
     // target dir
     $dir = $input->getOption('dir') ?: dirname($this->container->getParameter('kernel.root_dir')) . '/src';
     $output->writeln(array('', 'The bundle can be generated anywhere, but remember to update the autoloader', 'accordingly. The suggested defaults uses the standard conventions.', ''));
     $dir = $dialog->askAndValidate($output, $this->getQuestion('Target directory', $dir), function ($dir) use($generator, $bundle, $namespace) {
         return $generator->validateTargetDir($dir, $bundle, $namespace);
     }, false, $dir);
     $dir = $generator->validateTargetDir($dir, $bundle, $namespace);
     // format
     $format = $input->getOption('format') ?: 'annotation';
     $output->writeln(array('', 'Determine the format to use for the generated configuration.', ''));
     $format = $dialog->askAndValidate($output, $this->getQuestion('Configuration format (yml, xml, php, or annotation)', $format), array($generator, 'validateFormat'), false, $format);
     $format = $generator->validateFormat($format);
     // optional files to generate
     $files = array();
     $output->writeln(array('', 'To help you getting started faster, the command can generate some', 'code snippets for you.', ''));
     if ($dialog->askConfirmation($output, $this->getQuestion('Do you want to generate a simple controller with a template', 'yes', '?'), true)) {
         $files[] = 'controller';
     }
     // FIXME: add more options
     // Controller with template and routing
     // Unit test, functional test (if controller)
     // config avec un service / parameters
     // CLI command
     // Doc avec .rst
     // Translations
     // assets
     // summary
     $output->writeln(array('', $formatter->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf("You are going to generate a \"<info>%s\\%s</info>\" bundle\nin \"<info>%s</info>\" using the \"<info>%s</info>\" format.", $namespace, $bundle, $dir, $format), ''));
     if (!$dialog->askConfirmation($output, $this->getQuestion('Do you confirm generation', 'no', '?'), false)) {
         $output->writeln('<error>Command aborted</error>');
         return false;
     }
     return array($namespace, $bundle, $dir, $format);
 }