/** * 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; }
/** * 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); }
/** * 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); }
/** * 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); }