private function getStop($value, $question = 'Which station ?') { $stops = $this->cff->getStop($value, false); if ($stops[0]['value'] != $value) { $values = array_column($stops, 'value'); $value = $this->io->choice($question, $values, $stops[0]['value']); $key = array_search($value, $values); return $stops[$key]; } return $stops[0]; }
/** * @param Bundle[] $bundles * * @return Bundle|null */ private function selectBundle(array $bundles) { $packageNames = array_map(function (Bundle $bundle) { return $bundle->getName(); }, $bundles); $selectedName = $this->io->choice('Please select the package, where you want to place the Migration file', $packageNames, $this->getContainer()->getParameter('campaignchain_update.diff_package')); $this->io->text('You have selected: ' . $selectedName); $selectedBundle = null; foreach ($bundles as $bundle) { if ($bundle->getName() != $selectedName) { continue; } $selectedBundle = $bundle; break; } return $selectedBundle; }
/** * @inheritDoc */ protected function execute(InputInterface $input, OutputInterface $output) { $helper = new SymfonyStyle($input, $output); $helper->title('Doctrine'); $choices = [self::ACTION_DATABASE_IMPORT => 'Import database from remote host']; $todo = $helper->choice('Select action', $choices); $helper->newLine(4); $helper->section($choices[$todo]); $this->executeChoice($helper, $todo); CommandUtility::writeFinishedMessage($helper, self::NAME); }
/** * @inheritDoc */ protected function execute(InputInterface $input, OutputInterface $output) { $helper = new SymfonyStyle($input, $output); $helper->title('FOSUserBundle'); $choices = [self::ACTION_PASSWORD_REPLACE => 'Replace all passwords (be careful!)']; $todo = $helper->choice('Select action', $choices); $helper->newLine(4); $helper->section($choices[$todo]); $this->executeChoice($helper, $todo); CommandUtility::writeFinishedMessage($helper, self::NAME); }
/** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); // --title option if (!$input->getOption('title')) { $input->setOption('title', $io->ask('Enter the title of the page')); } // --extension option if (!$input->getOption('extension')) { $input->setOption('extension', $io->choice('Which file extension?', ['md', 'html.twig', 'twig', 'html'])); } // --fieldname option if (!$input->getOption('filename')) { $input->setOption('filename', $io->ask('Enter the name of the file', str_replace(' ', self::FILENAME_SEPARATOR, strtolower($input->getOption('title'))) . '.' . $input->getOption('extension'))); } }
private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, $name) { if ($builder->has($name) || !$input->isInteractive()) { return $name; } $matchingServices = $this->findServiceIdsContaining($builder, $name); if (empty($matchingServices)) { throw new \InvalidArgumentException(sprintf('No services found that match "%s".', $name)); } $default = 1 === count($matchingServices) ? $matchingServices[0] : null; return $io->choice('Select one of the following services to display its information', $matchingServices, $default); }
private function selectWorkingLocale() { $this->workingLocale = $this->formatter->choice('What locale would you like to configure', $this->getInstallableLocale()); }
<?php use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; //Ensure questions do not output anything when input is non-interactive return function (InputInterface $input, OutputInterface $output) { $output = new SymfonyStyle($input, $output); $output->title('Title'); $output->askHidden('Hidden question'); $output->choice('Choice question with default', array('choice1', 'choice2'), 'choice1'); $output->confirm('Confirmation with yes default', true); $output->text('Duis aute irure dolor in reprehenderit in voluptate velit esse'); };