本文整理汇总了PHP中Symfony\Component\Console\Question\Question::setMaxAttempts方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::setMaxAttempts方法的具体用法?PHP Question::setMaxAttempts怎么用?PHP Question::setMaxAttempts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Question\Question
的用法示例。
在下文中一共展示了Question::setMaxAttempts方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
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.');
}
示例2: interact
/**
* @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;
}
}
}
示例3: execute
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);
}
示例4: interact
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);
}
}
}
示例5: interact
/**
*
* 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>");
}
示例6: buildQuestion
/**
* @return SimpleQuestion
*/
private function buildQuestion()
{
$question = new SimpleQuestion('<question>Enter your project homepage:</question>');
$question->setValidator($this->buildValidator());
$question->setMaxAttempts(3);
return $question;
}
示例7: interact
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);
}
示例8: informAboutStructure
/**
* 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);
}
示例9: interact
/**
* {@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);
}
}
示例10: interact
/**
* {@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);
}
示例11: confirmSend
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';
}
示例12: interact
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];
}
示例13: execute
/**
* 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');
}
示例14: ask
/**
* {@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);
}
示例15: buildAuthorQuestion
/**
* @return SimpleQuestion
*/
private function buildAuthorQuestion()
{
$question = new SimpleQuestion('<question>Enter the author (name <mail@mail.com>):</question>');
$question->setValidator($this->buildValidator());
$question->setMaxAttempts(3);
return $question;
}