/** * 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(); }
/** * @inheritdoc */ public function export() { foreach ($this->messages as $message) { if ($message[1] == Logger::LEVEL_ERROR) { Console::error($this->formatMessage($message)); } else { Console::output($this->formatMessage($message)); } } }
/** * @param string $command serialized command object * @return string */ public function actionHandle($command) { try { $command = unserialize(base64_decode($command)); $command->setRunningInBackground(true); $this->commandBus->handle($command); } catch (\Exception $e) { Console::error($e->getMessage()); } }
/** * @param $path * @param bool $newSourceLanguage * @param bool $configFile * @throws Exception */ public function actionReplaceSourceLanguage($configFile, $newSourceLanguage = false) { $config = ['translator' => 'Yii::t', 'overwrite' => false, 'removeUnused' => false, 'sort' => false, 'format' => 'php']; $configFile = Yii::getAlias($configFile); if (!is_file($configFile)) { throw new Exception("The configuration file does not exist: {$configFile}"); } $config = array_merge($config, require $configFile); if (!is_dir($config['sourcePath'])) { throw new Exception("The source path {$config['sourcePath']} is not a valid directory."); } $files = FileHelper::findFiles(realpath($config['sourcePath']), $config); $unremoved = []; foreach ($files as $fileName) { if (!is_array($config['translator'])) { $translator = [$config['translator']]; } foreach ($translator as $currentTranslator) { $n = 0; $subject = file_get_contents($fileName); $replacedSubject = preg_replace_callback('/\\b(\\\\)?' . $currentTranslator . '\\s*\\(\\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\\s*,\\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\\s*[,\\)]/s', function ($matches) use($newSourceLanguage, $fileName, &$unremoved) { $category = substr($matches[2], 1, -1); $message = $matches[3]; if ($newSourceLanguage !== false) { $message = eval("return {$message};"); $result = str_replace($message, Yii::t($category, $message, [], $newSourceLanguage), $matches[0]); } else { if (strpos($matches[0], ')') != strlen($matches[0]) - 1) { $unremoved[$fileName][] = $message; $result = $matches[0]; } else { $result = $message; } } return $result; }, $subject, -1, $n); if (@file_put_contents($fileName, $replacedSubject) !== false) { Console::output("File: {$fileName}; Translator: {$currentTranslator}; Affected: {$n}"); } else { Console::error("File: {$fileName}; Translator: {$currentTranslator}; Affected: {$n}"); } } } if ($newSourceLanguage == false && !empty($unremoved)) { Console::output('Messages with params, can`t be removed by this tool. Remove it manually'); foreach ($unremoved as $fileName => $messages) { $messages = implode(PHP_EOL, $messages); Console::output("{$fileName}:" . PHP_EOL . $messages); } } }
public function execute($command, $params = []) { $command = strtr($command, $params); $exec = $this->getExec(); try { if ($this->getIsVerbose()) { Console::output("Executing {$command}"); } $result = $exec($command); if ($this->getIsVerbose()) { Console::output($result); } return $result; } catch (\RuntimeException $e) { Console::error($e->getMessage()); return false; } }
/** * @param $exception * @param $job */ protected function onError($job, \Exception $exception = null) { Console::error("Job ID#{$job['id']}: {$exception->getMessage()}"); }
protected function runTasks() { foreach ($this->_tasks as $k => $id) { Console::output(sprintf('Running task "%s" (%d/%d)', $id, $k + 1, count($this->_tasks))); $result = $this->_container->get("tasks.{$id}")->run($this->_container, $this); if ($result === false) { Console::error(sprintf('Task "%s" failed.', $id)); return false; } } return true; }