app/console/components/Controller.php
<?php
namespace console\components;
use yii\helpers\Console;
/**
* Class Controller is the base class of console controllers.
* Not recommended to implement actions in this component.
*
* @package console\components
*/
class Controller extends \yii\console\Controller
{
/**
* Formats a string with ANSI codes.
*
* @param string $string the string to be formatted
* @return string
*/
public function ansiFormat($string)
{
if ($this->isColorEnabled()) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args);
}
return $string . "\n";
}
/**
* 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);
}
/**
* Prints a string to STDERR.
*
* @param string $string the string to print
* @return int|boolean Number of bytes printed or false on error
*/
public function stderr($string)
{
if ($this->isColorEnabled(\STDERR)) {
$args = func_get_args();
array_shift($args);
$string = Console::ansiFormat($string, $args) . "\n";
}
return Console::stderr($string);
}
}