本文整理汇总了PHP中yii\helpers\Console::stdout方法的典型用法代码示例。如果您正苦于以下问题:PHP Console::stdout方法的具体用法?PHP Console::stdout怎么用?PHP Console::stdout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Console
的用法示例。
在下文中一共展示了Console::stdout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stdout
/**
* Prints a string to STDOUT.
*
* @param string $string the string to print
* @return int|boolean Number of bytes printed or false on error
*/
public static function stdout($string)
{
$args = func_get_args();
array_shift($args);
$string = parent::ansiFormat($string, $args) . "\n";
return parent::stdout($string);
}
示例2: stdout
/**
* Prints a string to STDOUT.
*
* @param string $string the string to print
* @return int|boolean Number of bytes printed or false on error
*/
public function stdout($string)
{
if ($this->isColorEnabled()) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args) . "\n";
}
return Console::stdout($string);
}
示例3: stdout
public function stdout($string)
{
if (Console::streamSupportsAnsiColors(STDOUT)) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args);
}
return Console::stdout($string);
}
示例4: message
/**
* message
*
* @param string $string
* @access private
* @return integer|null
*/
private function message($string)
{
if (!empty($string) && !$this->quiet) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args);
return Console::stdout($string);
}
}
示例5: log
/**
* Logs a message to console and then to yii\log\Logger.
*/
public function log($message, $level, $category = 'application')
{
if ($level <= $this->getSpamLevel()) {
$style = self::$styles[$level];
if ($style) {
$message = Console::ansiFormat($message, $style);
}
Console::stdout($message . "\n");
}
parent::log($message, $level, $category);
}
示例6: output
/**
*
* @param string $string
* @return string
*/
public function output($string)
{
if ($this->isColorEnabled()) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args);
}
$b = Console::stdout($string);
echo PHP_EOL;
return $b;
}
示例7: write
public static function write($path, $content)
{
if (file_exists($path)) {
$old = file_get_contents($path);
if ($old === $content) {
return;
}
}
file_put_contents($path, $content);
Console::stdout(Console::ansiFormat("written file: {$path}\n", [Console::FG_YELLOW]));
}
示例8: export
/**
* @inheritdoc
*/
public function export()
{
foreach ($this->messages as $message) {
$string = $this->formatMessage($message) . "\n";
$level = $message[1];
if ($this->stderrIsNotStdout && in_array($level, $this->stderrLevels)) {
if ($this->stderrSupportsColors) {
Console::stderr(Console::ansiFormat($string, $this->colorMap[$level]));
} else {
Console::stderr($string);
}
}
if ($this->stdoutSupportsColors) {
Console::stdout(Console::ansiFormat($string, $this->colorMap[$level]));
} else {
Console::stdout($string);
}
}
}
示例9: export
/**
* Exports log [[messages]] to a specific destination.
* Child classes must implement this method.
*/
public function export()
{
foreach ($this->messages as $message) {
list($text, $level, $category, $timestamp) = $message;
if (!is_string($text)) {
// exceptions may not be serializable if in the call stack somewhere is a Closure
if ($text instanceof \Throwable || $text instanceof \Exception) {
$text = (string) $text;
} else {
$text = VarDumper::export($text);
}
}
$string = "[{$level}][{$category}] {$text}";
if ($level == Logger::LEVEL_ERROR) {
Console::stderr($string);
} else {
Console::stdout($string);
}
}
}
示例10: callback
public function callback(AMQPMessage $msg)
{
$routingKey = $msg->delivery_info['routing_key'];
$method = 'read' . Inflector::camelize($routingKey);
if (!isset($this->interpreters[$this->queue])) {
$interpreter = $this;
} elseif (class_exists($this->interpreters[$this->queue])) {
$interpreter = new $this->interpreters[$this->queue]();
if (!$interpreter instanceof AmqpInterpreter) {
throw new Exception(sprintf("Class '%s' is not correct interpreter class.", $this->interpreters[$this->queue]));
}
} else {
throw new Exception(sprintf("Interpreter class '%s' was not found.", $this->interpreters[$this->queue]));
}
if (method_exists($interpreter, $method)) {
$info = ['exchange' => $msg->get('exchange'), 'queue' => $this->queue, 'routing_key' => $msg->get('routing_key'), 'reply_to' => $msg->has('reply_to') ? $msg->get('reply_to') : null];
try {
$interpreter->{$method}(Json::decode($msg->body, true), $info);
} catch (\Exception $exc) {
$error_info = "consumer fail:" . $exc->getMessage() . PHP_EOL . "info:" . print_r($info, true) . PHP_EOL . "body:" . PHP_EOL . print_r($msg->body, true) . PHP_EOL . $exc->getTraceAsString();
\Yii::warning($error_info, __METHOD__);
$format = [Console::FG_RED];
Console::stdout(Console::ansiFormat($error_info . PHP_EOL, $format));
Console::stdout(Console::ansiFormat($exc->getTraceAsString() . PHP_EOL, $format));
}
} else {
if (!isset($this->interpreters[$this->queue])) {
$interpreter = new AmqpInterpreter();
}
$error_info = "Unknown routing key '{$routingKey}' for exchange '{$this->queue}'.";
$error_info .= PHP_EOL . $msg->body;
\Yii::warning($error_info, __METHOD__);
$interpreter->log(sprintf("Unknown routing key '%s' for exchange '%s'.", $routingKey, $this->queue), $interpreter::MESSAGE_ERROR);
// debug the message
$interpreter->log(print_r(Json::decode($msg->body, true), true), $interpreter::MESSAGE_INFO);
}
}
示例11: export
public function export()
{
foreach ($this->messages as $message) {
$string = $this->formatMessage($message) . "\n";
$level = $message[1];
if ($level == Logger::LEVEL_INFO) {
if (strncmp('BEGIN ', $message[0], 6) == 0) {
$ansiColor = $this->_levelAnsiColorMap[Logger::LEVEL_PROFILE_BEGIN];
} elseif (strncmp('END ', $message[0], 4) == 0) {
$ansiColor = $this->_levelAnsiColorMap[Logger::LEVEL_PROFILE_END];
} else {
$ansiColor = $this->_levelAnsiColorMap[Logger::LEVEL_INFO];
}
} elseif (array_key_exists($level, $this->_levelAnsiColorMap)) {
$ansiColor = $this->_levelAnsiColorMap[$level];
} else {
$ansiColor = $this->defaultAnsiColor;
}
if ($this->_stdoutIsTerminal) {
if ($this->_stdoutSupportsAnsiColors && $ansiColor) {
Console::stdout(Console::ansiFormat($string, $ansiColor));
} else {
Console::stdout($string);
}
} else {
Console::stdout($string);
if ($this->_stderrIsTerminal && ($level == Logger::LEVEL_ERROR || $level == Logger::LEVEL_WARNING)) {
if ($this->_stderrSupportsAnsiColors && $ansiColor) {
Console::stderr(Console::ansiFormat($string, $ansiColor));
} else {
Console::stderr($string);
}
}
}
}
}
示例12: stdout
/**
* Prints a string to STDOUT
* @param string $string
*/
public function stdout($string)
{
if (Yii::$app->request->isConsoleRequest) {
if (Console::streamSupportsAnsiColors(STDOUT)) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args);
}
Console::stdout($string . "\n");
}
}
示例13: log
/**
* Logs info and error messages.
*
* @param $message
* @param $type
*/
public static function log($message, $type = self::MESSAGE_INFO)
{
$format = [$type == self::MESSAGE_ERROR ? Console::FG_RED : Console::FG_BLUE];
Console::stdout(Console::ansiFormat($message . PHP_EOL, $format));
}
示例14: stdout
/**
* Prints a string to STDOUT
*
* You may optionally format the string with ANSI codes by
* passing additional parameters using the constants defined in [[\yii\helpers\Console]].
*
* Example:
*
* ~~~
* $this->stdout('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
* ~~~
*
* @param string $string the string to print
* @return int|boolean Number of bytes printed or false on error
*/
public function stdout($string)
{
if (Yii::$app->id != 'app-console') {
return false;
}
if ($this->isColorEnabled()) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args);
}
return Console::stdout($string);
}
示例15: chmod
/**
* @param string $mode
* @param string $path
* @param bool $recursive
*
* @return bool
*/
public function chmod($mode, $path, $recursive = false)
{
switch ($this->_connType) {
case SftpHelper::TYPE_SFTP:
default:
$res = $this->_connection->chmod($mode, $path, $recursive);
break;
case SftpHelper::TYPE_FTP:
if ($recursive) {
Console::stdout("\n");
Log::throwException('Recursive not supported for chmod in ftp mode');
}
$res = @ftp_chmod($this->_connection, $mode, $path);
break;
}
return $res;
}