Can be connected to any stream resource that can be used with fopen() Can generate colorized output on consoles that support it. There are a few built in styles - error Error messages. - warning Warning messages. - info Informational messages. - comment Additional text. - question Magenta text used for user prompts By defining styles with addStyle() you can create custom console styles. ### Using styles in output You can format console output using tags with the name of the style to apply. From inside a shell object $this->out('Overwrite: foo.php was overwritten.'); This would create orange 'Overwrite:' text, while the rest of the text would remain the normal color. See ConsoleOutput::styles() to learn more about defining your own styles. Nested styles are not supported at this time.
Ejemplo n.º 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->_out->write('<question>' . $prompt . "</question>{$optionsText}\n{$defaultText}> ", 0);
     $result = $this->_in->read();
     $result = trim($result);
     if ($default !== null && ($result === '' || $result === null)) {
         return $default;
     }
     return $result;
 }
Ejemplo n.º 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, $context);
     $output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message . "\n";
     return $this->_output->write(sprintf('<%s>%s</%s>', $level, $output, $level), false);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 4
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 string|array $scope The scope(s) a log message is being created in.
  *    See Cake\Log\Log::config() for more information on logging scopes.
  * @return bool success of write.
  */
 public function write($level, $message, $scope = [])
 {
     $output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message . "\n";
     return $this->_output->write(sprintf('<%s>%s</%s>', $level, $output, $level), false);
 }