/** * @see Command */ protected function interact(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $questionHelper = $this->getQuestionHelper(); $questionHelper->writeSection($output, 'Welcome to the Sylius resource generator'); // namespace $output->writeln(array('', 'This command helps you generate Sylius resource.', '', 'First, you need to give the entity name you want to generate.', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.', '')); $bundleNames = $this->getContainer()->get('kernel')->getBundles(); $bundleList = array(); foreach ($bundleNames as $bundle) { if ($bundle instanceof AbstractResourceBundle) { $bundleList[] = $bundle->getName(); } } while (true) { $question = new Question($questionHelper->getQuestion('The Entity shortcut name', $input->getOption('resource')), $input->getOption('resource')); $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName')); $question->setAutocompleterValues($bundleList); $resource = $questionHelper->ask($input, $output, $question); $resource = Validators::validateEntityName($resource); list($bundle, $entity) = $this->parseShortcutNotation($resource); $bundle = Validators::validateBundleName($bundle); try { $this->getContainer()->get('kernel')->getBundle($bundle); } catch (\Exception $e) { $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $bundle)); continue; } if (in_array($entity, Validators::getReservedWords())) { $output->writeln(sprintf('<bg=red> "%s" is a reserved word</>.', $entity)); continue; } break; } $input->setOption('resource', $resource); $dialog = $this->getHelper('dialog'); if ($dialog->askConfirmation($output, '<question>Would you add form? (y/N)</question>')) { $this->commands[] = array('avoo:generate:form', '--entity' => $resource, '--no-summary' => true); if ($dialog->askConfirmation($output, '<question>Would you add controller? (y/N)</question>')) { $this->commands[] = array('avoo:generate:controller', '--controller' => $resource, '--no-summary' => true); if ($dialog->askConfirmation($output, '<question>Would you add CRUD? (y/N)</question>')) { $backend = $dialog->askConfirmation($output, '<question>With backend? (y/N)</question>'); $crud = array(); if (!$backend) { $crud['--no-backend'] = true; } else { while (true) { $question = new Question($questionHelper->getQuestion('Backend bundle', null)); $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateBundleName')); $question->setAutocompleterValues($bundleList); $backendBundle = $questionHelper->ask($input, $output, $question); try { $this->getContainer()->get('kernel')->getBundle($backendBundle); break; } catch (\Exception $e) { $output->writeln(sprintf('<bg=red>Bundle "%s" does not exist.</>', $backendBundle)); $input->setOption('no-summary', null); continue; } } $crud['--backend'] = $backendBundle; } $this->commands[] = array_merge(array('avoo:generate:crud', '--entity' => $resource, '--no-summary' => true), $crud); } } $this->commands[] = array('cache:clear', '--no-warmup' => true); } }