/**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     if ($input->isInteractive()) {
         $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you confirm generation', 'yes', '?'), true);
         if (!$questionHelper->ask($input, $output, $question)) {
             $output->writeln('<error>Command aborted</error>');
             return 1;
         }
     }
     $entity = Validators::validateEntityName($input->getOption('entity'));
     list($bundle, $entity) = $this->parseShortcutNotation($entity);
     $format = Validators::validateFormat($input->getOption('format'));
     $prefix = $this->getRoutePrefix($input, $entity);
     $withWrite = $input->getOption('with-write');
     $forceOverwrite = $input->getOption('overwrite');
     $questionHelper->writeSection($output, 'CRUD generation');
     $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity;
     $metadata = $this->getEntityMetadata($entityClass);
     $bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
     $generator = $this->getGenerator($bundle);
     $generator->setSkeletonDirs($this->getContainer()->get('kernel')->locateResource('@OliorgaGeneratorBundle/Resources/skeleton'));
     $generator->generate($bundle, $entity, $metadata[0], $format, $prefix, $withWrite, $forceOverwrite);
     $output->writeln('Generating the CRUD code: <info>OK</info>');
     $errors = array();
     $runner = $questionHelper->getRunner($output, $errors);
     // form
     if ($withWrite) {
         $this->generateForm($bundle, $entity, $metadata);
         $output->writeln('Generating the Form code: <info>OK</info>');
     }
     $questionHelper->writeGeneratorSummary($output, $errors);
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getQuestionHelper();
     $questionHelper->writeSection($output, 'Welcome to the Symfony2 bundle generator');
     // namespace
     $namespace = null;
     try {
         $namespace = $input->getOption('namespace') ? Validators::validateBundleNamespace($input->getOption('namespace')) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $namespace) {
         $output->writeln(array('', 'Your application code must be written in <comment>bundles</comment>. This command helps', 'you generate them easily.', '', '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).', '', 'See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more', 'details on bundle naming conventions.', '', 'Use <comment>/</comment> instead of <comment>\\ </comment> for the namespace delimiter to avoid any problem.', ''));
         $namespace = $questionHelper->askAndValidate($output, $questionHelper->getQuestion('Bundle namespace', $input->getOption('namespace')), array('Oliorga\\GeneratorBundleCommand\\Validators', 'validateBundleNamespace'), false, $input->getOption('namespace'));
         $input->setOption('namespace', $namespace);
     }
     // bundle name
     $bundle = null;
     try {
         $bundle = $input->getOption('bundle-name') ? Validators::validateBundleName($input->getOption('bundle-name')) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $bundle) {
         $bundle = strtr($namespace, array('\\Bundle\\' => '', '\\' => ''));
         $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 = $questionHelper->askAndValidate($output, $questionHelper->getQuestion('Bundle name', $bundle), array('Oliorga\\GeneratorBundleCommand\\Validators', 'validateBundleName'), false, $bundle);
         $input->setOption('bundle-name', $bundle);
     }
     // target dir
     $dir = null;
     try {
         $dir = $input->getOption('dir') ? Validators::validateTargetDir($input->getOption('dir'), $bundle, $namespace) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $dir) {
         $dir = dirname($this->getContainer()->getParameter('kernel.root_dir')) . '/src';
         $output->writeln(array('', 'The bundle can be generated anywhere. The suggested default directory uses', 'the standard conventions.', ''));
         $dir = $questionHelper->askAndValidate($output, $questionHelper->getQuestion('Target directory', $dir), function ($dir) use($bundle, $namespace) {
             return Validators::validateTargetDir($dir, $bundle, $namespace);
         }, false, $dir);
         $input->setOption('dir', $dir);
     }
     // format
     $format = null;
     try {
         $format = $input->getOption('format') ? Validators::validateFormat($input->getOption('format')) : null;
     } catch (\Exception $error) {
         $output->writeln($questionHelper->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
     }
     if (null === $format) {
         $output->writeln(array('', 'Determine the format to use for the generated configuration.', ''));
         $format = $questionHelper->askAndValidate($output, $questionHelper->getQuestion('Configuration format (yml, xml, php, or annotation)', $input->getOption('format')), array('Oliorga\\GeneratorBundleCommand\\Validators', 'validateFormat'), false, $input->getOption('format'));
         $input->setOption('format', $format);
     }
     // optional files to generate
     $output->writeln(array('', 'To help you get started faster, the command can generate some', 'code snippets for you.', ''));
     $structure = $input->getOption('structure');
     if (!$structure && $questionHelper->askConfirmation($output, $questionHelper->getQuestion('Do you want to generate the whole directory structure', 'no', '?'), false)) {
         $structure = true;
     }
     $input->setOption('structure', $structure);
     // summary
     $output->writeln(array('', $this->getHelper('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), ''));
 }