當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Console::ansiFormat方法代碼示例

本文整理匯總了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);
     }
 }
開發者ID:freddykr,項目名稱:humhub,代碼行數:29,代碼來源:MessageController.php

示例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;
 }
開發者ID:psesd,項目名稱:sensor-hub,代碼行數:33,代碼來源:Daemon.php

示例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;
 }
開發者ID:aldegtyarev,項目名稱:fantasy,代碼行數:7,代碼來源:EconomyController.php

示例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);
 }
開發者ID:delagics,項目名稱:yii2-app-another,代碼行數:13,代碼來源:Console.php

示例5: stderr

 protected function stderr($string)
 {
     if (Console::streamSupportsAnsiColors(\STDOUT)) {
         $string = Console::ansiFormat("    Error: " . $string, [Console::FG_RED]);
     }
     return fwrite(\STDERR, $string);
 }
開發者ID:inblank,項目名稱:yii2-activeuser,代碼行數:7,代碼來源:Migration.php

示例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();
 }
開發者ID:inblank,項目名稱:yii2-activeuser,代碼行數:12,代碼來源:ConsoleController.php

示例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);
     }
 }
開發者ID:dmitriy-luch,項目名稱:yii2-asset-clean,代碼行數:16,代碼來源:AssetController.php

示例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);
 }
開發者ID:delagics,項目名稱:yii2-app-another,代碼行數:15,代碼來源:Controller.php

示例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;
 }
開發者ID:Jaaviieer,項目名稱:PrograWeb,代碼行數:16,代碼來源:ErrorHandler.php

示例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);
 }
開發者ID:filsh,項目名稱:yii2-platform,代碼行數:9,代碼來源:HostRegexpConsoleRule.php

示例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);
     }
 }
開發者ID:maxxer,項目名稱:yii2-translate-manager,代碼行數:14,代碼來源:Optimizer.php

示例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);
     }
 }
開發者ID:gitter-badger,項目名稱:luya,代碼行數:17,代碼來源:Controller.php

示例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;
 }
開發者ID:jlorente,項目名稱:yii2-app-advanced-template,代碼行數:16,代碼來源:Controller.php

示例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]));
 }
開發者ID:hiqdev,項目名稱:chkipper,代碼行數:11,代碼來源:File.php

示例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);
 }
開發者ID:hiqdev,項目名稱:hidev,代碼行數:14,代碼來源:Logger.php


注:本文中的yii\helpers\Console::ansiFormat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。