/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { // Start question helper $questionHelper = $this->getQuestionHelper(); $questionHelper->writeSection($output, 'Welcome to the united CRUD generator!'); // get entity $entity = $input->getOption('entity'); $question = new Question($questionHelper->getQuestion('Entity', $entity), $entity); $question->setValidator(function ($answer) { return Validators::validateEntityName($answer); }); $complete = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager()); $completeEntities = $complete->getSuggestions(); $question->setAutocompleterValues($completeEntities); $entity = $questionHelper->ask($input, $output, $question); $input->setOption('entity', $entity); // get bundle $destinationBundle = $input->getOption('bundle'); $question = new Question($questionHelper->getQuestion('Destination bundle', $destinationBundle), $destinationBundle); $question->setValidator(function ($answer) { return Validators::validateBundleName($answer); }); $question->setAutocompleterValues($this->getBundleSuggestions()); $destinationBundle = $questionHelper->ask($input, $output, $question); $input->setOption('bundle', $destinationBundle); }
protected function interact(InputInterface $input, OutputInterface $output) { $questionHelper = $this->getQuestionHelper(); $questionHelper->writeSection($output, 'Welcome to the Doctrine2 CRUD generator'); // namespace $output->writeln(array('', 'This command helps you generate CRUD controllers and templates.', '', 'First, you need to give the entity for which you want to generate a CRUD.', 'You can give an entity that does not exist yet and the wizard will help', 'you defining it.', '', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.', '')); if ($input->hasArgument('entity') && $input->getArgument('entity') != '') { $input->setOption('entity', $input->getArgument('entity')); } $question = new Question($questionHelper->getQuestion('The Entity shortcut name', $input->getOption('entity')), $input->getOption('entity')); $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName')); $autocompleter = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager()); $autocompleteEntities = $autocompleter->getSuggestions(); $question->setAutocompleterValues($autocompleteEntities); $entity = $questionHelper->ask($input, $output, $question); $input->setOption('entity', $entity); list($bundle, $entity) = $this->parseShortcutNotation($entity); // write? $withWrite = 'yes'; $input->setOption('with-write', $withWrite); // format $format = 'annotation'; $input->setOption('format', $format); // route prefix $prefix = $this->getRoutePrefix($input, $entity); $output->writeln(array('', 'Determine the routes prefix (all the routes will be "mounted" under this', 'prefix: /prefix/, /prefix/new, ...).', '')); $prefix = $questionHelper->ask($input, $output, new Question($questionHelper->getQuestion('Routes prefix', '/' . $prefix), '/' . $prefix)); $input->setOption('route-prefix', $prefix); // summary $output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf("You are going to generate a CRUD controller for \"<info>%s:%s</info>\"", $bundle, $entity), sprintf("using the \"<info>%s</info>\" format.", $format), '')); }
protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->getContainer()->get('doctrine')->getManager(); $helper = $this->getHelper('question'); $output->writeln("\n<question> "); $output->writeln(' Welcome to the Fbeen slug generator. '); $output->writeln(" </question>\n"); $entityName = $input->getArgument('entity'); if (!$entityName) { $output->writeln('This command helps you to update slugs on an entire table.'); $output->writeln('First, you need to give the entity for which you want to generate the slugs.'); $output->writeln("\nYou must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.\n"); $question = new Question('<info>The Entity shortcut name: </info>'); $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName')); $autocompleter = new EntitiesAutoCompleter($em); $autocompleteEntities = $autocompleter->getSuggestions(); $question->setAutocompleterValues($autocompleteEntities); $entityName = $helper->ask($input, $output, $question); } $entities = $em->getRepository($entityName)->findAll(); $question = new ConfirmationQuestion('<info>Continue generating slugs for ' . $entityName . '</info> [<comment>no</comment>]? ', false); if (!$helper->ask($input, $output, $question)) { return; } $output->writeln("\nGenerating the slugs..."); $slugupdater = new SlugUpdater(); foreach ($entities as $entity) { $slugupdater->preUpdate(new LifecycleEventArgs($entity, $em)); $em->flush(); } $output->writeln("\nDone!\n"); }
protected function interact(InputInterface $input, OutputInterface $output) { $questionHelper = $this->getQuestionHelper(); $questionHelper->writeSection($output, 'Welcome to the Parse.com CRUD generator'); // namespace $output->writeln(array('', 'This command helps you generate CRUD controllers and templates.', 'You must use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>.', '')); if ($input->hasArgument('parse-entity-name') && $input->getArgument('parse-entity-name') != '') { $input->setOption('parse-entity-name', $input->getArgument('parse-entity-name')); } $question = new Question($questionHelper->getQuestion('The Entity shortcut name', $input->getOption('parse-entity-name')), $input->getOption('parse-entity-name')); $question->setValidator(array('BcTic\\ParseCrudGenerator\\CrudGeneratorBundle\\Command\\Validators', 'validateParseEntityName')); $autocompleter = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager()); $autocompleteEntities = $autocompleter->getSuggestions(); $question->setAutocompleterValues($autocompleteEntities); $entity = $questionHelper->ask($input, $output, $question); $input->setOption('parse-entity-name', $entity); list($bundle, $entity) = $this->parseShortcutNotation($entity); // route prefix $prefix = $this->getRoutePrefix($input, $entity); $output->writeln(array('', 'Determine the routes prefix (all the routes will be "mounted" under this', 'prefix: /prefix/, /prefix/new, ...).', '')); $prefix = $questionHelper->ask($input, $output, new Question($questionHelper->getQuestion('Routes prefix', '/' . $prefix), '/' . $prefix)); $input->setOption('route-prefix', $prefix); // summary $output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf("You are going to generate a CRUD controller for \"<info>%s:%s</info>\"", $bundle, $entity), '')); }
protected function interact(InputInterface $input, OutputInterface $output) { $questionHelper = $this->getQuestionHelper(); $questionHelper->writeSection($output, 'Welcome to the Doctrine2 CRUD generator'); // namespace $output->writeln(array('', 'This command helps you generate CRUD controllers and templates.', '', 'First, give the name of the existing entity for which you want to generate a CRUD', '(use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>)', '')); if ($input->hasArgument('entity') && $input->getArgument('entity') != '') { $input->setOption('entity', $input->getArgument('entity')); } $question = new Question($questionHelper->getQuestion('The Entity shortcut name', $input->getOption('entity')), $input->getOption('entity')); $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName')); $autocompleter = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager()); $autocompleteEntities = $autocompleter->getSuggestions(); $question->setAutocompleterValues($autocompleteEntities); $entity = $questionHelper->ask($input, $output, $question); $input->setOption('entity', $entity); list($bundle, $entity) = $this->parseShortcutNotation($entity); try { $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($bundle) . '\\' . $entity; $metadata = $this->getEntityMetadata($entityClass); } catch (\Exception $e) { throw new \RuntimeException(sprintf('Entity "%s" does not exist in the "%s" bundle. You may have mistyped the bundle name or maybe the entity doesn\'t exist yet (create it first with the "doctrine:generate:entity" command).', $entity, $bundle)); } // write? $withWrite = $input->getOption('with-write') ?: false; $output->writeln(array('', 'By default, the generator creates two actions: list and show.', 'You can also ask it to generate "write" actions: new, update, and delete.', '')); $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you want to generate the "write" actions', $withWrite ? 'yes' : 'no', '?', $withWrite), $withWrite); $withWrite = $questionHelper->ask($input, $output, $question); $input->setOption('with-write', $withWrite); // format $format = $input->getOption('format'); $output->writeln(array('', 'Determine the format to use for the generated CRUD.', '')); $question = new Question($questionHelper->getQuestion('Configuration format (yml, xml, php, or annotation)', $format), $format); $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateFormat')); $format = $questionHelper->ask($input, $output, $question); $input->setOption('format', $format); // route prefix $prefix = $this->getRoutePrefix($input, $entity); $output->writeln(array('', 'Determine the routes prefix (all the routes will be "mounted" under this', 'prefix: /prefix/, /prefix/new, ...).', '')); $prefix = $questionHelper->ask($input, $output, new Question($questionHelper->getQuestion('Routes prefix', '/' . $prefix), '/' . $prefix)); $input->setOption('route-prefix', $prefix); // controller folder? $controllerFolder = $input->getOption('controller-folder') ?: 'src/AppBundle/Controller/'; $output->writeln(array('', 'By default, the generator creates the controller on Controller namespace.', 'You can also generate it on an subnamespace (Ex: src/AppBundle/Controller/Backend).', '')); $question = new Question($questionHelper->getQuestion('Determine the subnamespace you want:', $controllerFolder), $controllerFolder); $controllerFolder = $questionHelper->ask($input, $output, $question); if ($controllerFolder == 'src/AppBundle/Controller/') { $controllerFolder = ''; } $input->setOption('controller-folder', $controllerFolder); // summary $output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf('You are going to generate a CRUD controller for "<info>%s:%s</info>"', $bundle, $entity), sprintf('using the "<info>%s</info>" format.', $format), '')); }
/** * @dataProvider getNamespaces */ public function testSuggestions($expected, $alias, $classes) { $autoCompleter = new EntitiesAutoCompleter($this->getEntityManagerMock($alias, $classes)); $this->assertSame($expected, $autoCompleter->getSuggestions()); }
protected function interact(InputInterface $input, OutputInterface $output) { $questionHelper = $this->getQuestionHelper(); $questionHelper->writeSection($output, 'Welcome to the Doctrine2 CRUD generator'); // namespace $output->writeln(array('', 'This command helps you generate CRUD controllers and templates.', '', 'First, give the name of the existing entity for which you want to generate a CRUD', '(use the shortcut notation like <comment>AcmeBlogBundle:Post</comment>)', '')); if ($input->hasArgument('entity') && $input->getArgument('entity') != '') { $input->setOption('entity', $input->getArgument('entity')); } $question = new Question($questionHelper->getQuestion('The Entity shortcut name', $input->getOption('entity')), $input->getOption('entity')); $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateEntityName')); $autocompleter = new EntitiesAutoCompleter($this->getContainer()->get('doctrine')->getManager()); $autocompleteEntities = $autocompleter->getSuggestions(); $question->setAutocompleterValues($autocompleteEntities); $entity = $questionHelper->ask($input, $output, $question); $input->setOption('entity', $entity); list($bundle, $entity) = $this->parseShortcutNotation($entity); // write? $withWrite = $input->getOption('with-write') ?: false; $output->writeln(array('', 'By default, the generator creates two actions: list and show.', 'You can also ask it to generate "write" actions: new, update, and delete.', '')); $question = new ConfirmationQuestion($questionHelper->getQuestion('Do you want to generate the "write" actions', $withWrite ? 'yes' : 'no', '?', $withWrite), $withWrite); $withWrite = $questionHelper->ask($input, $output, $question); $input->setOption('with-write', $withWrite); // format $format = $input->getOption('format'); $output->writeln(array('', 'Determine the format to use for the generated CRUD.', '')); $question = new Question($questionHelper->getQuestion('Configuration format (yml, xml, php, or annotation)', $format), $format); $question->setValidator(array('Sensio\\Bundle\\GeneratorBundle\\Command\\Validators', 'validateFormat')); $format = $questionHelper->ask($input, $output, $question); $input->setOption('format', $format); // route prefix $prefix = $this->getRoutePrefix($input, $entity); $output->writeln(array('', 'Determine the routes prefix (all the routes will be "mounted" under this', 'prefix: /prefix/, /prefix/new, ...).', '')); $prefix = $questionHelper->ask($input, $output, new Question($questionHelper->getQuestion('Routes prefix', '/' . $prefix), '/' . $prefix)); $input->setOption('route-prefix', $prefix); // summary $output->writeln(array('', $this->getHelper('formatter')->formatBlock('Summary before generation', 'bg=blue;fg=white', true), '', sprintf('You are going to generate a CRUD controller for "<info>%s:%s</info>"', $bundle, $entity), sprintf('using the "<info>%s</info>" format.', $format), '')); }