/** * Writes question to output and returns hidden user input. * * @access public * @param string $question Question to ask * @param null|mixed $default Default if no input is entered * @param boolean $fallback Fall back to non-hidden input? * @return string */ public function ask($question, $default = null, $fallback = false) { if (DIRECTORY_SEPARATOR === '\\' || $this->hasStty()) { $this->output->write(trim($question) . ' '); if (DIRECTORY_SEPARATOR === '\\') { $answer = trim(shell_exec(__DIR__ . '/resources/hiddeninput.exe')); } else { $settings = shell_exec('stty -g'); exec('stty -echo'); $answer = $this->input->read(); exec('stty ' . $settings); } $this->output->write(PHP_EOL); return empty($answer) ? $default : $answer; } elseif ($fallback) { return parent::ask($question, $default); } else { throw new RuntimeException(vsprintf("%s(): Unable to hide the user input.", [__METHOD__])); } }
/** * Run the reactor. * * @access public */ public function run() { $this->handleCustomOptions(); $this->output->write(PHP_EOL); if (($command = $this->input->getArgument(1)) === null) { $this->displayReactorInfo(); $this->listCommands(); } else { $this->dispatch($command); } $this->output->write(PHP_EOL); }
/** * Displays command details. * * @access protected */ protected function displayCommandDetails() { $this->write('<yellow>Command:</yellow>'); $this->nl(); $this->write('php reactor ' . $this->input->getArgument(1)); $this->nl(); $this->write('<yellow>Description:</yellow>'); $this->nl(); $this->write($this->getCommandDescription()); if (!empty($this->commandInformation['arguments'])) { $this->nl(); $this->write('<yellow>Arguments:</yellow>'); $this->nl(); $this->drawInfoTable($this->commandInformation['arguments']); } if (!empty($this->commandInformation['options'])) { $this->nl(); $this->write('<yellow>Options:</yellow>'); $this->nl(); $this->drawInfoTable($this->commandInformation['options']); } $this->shouldExecute = false; }
/** * Writes question to output and returns user input. * * @access public * @param string $question Question to ask * @param null|mixed $default Default if no input is entered * @return string */ public function ask($question, $default = null) { $this->output->write(trim($question) . ' '); $answer = $this->input->read(); return empty($answer) ? $default : $answer; }
/** * */ public function testGetMissingArgument() { $reader = $this->getReader(); $arguments = ['--foo']; $input = new Input($reader, $arguments); $this->assertSame(true, $input->getArgument('foo')); $this->assertSame(null, $input->getArgument('bar')); $this->assertSame(false, $input->getArgument('bar', false)); }