本文整理汇总了PHP中yii\helpers\Console::ansiFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Console::ansiFormat方法的具体用法?PHP Console::ansiFormat怎么用?PHP Console::ansiFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Console
的用法示例。
在下文中一共展示了Console::ansiFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveMessagesToPHP
/**
* @inheritdoc
*/
protected function saveMessagesToPHP($messages, $dirName, $overwrite, $removeUnused, $sort, $markUnused)
{
$dirNameBase = $dirName;
foreach ($messages as $category => $msgs) {
/**
* Fix Directory
*/
$module = $this->getModuleByCategory($category);
if ($module !== null) {
// Use Module Directory
$dirName = str_replace(Yii::getAlias("@humhub/messages"), $module->getBasePath() . '/messages', $dirNameBase);
preg_match('/.*?Module\\.(.*)/', $category, $result);
$category = $result[1];
} else {
// Use Standard HumHub Directory
$dirName = $dirNameBase;
}
$file = str_replace("\\", '/', "{$dirName}/{$category}.php");
$path = dirname($file);
FileHelper::createDirectory($path);
$msgs = array_values(array_unique($msgs));
$coloredFileName = Console::ansiFormat($file, [Console::FG_CYAN]);
$this->stdout("Saving messages to {$coloredFileName}...\n");
$this->saveMessagesCategoryToPHP($msgs, $file, $overwrite, $removeUnused, $sort, $category, $markUnused);
}
}
示例2: startHead
public function startHead($controller, $headType, $headId, $restarting)
{
if (!$restarting) {
// Console::output(Console::ansiFormat('Starting ' . $headId, [Console::FG_CYAN]));
} else {
// Console::output(Console::ansiFormat('Restarting ' . $headId, [Console::FG_CYAN]));
}
$_this = $this;
$process = new \React\ChildProcess\Process($this->getSubCommand($controller, [$headType, $headId]));
$process->on('exit', function ($exitCode, $termSignal) use(&$_this, &$controller, $headType, $headId) {
if ($exitCode !== 0) {
Console::stderr(Console::ansiFormat("Broadcast head {$headType}:{$headId} exited with error code {$exitCode}", [Console::FG_RED]));
sleep(10);
}
if (static::isPaused()) {
Yii::$app->end(0);
}
$_this->_heads[$headId] = $_this->startHead($controller, $headType, $headId, true);
});
$this->loop->addTimer(0.0001, function ($timer) use($process, &$_this) {
$process->start($timer->getLoop());
$process->stdout->on('data', function ($output) use($_this) {
$stdout = fopen('php://stdout', 'w+');
fwrite($stdout, $output);
});
$process->stderr->on('data', function ($output) use($_this) {
$stderr = fopen('php://stderr', 'w+');
fwrite($stderr, $output);
});
});
sleep(5);
return $process;
}
示例3: actionIndex
public function actionIndex()
{
$this->stdout('Description goes here.' . PHP_EOL);
$helpCommand = Console::ansiFormat("yii help dota2api/economy", [Console::FG_CYAN]);
$this->stdout("Use {$helpCommand} to get usage info." . PHP_EOL);
return self::EXIT_CODE_NORMAL;
}
示例4: stderr
/**
* Prints a string to STDERR.
*
* @param string $string the string to print
* @return int|boolean Number of bytes printed or false on error
*/
public static function stderr($string)
{
$args = func_get_args();
array_shift($args);
$string = parent::ansiFormat($string, $args) . "\n";
return parent::stderr($string);
}
示例5: stderr
protected function stderr($string)
{
if (Console::streamSupportsAnsiColors(\STDOUT)) {
$string = Console::ansiFormat(" Error: " . $string, [Console::FG_RED]);
}
return fwrite(\STDERR, $string);
}
示例6: showErrors
/**
* Show errors
* @param array $errors array of errors string
* @throws yii\base\ExitException
*/
protected function showErrors($errors)
{
foreach ((array) $errors as $err) {
Console::error(Console::ansiFormat(Yii::t('activeuser_backend', "Error") . ": ", [Console::FG_RED]) . $err[0]);
}
yii::$app->end();
}
示例7: 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);
}
}
示例8: stderr
/**
* 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);
}
示例9: formatMessage
/**
* Colorizes a message for console output.
* @param string $message the message to colorize.
* @param array $format the message format.
* @return string the colorized message.
* @see Console::ansiFormat() for details on how to specify the message format.
*/
protected function formatMessage($message, $format = [Console::FG_RED, Console::BOLD])
{
$stream = PHP_SAPI === 'cli' ? \STDERR : \STDOUT;
// try controller first to allow check for --color switch
if (Yii::$app->controller instanceof \yii\console\Controller && Yii::$app->controller->isColorEnabled($stream) || Yii::$app instanceof \yii\console\Application && Console::streamSupportsAnsiColors($stream)) {
$message = Console::ansiFormat($message, $format);
}
return $message;
}
示例10: 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);
}
示例11: _initLanguageElements
/**
* Initializing $_languageElements array.
* @param array $languageSourceIds
*/
private function _initLanguageElements($languageSourceIds)
{
$languageSources = LanguageSource::findAll(['id' => $languageSourceIds]);
foreach ($languageSources as $languageSource) {
$this->_languageElements[$languageSource->category][$languageSource->message] = $languageSource->id;
$category = Console::ansiFormat($languageSource->category, [Console::FG_RED]);
$message = Console::ansiFormat($languageSource->message, [Console::FG_RED]);
$this->_scanner->stdout('category: ' . $category . ', message: ' . $message);
}
}
示例12: output
/**
* Helper method for writting console application output, include before and after wrappers.
*
* @param string $message The message which is displayed
* @param string $color A color from \yii\helpers\Console::FG_GREEN;
* @param return void
*/
protected function output($message, $color = null)
{
$format = [];
if (!$this->isMuted()) {
if ($color !== null) {
$format[] = $color;
}
echo Console::ansiFormat("\r" . $message . "\n", $format);
}
}
示例13: 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;
}
示例14: 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]));
}
示例15: 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);
}