Symfony\Component\Console\Style\SymfonyStyle::ask PHP Method

ask() public method

public ask ( $question, $default = null, $validator = null )
    public function ask($question, $default = null, $validator = null)
    {
        $question = new Question($question, $default);
        $question->setValidator($validator);

        return $this->askQuestion($question);
    }

Usage Example

 public function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $bundle = $input->getArgument('bundle');
     $name = $input->getArgument('name');
     $container = $this->getContainer();
     if (null !== $bundle && null !== $name) {
         return;
     }
     $io->title('Generate new RPC method');
     // Bundle name
     $bundle = $io->ask('Bundle name', null, function ($answer) use($container) {
         try {
             $container->get('kernel')->getBundle($answer);
         } catch (\Exception $e) {
             throw new \RuntimeException(sprintf('Bundle "%s" does not exist.', $answer));
         }
         return $answer;
     });
     $input->setArgument('bundle', $bundle);
     // Method name
     $name = $io->ask('Method name', null, function ($answer) use($container, $bundle) {
         if (empty($answer)) {
             throw new \RuntimeException('Method name can`t be empty.');
         }
         $answer = str_replace(' ', ':', $answer);
         if ($this->isMethodExist($container->get('kernel')->getBundle($bundle), $answer)) {
             throw new \RuntimeException(sprintf('Method "%s" already exist.', $answer));
         }
         return $answer;
     });
     $input->setArgument('name', $name);
 }
All Usage Examples Of Symfony\Component\Console\Style\SymfonyStyle::ask