Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new ConsoleIO($input, $output);
     $this->welcomeMessage($io);
     $title = $io->askAndValidate('Post title', function ($answer) {
         return Validators::validatePostTitle($answer);
     }, false, $input->getOption('title'));
     $input->setOption('title', $title);
     $layout = $io->ask('Post layout', $input->getOption('layout'));
     $input->setOption('layout', $layout);
     $defaultDate = $input->getOption('date');
     if (empty($defaultDate) === true) {
         $defaultDate = $this->getDateFormated();
     }
     $date = $io->ask('Post date', $defaultDate);
     $input->setOption('date', $date);
     if ($io->askConfirmation('Do you want to use tags?', empty($input->getOption('tags')) === false)) {
         $tags = $io->ask('Comma separated list of post tags', $input->getOption('tags'));
         $input->setOption('tags', $tags);
     }
     if ($io->askConfirmation('Do you want to use categories?', empty($input->getOption('categories')) === false)) {
         $categories = $io->ask('Comma separated list of post categories', $input->getOption('categories'));
         $input->setOption('categories', $categories);
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $io = new ConsoleIO($input, $output, $this->getHelperSet());
     $this->welcomeMessage($io);
     $title = $input->getOption('title');
     $question = new Question('Post title: ', $title);
     $question->setMaxAttempts(null);
     $question->setValidator(function ($answer) {
         return Validators::validatePostTitle($answer);
     });
     $title = $helper->ask($input, $output, $question);
     $input->setOption('title', $title);
     $layout = $input->getOption('layout');
     $question = new Question('Post layout: ', $layout);
     $layout = $helper->ask($input, $output, $question);
     $input->setOption('layout', $layout);
     $date = $input->getOption('date') ?: $this->getDateFormated();
     $question = new Question("Post date ({$date}): ", $date);
     $date = $helper->ask($input, $output, $question);
     $input->setOption('date', $date);
     $tags = $input->getOption('tags') ?: '';
     $question = new Question('Comma separated list of post tags: ', $tags);
     $tags = $helper->ask($input, $output, $question);
     $input->setOption('tags', $tags);
     $categories = $input->getOption('categories') ?: '';
     $question = new Question('Comma separated list of post categories: ', $categories);
     $categories = $helper->ask($input, $output, $question);
     $input->setOption('categories', $categories);
 }
Exemplo n.º 3
0
 public function testValidatePostTitle()
 {
     $this->assertEquals('The title', Validators::validatePostTitle('The title'));
 }