Ejemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var WardenSetupService $wardenSetupService */
     $wardenSetupService = $this->getContainer()->get('warden_setup');
     /** @var UserProviderService $userProviderService */
     $userProviderService = $this->getContainer()->get('user_provider');
     if ($userProviderService->isSetup() && !$input->getOption('regenerate')) {
         $output->writeln('Warden username and password is already setup - check the README file if you need to regenerate.');
         return;
     }
     $helper = $this->getHelper('question');
     $usernameQuestion = new Question('Please enter the admin username [admin]: ', 'admin');
     $username = $helper->ask($input, $output, $usernameQuestion);
     $passwordQuestion = new Question('Please enter the admin password (minimum of 8 characters): ', '');
     $passwordQuestion->setValidator(function ($value) {
         if (trim($value) == '') {
             throw new \Exception('The password can not be empty');
         }
         if (strlen($value) < 8) {
             throw new \Exception('Password provided is too short - must be minimum of 8 characters');
         }
         return $value;
     });
     $passwordQuestion->setMaxAttempts(3);
     $passwordQuestion->setHidden(TRUE);
     $passwordQuestion->setHiddenFallback(FALSE);
     $password = $helper->ask($input, $output, $passwordQuestion);
     $output->writeln(' - Setting up the password file ...');
     $userProviderService->generateLoginFile($username, $password);
     $output->writeln(' - Setting up the CSS file ...');
     $wardenSetupService->generateCSSFile();
     $output->writeln('Warden installation complete.');
 }
Ejemplo n.º 2
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @throws \Exception
  * @throws \Symfony\Component\Console\Exception\ExceptionInterface
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     # print the status list
     /** @var StatusCommand $command */
     $command = $this->getApplication()->find('status');
     $statusInput = new ArrayInput(array(), $command->getDefinition());
     $command->run($statusInput, $output);
     foreach (array_keys($this->actions) as $name) {
         # ask with boxes to handle
         $helper = $this->getHelper('question');
         $question = new Question('<fg=yellow>' . "Select box/boxes to " . $name . ' []:</> ', null);
         $question->setMaxAttempts(5);
         # set up validation for the question
         $question->setValidator(function ($answer) {
             $vagrant = new Vagrant();
             # check if the answer can be resolved
             if ($answer != "" && !count($vagrant->resolveStr($answer))) {
                 throw new \RuntimeException('Your selection does not match any boxes');
             }
             return $answer;
         });
         # if we have an answer, set it as an argument, and move on
         if ($answer = $helper->ask($input, $output, $question)) {
             $this->actions[$name]["boxes"] = $answer;
         }
     }
 }
Ejemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question('Please enter app\'s shared secret: ');
     $question->setValidator(function ($answer) {
         if (empty($answer)) {
             throw new RuntimeException('Shared secret must be provided');
         }
         return $answer;
     });
     $question->setHidden(true);
     $question->setMaxAttempts(2);
     $sharedSecret = $helper->ask($input, $output, $question);
     $receiptFile = __DIR__ . '/../../../tmp/receipt';
     if (!is_file(realpath($receiptFile))) {
         throw new RuntimeException(sprintf('Create a file with receipt data here %s', $receiptFile));
     }
     $receiptData = file_get_contents($receiptFile);
     if (empty($receiptData)) {
         throw new RuntimeException(sprintf('Put receipt data here %s', $receiptFile));
     }
     $validator = new Validator();
     $validator->setSecret($sharedSecret);
     $validator->setReceiptData($receiptData);
     $response = $validator->validate();
     var_dump($response);
 }
Ejemplo n.º 4
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     if ($input->hasOption("browse") && $input->getOption("browse")) {
         # print the status list
         $command = $this->getApplication()->find('status');
         $statusInput = new ArrayInput(array(), $command->getDefinition());
         $command->run($statusInput, $output);
         # ask with boxes to handle
         $helper = $this->getHelper('question');
         $question = new Question('<fg=yellow>' . "Select box/boxes to " . $this->action . ':</> ', null);
         $question->setMaxAttempts(5);
         # set up validation for the question
         $question->setValidator(function ($answer) {
             $vagrant = new Vagrant();
             # check if the answer can be resolved
             if (!count($vagrant->resolveStr($answer))) {
                 throw new \RuntimeException('Your selection does not match any boxes');
             }
             return $answer;
         });
         # if we have an answer, set it as an argument, and move on
         if ($answer = $helper->ask($input, $output, $question)) {
             $input->setArgument("identifier", $answer);
         }
     }
 }
 /**
  *
  * TODO Provide extensibility to list of Sugar 7 boxes (allow hard coding, usage of a web service, etc.)
  * {inheritDoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $box = $input->getArgument('box');
     if (empty($box)) {
         $output->writeln('You MUST provide a <info>Vagrant Box Name</info> for your Sugar instance.');
         $output->writeln('<comment>You may pick one from below OR provide your own.</comment>');
         $table = new Table($output);
         $table->setHeaders(array('Box Name', 'PHP', 'Apache', 'MySQL', 'Elasticsearch', 'OS'));
         $table->addRow(['mmarum/sugar7-php54', '5.4.x', '2.2.x', '5.5.x', '1.4.x', 'Ubuntu 12.04']);
         $table->addRow(['mmarum/sugar7-php53', '5.3.x', '2.2.x', '5.5.x', '1.4.x', 'Ubuntu 12.04']);
         $table->render();
         $helper = $this->getHelper('question');
         $question = new Question('<info>Name of Vagrant Box?</info> <comment>[mmarum/sugar7-php54]</comment> ', 'mmarum/sugar7-php54');
         $question->setValidator(function ($answer) {
             if (empty($answer)) {
                 throw new \RuntimeException('You must provide a Box Name to continue!');
             }
             return $answer;
         });
         $question->setMaxAttempts(2);
         $box = $helper->ask($input, $output, $question);
         $input->setArgument('box', $box);
     }
     $output->writeln("<info>Using {$box} ...</info>");
 }
Ejemplo n.º 6
0
 /**
  * @return SimpleQuestion
  */
 private function buildQuestion()
 {
     $question = new SimpleQuestion('<question>Enter your project homepage:</question>');
     $question->setValidator($this->buildValidator());
     $question->setMaxAttempts(3);
     return $question;
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     if (trim($input->getOption('name')) == '') {
         $question = new Question\Question('Please enter the client name: ');
         $question->setValidator(function ($value) {
             if (trim($value) == '') {
                 throw new \Exception('The client name can not be empty');
             }
             $doctrine = $this->getContainer()->get('doctrine');
             $client = $doctrine->getRepository('AppBundle:Client')->findOneBy(['name' => $value]);
             if ($client instanceof \AppBundle\Entity\Client) {
                 throw new \Exception('The client name must be unique');
             }
             return $value;
         });
         $question->setMaxAttempts(5);
         $input->setOption('name', $helper->ask($input, $output, $question));
     }
     $grants = $input->getOption('grant-type');
     if (!(is_array($grants) && count($grants))) {
         $question = new Question\ChoiceQuestion('Please select the grant types (defaults to password and facebook_access_token): ', [\OAuth2\OAuth2::GRANT_TYPE_AUTH_CODE, \OAuth2\OAuth2::GRANT_TYPE_CLIENT_CREDENTIALS, \OAuth2\OAuth2::GRANT_TYPE_EXTENSIONS, \OAuth2\OAuth2::GRANT_TYPE_IMPLICIT, \OAuth2\OAuth2::GRANT_TYPE_REFRESH_TOKEN, \OAuth2\OAuth2::GRANT_TYPE_USER_CREDENTIALS, 'http://grants.api.schoolmanager.ledo.eu.org/facebook_access_token'], '5,6');
         $question->setMultiselect(true);
         $question->setMaxAttempts(5);
         $input->setOption('grant-type', $helper->ask($input, $output, $question));
     }
     parent::interact($input, $output);
 }
Ejemplo n.º 8
0
 /**
  * Informs the display about the structure of a Field.
  * 
  * Each time the Field structure changes for some reason, this method shall
  * be called.
  *
  * @param \Feeld\Display\DisplayDataSourceInterface $field
  * @throws Exception
  */
 public function informAboutStructure(\Feeld\Display\DisplayDataSourceInterface $field)
 {
     parent::informAboutStructure($field);
     $this->field = $field;
     if ($field instanceof \Feeld\Field\Entry) {
         $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
     } elseif ($field instanceof \Feeld\Field\Select) {
         $this->symfonyQuestion = new \Symfony\Component\Console\Question\ChoiceQuestion((string) $this, array_keys($field->getOptions()), $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
         if ($field instanceof \Feeld\Field\CommonProperties\MultipleChoiceInterface && $field->isMultipleChoice()) {
             $field->symfonyQuestion->setMultiselect(true);
         }
     } elseif ($field instanceof \Feeld\Field\CloakedEntry) {
         $this->symfonyQuestion = new SymfonyQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : null);
         $this->symfonyQuestion->setHidden(true);
     } elseif ($field instanceof \Feeld\Field\Constant) {
         throw new Exception('Constants are currently not supported in SymfonyConsoleDisplay');
     } elseif ($field instanceof \Feeld\Field\Checkbox) {
         $this->symfonyQuestion = new \Symfony\Component\Console\Question\ConfirmationQuestion((string) $this, $field instanceof DefaultValueInterface && $field->hasDefault() ? $field->getDefault() : true, '/^' . strtolower(substr($this->getTrueOption(), 0, 1)) . '/i');
     }
     $this->symfonyQuestion->setNormalizer(function ($value) {
         return $this->field->getSanitizer()->filter($value);
     });
     $this->symfonyQuestion->setValidator(function ($value) {
         $validationResultSet = $this->field->validateValue($value);
         if ($validationResultSet->hasErrors()) {
             $this->field->clearValidationResult();
             throw new \Exception(implode(PHP_EOL, $validationResultSet->getErrorMessages()));
         }
         return $this->field->getFilteredValue();
     });
     $this->symfonyQuestion->setMaxAttempts(null);
 }
Ejemplo n.º 9
0
 /**
  * @return SimpleQuestion
  */
 private function buildQuestion()
 {
     $question = new SimpleQuestion('<question>Enter your project name (<vendor>/<package>):</question>');
     $question->setValidator($this->buildValidator());
     $question->setMaxAttempts(3);
     return $question;
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function interact(InputInterface $input, OutputInterface $output)
 {
     if (null !== $input->getOption('more-than-days') && null !== $input->getOption('less-than-days')) {
         throw new InvalidArgumentException('Options --more-than-days and --less-than-days cannot be used together.');
     }
     if (null === $input->getOption('more-than-days') && null === $input->getOption('less-than-days')) {
         $input->setOption('more-than-days', self::DEFAULT_MORE_THAN_DAYS);
     }
     $resourceFQCN = $input->hasArgument('entity') ? $input->getArgument('entity') : null;
     $isForced = $input->getOption('force');
     if (null !== $resourceFQCN && !class_exists($resourceFQCN)) {
         $errorCallback = function ($resourceFQCN) use($output) {
             $output->writeln('<info>Abort the purge operation. Nothing has been deleted from the database.</info>');
             throw new InvalidArgumentException(sprintf('Entity %s is not a valid fully qualified class name.', $resourceFQCN));
         };
         $output->writeln(sprintf('<info>"%s" is not a valid resource name.</info>', $resourceFQCN));
         if ($isForced) {
             $errorCallback($resourceFQCN);
         }
         $helper = $this->getHelper('question');
         $question = new Question('<question>Please insert a valid fully qualified class name: </question>');
         $question->setValidator(function ($answer) {
             if (!class_exists($answer)) {
                 throw new \RuntimeException('The fully qualified class name does not exist. Please choose a value from the table above.');
             }
             return $answer;
         });
         $question->setMaxAttempts(2);
         $resourceFQCN = $helper->ask($input, $output, $question);
         if (!$resourceFQCN) {
             $errorCallback($resourceFQCN);
         }
         $input->setArgument('entity', $resourceFQCN);
     }
 }
Ejemplo n.º 11
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);
 }
 private function confirmSend($input, $output)
 {
     //Symfony の Console コンポーネ ントには、確認プロンプトを出したり、
     //そこでの入力値をバリデーションしたりするための機能が
     // Questionとして組み込まれています。
     $qHelper = $this->getHelper('question');
     //Question クラス
     $question = new Question('通知メールを送信しますか? [y/n]: ', null);
     //setValidator( )メソッドに、バリデーション時に呼び出すコールバックを渡します
     //引数:入力された値
     //戻り値:正常な場合はバリデーション後の値、エラーがある場合は例外をスロー
     $question->setValidator(function ($answer) {
         //strtolower 大文字を小文字に substrは$answerの0番目の1文字を返す
         $answer = strtolower(substr($answer, 0, 1));
         if (!in_array($answer, ['y', 'n'])) {
             throw new \RuntimeException('yまたはnを入力してください');
         }
         return $answer;
     });
     //❺許容する試行回数の設定
     $question->setMaxAttempts(3);
     //プロンプトを表示して回答を得る
     //Questionヘルパのask( )メソッドを呼び出します。ask( )メソッドの戻り値は、
     //入力バリデーション後の値です。これが'y'だった場合は、confirmSend( )メソッドの戻り値として
     // true が返るようにしています。
     return $qHelper->ask($input, $output, $question) == 'y';
 }
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getHelper('question');
     $question = new Question($this->getQuestion('Enter a comma separated list of the models you want to create the pivot table for', $input->getOption('models')), $input->getOption('models'));
     $question->setValidator(function ($answer) {
         $answer = array_map(function ($el) {
             return trim($el);
         }, explode(',', $answer));
         if (2 != count($answer)) {
             throw new \RuntimeException('This Option requires exactly 2 models');
         }
         return $answer;
     });
     $question->setMaxAttempts(3);
     $models = $questionHelper->ask($input, $output, $question);
     $table = $input->getOption('table');
     if (!$table) {
         $table = 'tl_' . strtolower($models[0]) . '_' . strtolower($models[1]);
     }
     $question = new Question($this->getQuestion('Enter the name of the table being created', $table), $table);
     $question->setValidator(function ($answer) {
         if ('tl_' !== substr($answer, 0, 3)) {
             throw new \RuntimeException('The name of the table should be prefixed with \'tl_\'');
         }
         return $answer;
     });
     $question->setMaxAttempts(3);
     $table = $questionHelper->ask($input, $output, $question);
     $question = new Question($this->getQuestion('Enter the relative path to your contao bundle', './src'), './src');
     $base = $questionHelper->ask($input, $output, $question);
     $this->parameters = ['models' => $models, 'table' => $table, 'base' => $base];
 }
Ejemplo n.º 14
0
 /**
  * Executes the command.
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!$this->getGitHelper()->available()) {
         throw new \Exception('Is not a git project.');
     }
     $git = $this->getGitHelper();
     do {
         $tags = $git->getTags();
         foreach ($tags as $id => $tagName) {
             $output->writeln(sprintf('[%s] %s', $id, $tagName));
         }
         /* @var $question \Symfony\Component\Console\Helper\QuestionHelper */
         $question = $this->getHelper('question');
         $tagQuestion = new Question('Which branch should deleted? ');
         $tagQuestion->setValidator(function ($answer) use($tags) {
             if (!isset($tags[$answer])) {
                 throw new \Exception($answer . ' is not a valid value');
             }
         });
         $tagQuestion->setMaxAttempts(3);
         $answer = $question->ask($input, $output, $tagQuestion);
         $git->deleteTag($tags[$answer]);
         $deleteOtherTagQuestion = new Question('Delete another tag/branch? [y/n]: ');
         $deleteOtherTag = $question->ask($input, $output, $deleteOtherTagQuestion);
     } while (strtolower(substr($deleteOtherTag, 0, 1)) == 'y');
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function ask(InputInterface $input, OutputInterface $output, Question $question)
 {
     if (null !== $this->attempts && null === $question->getMaxAttempts()) {
         $question->setMaxAttempts($this->attempts);
     }
     return QuestionHelper::ask($input, $output, $question);
 }
Ejemplo n.º 16
0
 /**
  * @return SimpleQuestion
  */
 private function buildAuthorQuestion()
 {
     $question = new SimpleQuestion('<question>Enter the author (name <*****@*****.**>):</question>');
     $question->setValidator($this->buildValidator());
     $question->setMaxAttempts(3);
     return $question;
 }
 /**
  * Get the question object with a formatted question
  *
  * @param string          $message        Question message
  * @param string|int|null $default
  * @param array           $options
  * @param bool            $required
  * @param bool            $useOptionValue Value from options should be considered as an answer
  * @return \Symfony\Component\Console\Question\Question
  */
 public function getQuestion($message, $default = null, array $options = array(), $required = true, $useOptionValue = true)
 {
     $default = !$useOptionValue && $this->isList($options) && $default !== null ? $options[$default] : $default;
     $question = new Question($this->getFormattedQuestion($message, $default, $options), $default);
     $question->setMaxAttempts(self::MAX_ATTEMPTS);
     $question->setValidator($this->getValidator($options, $required, $useOptionValue));
     return $question;
 }
Ejemplo n.º 18
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $question = new SimpleQuestion('<question>Enter your project description:</question>');
     $question->setValidator($this->buildValidator());
     $question->setMaxAttempts(3);
     $this->getProject()->setDescription($this->ask($input, $output, $question));
     return $this->getProject()->getDescription() ? ITask::NO_ERROR_CODE : ITask::BLOCKING_ERROR_CODE;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = [];
     $helper = $this->getHelper('question');
     $target = new Question('<info>Please enter the install name : </info>', 'php70');
     $target->setValidator(function ($answer) {
         if ($this->getApplication()->phpInstallExists($answer)) {
             throw new \RuntimeException('This install name already exists !');
         }
         return $answer;
     });
     $target->setMaxAttempts(2);
     $name = $helper->ask($input, $output, $target);
     $tmp_dir = new Question('<info>Please enter the temporary folder : </info>', 'c:\\sites\\outils');
     $tmp_dir->setValidator(function ($answer) {
         if (!file_exists($answer)) {
             throw new \RuntimeException('The temporary folder does not exists !');
         }
         return $answer;
     });
     $tmp_dir->setMaxAttempts(2);
     $config['tmp_dir'] = $helper->ask($input, $output, $tmp_dir);
     $php_dir = new Question('<info>Please enter the PHP folder : </info>', 'c:\\sites\\outils');
     $php_dir->setValidator(function ($answer) {
         if (!file_exists($answer)) {
             throw new \RuntimeException('The PHP folder does not exists !');
         }
         if (null !== $this->getApplication()->configFromPhpDir($answer)) {
             throw new \RuntimeException('The PHP folder is already used in another configuration !');
         }
         return $answer;
     });
     $php_dir->setMaxAttempts(2);
     $config['php_dir'] = $helper->ask($input, $output, $php_dir);
     $backup_dir = new Question('<info>Please enter the backup folder : </info>', 'c:\\sites\\outils');
     $backup_dir->setValidator(function ($answer) {
         if (!file_exists($answer)) {
             throw new \RuntimeException('The backup folder does not exists !');
         }
         return $answer;
     });
     $backup_dir->setMaxAttempts(2);
     $config['backup_dir'] = $helper->ask($input, $output, $backup_dir);
     $php_branch = new Question('<info>PHP branch : </info>', 'php56');
     $app = $this->getApplication();
     $php_branch->setValidator(function ($answer) use($app) {
         if (!$app->getSources()->branchExists($answer)) {
             throw new \RuntimeException('The branch does not exists !');
         }
         return $answer;
     });
     $php_branch->setMaxAttempts(2);
     $config['php_branch'] = $helper->ask($input, $output, $php_branch);
     $app->addPhpInstall($name, $config);
     //['install' => [$name => $config]]);
     $app->saveCurrentConfig();
     $output->writeln('<comment>Configuration  end. Use \'config:show\' command for check configuration.</comment>');
 }
Ejemplo n.º 20
0
 /**
  * This method is executed after initialize() and before execute(). Its purpose
  * is to check if some of the options/arguments are missing and interactively
  * ask the user for those values.
  *
  * This method is completely optional. If you are developing an internal console
  * command, you probably should not implement this method because it requires
  * quite a lot of work. However, if the command is meant to be used by external
  * users, this method is a nice way to fall back and prevent errors.
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     if (null !== $input->getArgument('name') && null !== $input->getArgument('urlName') && null !== $input->getArgument('description') && null !== $input->getArgument('parent')) {
         return;
     }
     // multi-line messages can be displayed this way...
     $output->writeln('');
     $output->writeln('Add Category Command Interactive Wizard');
     $output->writeln('-----------------------------------');
     // ...but you can also pass an array of strings to the writeln() method
     $output->writeln(array('', 'If you prefer to not use this interactive wizard, provide the', 'arguments required by this command as follows:', '', ' $ php app/console app:add-user name urlName description parent', ''));
     $output->writeln(array('', 'Now we\'ll ask you for the value of all the missing command arguments.', ''));
     // See http://symfony.com/doc/current/components/console/helpers/questionhelper.html
     $console = $this->getHelper('question');
     // Ask for the username if it's not defined
     $name = $input->getArgument('name');
     if (null === $name) {
         $question = new Question(' > <info>Name</info>: ');
         $question->setValidator(function ($answer) {
             if (empty($answer)) {
                 throw new \RuntimeException('The name cannot be empty');
             }
             return $answer;
         });
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $name = $console->ask($input, $output, $question);
         $input->setArgument('name', $name);
     } else {
         $output->writeln(' > <info>Name</info>: ' . $name);
     }
     // Ask for the username if it's not defined
     $urlName = $input->getArgument('urlName');
     if (null === $urlName) {
         $question = new Question(' > <info>urlName</info> or leave empty to use name as urlName: ');
         $urlName = $console->ask($input, $output, $question);
         $input->setArgument('urlName', $urlName);
     } else {
         $output->writeln(' > <info>urlName</info>: ' . $urlName);
     }
     // Ask for the username if it's not defined
     $description = $input->getArgument('description');
     if (null === $description) {
         $question = new Question(' > <info>description</info> optional: ');
         $description = $console->ask($input, $output, $question);
         $input->setArgument('description', $description);
     } else {
         $output->writeln(' > <info>description</info>: ' . $description);
     }
     // Ask for the username if it's not defined
     $parent = $input->getArgument('parent');
     if (null === $parent) {
         $question = new Question(' > <info>parent</info> optional: ');
         $parent = $console->ask($input, $output, $question);
         $input->setArgument('parent', $parent);
     } else {
         $output->writeln(' > <info>description</info>: ' . $parent);
     }
 }
 /**
  * @param string   $question
  * @param \Closure $validator
  * @param null     $attempts
  * @param null     $default
  *
  * @return string
  */
 protected function askAndValidate($question, $validator, $attempts = null, $default = null)
 {
     /** @var QuestionHelper $helper */
     $helper = $this->helperSet->get('question');
     $question = new Question($question, $default);
     $question->setValidator($validator);
     $question->setMaxAttempts($attempts);
     return $helper->ask($this->input, $this->getErrorOutput(), $question);
 }
 protected function configureAccount(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question('Your email address: ');
     $question->setValidator(function ($answer) {
         if (empty($answer) || !filter_var($answer, FILTER_VALIDATE_EMAIL)) {
             throw new \RunTimeException('Please provide a valid email address.');
         }
         return $answer;
     });
     $question->setMaxAttempts(5);
     $email = $helper->ask($input, $output, $question);
     $userExists = true;
     if (!$userExists) {
         $createAccountText = "\nThis email address is not associated with a Platform.sh account. \n";
         $createAccountText .= 'Would you like to create a new account?';
         $createAccount = $helper->confirm($createAccountText, $input, $output);
         if ($createAccount) {
             // @todo
         } else {
             // Start from the beginning.
             $this->configureAccount($input, $output);
             return;
         }
     }
     $pendingInvitation = false;
     if ($pendingInvitation) {
         $resendInviteText = "\nThis email address is associated with a Platform.sh account, \n";
         $resendInviteText .= "but you haven't verified your email address yet. \n";
         $resendInviteText .= "Please click on the link in the email we sent you. \n";
         $resendInviteText .= "Do you want us to send you the email again?";
         $resendInvite = $helper->confirm($resendInviteText, $input, $output, false);
         if ($resendInvite) {
             // @todo
         }
         return;
     }
     $question = new Question('Your password: '******'') {
             throw new \RuntimeException('The password cannot be empty');
         }
         return $answer;
     });
     $question->setHidden(true);
     $question->setMaxAttempts(5);
     $password = $helper->ask($input, $output, $question);
     try {
         $this->authenticateUser($email, $password);
     } catch (\InvalidArgumentException $e) {
         $output->writeln("\n<error>Login failed. Please check your credentials.</error>\n");
         $output->writeln("Forgot your password? Visit: <comment>https://marketplace.commerceguys.com/user/password</comment>\n");
         $this->configureAccount($input, $output);
     }
 }
Ejemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $io = new ConsoleIO($input, $output, $this->getHelperSet());
     $this->welcomeMessage($io);
     $name = $input->getOption('name');
     $question = new Question('Plugin name <info>(follow the pattern</info> <comment>"vendor-name/plugin-name"</comment><info>)</info>: ', $name);
     $question->setMaxAttempts(null);
     $question->setValidator(function ($answer) {
         return Validators::validatePluginName($answer);
     });
     $name = $helper->ask($input, $output, $question);
     $input->setOption('name', $name);
     $question = new ConfirmationQuestion('Is it a command plugin?[<comment>n</comment>]: ', false);
     $isCommandPlugin = $helper->ask($input, $output, $question);
     if ($isCommandPlugin === true) {
         $commandName = $input->getOption('command-name');
         $question = new Question('Name of the command: ', $commandName);
         $question->setMaxAttempts(null);
         $question->setValidator(function ($answer) {
             return Validators::validateCommandName($answer);
         });
         $commandName = $helper->ask($input, $output, $question);
         $input->setOption('command-name', $commandName);
         $commandDescription = $input->getOption('command-description');
         $question = new Question('Description for the command: ', $commandDescription);
         $commandDescription = $helper->ask($input, $output, $question);
         $input->setOption('command-description', $commandDescription);
         $commandHelp = $input->getOption('command-help');
         $question = new Question('Help for the command: ', $commandHelp);
         $commandHelp = $helper->ask($input, $output, $question);
         $input->setOption('command-help', $commandHelp);
     }
     $author = $input->getOption('author');
     $question = new Question('Plugin author: ', $author);
     $author = $helper->ask($input, $output, $question);
     $input->setOption('author', $author);
     $email = $input->getOption('email');
     $question = new Question('Email author: ', $email);
     $question->setValidator(function ($answer) {
         return Validators::validateEmail($answer, true);
     });
     $email = $helper->ask($input, $output, $question);
     $input->setOption('email', $email);
     $description = $input->getOption('description');
     $question = new Question('Plugin description: ', $description);
     $description = $helper->ask($input, $output, $question);
     $input->setOption('description', $description);
     $this->licenseMessage($io);
     $license = $input->getOption('license');
     $question = new Question('Plugin license [<comment>MIT</comment>]: ', $license);
     $license = $helper->ask($input, $output, $question);
     $input->setOption('license', $license);
 }
Ejemplo n.º 24
0
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     if (null !== $input->getArgument('username') && null !== $input->getArgument('password') && null !== $input->getArgument('email')) {
         return;
     }
     // multi-line messages can be displayed this way...
     $output->writeln('');
     $output->writeln('Add User Command Interactive Wizard');
     $output->writeln('-----------------------------------');
     // ...but you can also pass an array of strings to the writeln() method
     $output->writeln(array('', 'If you prefer to not use this interactive wizard, provide the', 'arguments required by this command as follows:', '', ' $ php app/console app:add-user username password email@example.com --isAdmin', ''));
     $output->writeln(array('', 'Now we\'ll ask you for the value of all the missing command arguments.', ''));
     // See http://symfony.com/doc/current/components/console/helpers/questionhelper.html
     $console = $this->getHelper('question');
     // Ask for the username if it's not defined
     $username = $input->getArgument('username');
     if (null === $username) {
         $question = new Question(' > <info>Username</info>: ');
         $question->setValidator(function ($answer) {
             if (empty($answer)) {
                 throw new \RuntimeException('The username cannot be empty');
             }
             return $answer;
         });
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $username = $console->ask($input, $output, $question);
         $input->setArgument('username', $username);
     } else {
         $output->writeln(' > <info>Username</info>: ' . $username);
     }
     // Ask for the password if it's not defined
     $password = $input->getArgument('password');
     if (null === $password) {
         $question = new Question(' > <info>Password</info> (your type will be hidden): ');
         $question->setValidator(array($this, 'passwordValidator'));
         $question->setHidden(true);
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $password = $console->ask($input, $output, $question);
         $input->setArgument('password', $password);
     } else {
         $output->writeln(' > <info>Password</info>: ' . str_repeat('*', strlen($password)));
     }
     // Ask for the email if it's not defined
     $email = $input->getArgument('email');
     if (null === $email) {
         $question = new Question(' > <info>Email</info>: ');
         $question->setValidator(array($this, 'emailValidator'));
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $email = $console->ask($input, $output, $question);
         $input->setArgument('email', $email);
     } else {
         $output->writeln(' > <info>Email</info>: ' . $email);
     }
 }
Ejemplo n.º 25
0
 /**
  * @return Question
  */
 public function createSendCommandsToRoverQuestion()
 {
     $question = new Question('Move the rover: ');
     $question->setMaxAttempts(self::MAX_ATTEMPTS)->setValidator(function ($answer) {
         if (!$this->inputValidator->validateAllowedChars($answer, Rover::COMMANDS)) {
             throw new RuntimeException('Commands are invalid');
         }
         return str_split($answer);
     });
     return $question;
 }
Ejemplo n.º 26
0
 public function askQuestion($question, $default = null, $attempts = null, $validator = null)
 {
     $question = new Question($question, $default);
     if ($attempts) {
         $question->setMaxAttempts($attempts);
     }
     if ($validator) {
         $question->setValidator($validator);
     }
     return $this->ask($question);
 }
Ejemplo n.º 27
0
 public function interact(InputInterface $input, OutputInterface $output)
 {
     if (null !== $input->getArgument('username') && null !== $input->getArgument('password') && null !== $input->getArgument('email') && null !== $input->getArgument('name')) {
         return;
     }
     $output->writeln('');
     $output->writeln('Add User Command Interactive Wizard');
     $output->writeln('-----------------------------------');
     $output->writeln(array('', 'If you prefer to not use this interactive wizard, provide the', 'arguments required by this command as follows:', '', ' $ php app/console gitdown-wiki:add-user username password email@example.com', ''));
     $output->writeln(array('', 'Please insert the missing data', ''));
     $console = $this->getHelper('question');
     if (null === ($username = $input->getArgument('username'))) {
         $question = new Question(' > <info>Username</>: ');
         $question->setValidator(function ($answer) {
             if (empty($answer)) {
                 throw new \RuntimeException('The username cannot be empty');
             }
             return $answer;
         });
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $username = $console->ask($input, $output, $question);
         $input->setArgument('username', $username);
     } else {
         $output->writeln(' > <info>Username</>: ' . $username);
     }
     if (null === ($password = $input->getArgument('password'))) {
         $question = new Question(' > <info>Password</> (your type will be hidden): ');
         $question->setValidator(array($this, 'passwordValidator'));
         $question->setHidden(true);
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $password = $console->ask($input, $output, $question);
         $input->setArgument('password', $password);
     } else {
         $output->writeln(' > <info>Password</>: ' . str_repeat('*', strlen($password)));
     }
     // Ask for the email if it's not defined
     if (null === ($email = $input->getArgument('email'))) {
         $question = new Question(' > <info>Email</>: ');
         $question->setValidator(array($this, 'emailValidator'));
         $question->setMaxAttempts(self::MAX_ATTEMPTS);
         $email = $console->ask($input, $output, $question);
         $input->setArgument('email', $email);
     } else {
         $output->writeln(' > <info>Email</>: ' . $email);
     }
     if (null === ($name = $input->getArgument('name'))) {
         $question = new Question(' > <info>Name</>: ');
         $name = $console->ask($input, $output, $question);
         $input->setArgument('name', $name);
     } else {
         $output->writeln(' > <info>Name</>: ' . $name);
     }
 }
Ejemplo n.º 28
0
 protected function getEmail($input, $output)
 {
     $helper = $this->getHelper('question');
     $question = new Question('Please enter email: ');
     $question->setValidator(function ($value) {
         if (trim($value) == '') {
             throw new \Exception('The email can not be empty!');
         }
         return $value;
     });
     $question->setMaxAttempts(20);
     return $helper->ask($input, $output, $question);
 }
Ejemplo n.º 29
0
 /**
  * Ask a question
  * 
  * @param string $question  Question to ask
  * @param mixed  $default   Default value
  * @param bool   $hidden    Hide response
  * @param bool   $required  User input is required
  * @return mixed
  */
 public function ask($question, $default = null, $hidden = false, $required = true)
 {
     $helper = $this->getHelper('question');
     $q = new Question($question, $default);
     if ($hidden) {
         $q->setHidden(true);
         $q->setHiddenFallback(false);
     }
     if ($required) {
         $q->setValidator([$this, 'assertNotEmpty']);
         $q->setMaxAttempts(2);
     }
     return $helper->ask($this->input, $this->output, $q);
 }
 private function confirmSend($input, $output)
 {
     $qHelper = $this->getHelper('question');
     $question = new Question('通知メールを送信しますか? [y/n]: ', null);
     $question->setValidator(function ($answer) {
         $answer = strtolower(substr($answer, 0, 1));
         if (!in_array($answer, ['y', 'n'])) {
             throw new \RuntimeException('yまたはnを入力してください');
         }
         return $answer;
     });
     $question->setMaxAttempts(3);
     return $qHelper->ask($input, $output, $question) == 'y';
 }