MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
DialogHelper.php
Ir para a documentação deste ficheiro.
1<?php
2
4
6
7/*
8 * This file is part of the Symfony framework.
9 *
10 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
11 *
12 * This source file is subject to the MIT license that is bundled
13 * with this source code in the file LICENSE.
14 */
15
21class DialogHelper extends Helper
22{
32 public function ask(OutputInterface $output, $question, $default = null)
33 {
34 // @codeCoverageIgnoreStart
35 $output->writeln($question);
36
37 $ret = trim(fgets(STDIN));
38
39 return $ret ? $ret : $default;
40 // @codeCoverageIgnoreEnd
41 }
42
54 public function askConfirmation(OutputInterface $output, $question, $default = true)
55 {
56 // @codeCoverageIgnoreStart
57 $answer = 'z';
58 while ($answer && !in_array(strtolower($answer[0]), array('y', 'n'))) {
59 $answer = $this->ask($output, $question);
60 }
61
62 if (false === $default) {
63 return $answer && 'y' == strtolower($answer[0]);
64 } else {
65 return !$answer || 'y' == strtolower($answer[0]);
66 }
67 // @codeCoverageIgnoreEnd
68 }
69
82 public function askAndValidate(OutputInterface $output, $question, \Closure $validator, $attempts = false)
83 {
84 // @codeCoverageIgnoreStart
85 $error = null;
86 while (false === $attempts || $attempts--) {
87 if (null !== $error) {
88 $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
89 }
90
91 $value = $this->ask($output, $question, null);
92
93 try {
94 return $validator($value);
95 } catch (\Exception $error) {
96 }
97 }
98
99 throw $error;
100 // @codeCoverageIgnoreEnd
101 }
102
106 public function getName()
107 {
108 return 'dialog';
109 }
110}
ask(OutputInterface $output, $question, $default=null)
askAndValidate(OutputInterface $output, $question, \Closure $validator, $attempts=false)
askConfirmation(OutputInterface $output, $question, $default=true)