Created
June 27, 2019 10:02
-
-
Save Insolita/c046730aceef72b2881a058b58d3a045 to your computer and use it in GitHub Desktop.
yii2Climate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @link http://www.yiiframework.com/ | |
* @copyright Copyright (c) 2008 Yii Software LLC | |
* @license http://www.yiiframework.com/license/ | |
*/ | |
namespace app\commands; | |
use League\CLImate\CLImate; | |
use yii\console\Controller; | |
use yii\console\ExitCode; | |
/** | |
* This command echoes the first argument that you have entered. | |
* This command is provided as an example for you to learn how to create console commands. | |
* @author Qiang Xue <qiang.xue@gmail.com> | |
* @since 2.0 | |
*/ | |
class HelloController extends Controller | |
{ | |
/** | |
* @var \League\CLImate\CLImate | |
*/ | |
private $climate; | |
public function __construct($id, $module, $config = [], CLImate $climate) | |
{ | |
parent::__construct($id, $module, $config); | |
$this->climate = $climate; | |
} | |
public function actionIndex($message = 'hello world') | |
{ | |
$this->stdout($message.PHP_EOL); | |
$this->climate->red('Whoa now this text is red.'); | |
$this->climate->blue('Blue? Wow!'); | |
$this->stderr('Yii error message'.PHP_EOL); | |
$this->climate->backgroundGreen('Climate is Ok!'); | |
$this->climate->to('buffer')->yellow('123'); | |
$this->climate->to('buffer')->lightMagenta('321'); | |
$this->stdout($this->climate->output->get('buffer')->get()); | |
return ExitCode::OK; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment