ConsoleKit\Widgets\Dialog::ask PHP Метод

ask() публичный Метод

Writes $text and reads the user's input
public ask ( string $text, string $default = '', boolean $displayDefault = true ) : string
$text string
$default string
$displayDefault boolean
Результат string
    public function ask($text, $default = '', $displayDefault = true)
    {
        if ($displayDefault && !empty($default)) {
            $defaultText = $default;
            if (strlen($defaultText) > 30) {
                $defaultText = substr($default, 0, 30) . '...';
            }
            $text .= " [{$defaultText}]";
        }
        $this->textWriter->write("{$text} ");
        return trim(fgets(STDIN)) ?: $default;
    }

Usage Example

Пример #1
0
 /**
  * Says hello to someone
  *
  * @arg name The name of the person to say hello to
  */
 public function executeHello(array $args, array $options = array())
 {
     $name = 'unknown';
     if (empty($args)) {
         $dialog = new Dialog($this->console);
         $name = $dialog->ask('What is your name?', $name);
     } else {
         $name = $args[0];
     }
     $this->writeln(sprintf('hello %s!', $name));
 }
All Usage Examples Of ConsoleKit\Widgets\Dialog::ask