Пример #1
0
 /**
  * Prompts the user for input, and returns it.
  *
  * @param string $prompt Prompt text.
  * @param string|null $options String of options. Pass null to omit.
  * @param string|null $default Default input value. Pass null to omit.
  * @return string Either the default value, or the user-provided input.
  */
 protected function _getInput($prompt, $options, $default)
 {
     $optionsText = '';
     if (isset($options)) {
         $optionsText = " {$options} ";
     }
     $defaultText = '';
     if ($default !== null) {
         $defaultText = "[{$default}] ";
     }
     $this->_output->write('<question>' . $prompt . "</question>{$optionsText}\n{$defaultText}> ", 0);
     $result = $this->_input->read();
     $result = trim($result);
     if ($default !== null && ($result === '' || $result === null)) {
         return $default;
     }
     return $result;
 }
Пример #2
0
 /**
  * Implements writing to console.
  *
  * @param string $level The severity level of log you are making.
  * @param string $message The message you want to log.
  * @param array $context Additional information about the logged message
  * @return bool success of write.
  */
 public function log($level, $message, array $context = [])
 {
     $message = $this->_format($message);
     $output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message;
     return $this->_output->write(sprintf('<%s>%s</%s>', $level, $output, $level));
 }
Пример #3
0
 /**
  * Prints an error to stderr.
  *
  * Template method of BaseErrorHandler.
  *
  * @param array $error An array of error data.
  * @param bool $debug Whether or not the app is in debug mode.
  * @return void
  */
 protected function _displayError($error, $debug)
 {
     $message = sprintf('%s in [%s, line %s]', $error['description'], $error['file'], $error['line']);
     $message = sprintf("<error>%s Error:</error> %s\n", $error['error'], $message);
     $this->_stderr->write($message);
 }