mirror of
https://github.com/kmvan/x-prober.git
synced 2026-08-13 00:51:39 +08:00
adjust language loader
This commit is contained in:
+30
-29
@@ -23,20 +23,22 @@ class Compiler
|
||||
|
||||
$code = '';
|
||||
|
||||
foreach ($this->yieldFiles($this->COMPONENTS_DIR) as $filePath) {
|
||||
if (\is_dir($filePath) || false === \strpos($filePath, '.php')) {
|
||||
continue;
|
||||
}
|
||||
if ( ! $this->isDev()) {
|
||||
foreach ($this->yieldFiles($this->COMPONENTS_DIR) as $filePath) {
|
||||
if (\is_dir($filePath) || false === \strpos($filePath, '.php')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content = $this->getCodeViaFilePath($filePath);
|
||||
$code .= $content;
|
||||
$content = $this->getCodeViaFilePath($filePath);
|
||||
$code .= $content;
|
||||
}
|
||||
}
|
||||
|
||||
$preDefineCode = $this->preDefine([
|
||||
$this->getTimerCode(),
|
||||
$this->getDevMode(),
|
||||
$this->getDebugCode(),
|
||||
$this->getLangLoaderCode(),
|
||||
$this->getVendorCode(),
|
||||
]);
|
||||
$code = "<?php\n{$preDefineCode}\n{$code}";
|
||||
$code .= $this->loader();
|
||||
@@ -52,7 +54,7 @@ class Compiler
|
||||
'distFilePath' => $this->COMPILE_FILE_PATH,
|
||||
]);
|
||||
|
||||
if ( $this->isDev() || ! $this->isDebug()) {
|
||||
if ( ! $this->isDev()) {
|
||||
$this->writeFile(\php_strip_whitespace($this->COMPILE_FILE_PATH));
|
||||
}
|
||||
|
||||
@@ -82,7 +84,7 @@ class Compiler
|
||||
|
||||
echo "Packing `{$filePath}...";
|
||||
|
||||
if ($this->isDev() || $this->isDebug()) {
|
||||
if ($this->isDev()) {
|
||||
$code = \file_get_contents($filePath);
|
||||
} else {
|
||||
$code = \php_strip_whitespace($filePath);
|
||||
@@ -129,35 +131,23 @@ PHP;
|
||||
$isDev = $this->isDev() ? 'true' : 'false';
|
||||
|
||||
return <<<PHP
|
||||
\define('IS_DEV', {$isDev});
|
||||
\\define('XPROBER_IS_DEV', {$isDev});
|
||||
PHP;
|
||||
}
|
||||
|
||||
private function getTimerCode(): string
|
||||
{
|
||||
return <<<'PHP'
|
||||
\define('TIMER', \microtime(true));
|
||||
PHP;
|
||||
}
|
||||
|
||||
private function isDebug(): bool
|
||||
{
|
||||
global $argv;
|
||||
|
||||
return \in_array('debug', $argv);
|
||||
}
|
||||
|
||||
private function getDebugCode(): string
|
||||
{
|
||||
$debug = $this->isDev() || $this->isDebug() ? 'true' : 'false';
|
||||
|
||||
return <<<PHP
|
||||
\\define('DEBUG', {$debug});
|
||||
\define('XPROBER_TIMER', \microtime(true));
|
||||
PHP;
|
||||
}
|
||||
|
||||
private function getLangLoaderCode(): string
|
||||
{
|
||||
if ($this->isDev()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$filePath = $this->COMPONENTS_DIR . '/I18n/Lang.json';
|
||||
|
||||
if ( ! \is_readable($filePath)) {
|
||||
@@ -177,10 +167,10 @@ PHP;
|
||||
die('Invalid json format.');
|
||||
}
|
||||
|
||||
$json = \base64_encode(\json_encode($json));
|
||||
$json = \serialize($json);
|
||||
|
||||
return <<<PHP
|
||||
\\define('LANG', '{$json}');
|
||||
\\define('XPROBER_LANGUAGES', '{$json}');
|
||||
PHP;
|
||||
}
|
||||
|
||||
@@ -214,6 +204,17 @@ PHP;
|
||||
return \implode("\n", $files);
|
||||
}
|
||||
|
||||
private function getVendorCode(): string
|
||||
{
|
||||
if ( ! $this->isDev()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return <<<PHP
|
||||
include \dirname(__DIR__) . '/vendor/autoload.php';
|
||||
PHP;
|
||||
}
|
||||
|
||||
private function yieldFiles(string $dir): \Iterator
|
||||
{
|
||||
if (\is_dir($dir)) {
|
||||
|
||||
@@ -46,8 +46,8 @@ HTML;
|
||||
$scriptConf = \json_encode(EventsApi::emit('conf', array()));
|
||||
$footer = EventsApi::emit('footer', '');
|
||||
$footerOutline = EventsApi::emit('footerOutline', '');
|
||||
$scriptUrl = \defined('IS_DEV') && \IS_DEV ? "../tmp/app.js?v={$_SERVER['REQUEST_TIME']}" : "?action=getScript&v={$version}";
|
||||
$styleUrl = \defined('IS_DEV') && \IS_DEV ? "../tmp/app.css?v={$_SERVER['REQUEST_TIME']}" : "?action=getStyle&v={$version}";
|
||||
$scriptUrl = \defined('\XPROBER_IS_DEV') && \XPROBER_IS_DEV ? "../tmp/app.js?v={$_SERVER['REQUEST_TIME']}" : "?action=getScript&v={$version}";
|
||||
$styleUrl = \defined('\XPROBER_IS_DEV') && \XPROBER_IS_DEV ? "../tmp/app.css?v={$_SERVER['REQUEST_TIME']}" : "?action=getStyle&v={$version}";
|
||||
|
||||
return <<<HTML
|
||||
<!DOCTYPE html>
|
||||
|
||||
@@ -9,7 +9,13 @@ class I18nApi
|
||||
static $translation = null;
|
||||
|
||||
if (null === $translation) {
|
||||
$translation = \json_decode(\base64_decode(\LANG), true);
|
||||
if (\defined('\XPROBER_IS_DEV') && \XPROBER_IS_DEV) {
|
||||
$translation = \file(__DIR__ . '/Lang.json');
|
||||
unset($translation[0]);
|
||||
$translation = \json_decode(\implode("\n", $translation), true);
|
||||
} else {
|
||||
$translation = \unserialize(\XPROBER_LANGUAGES);
|
||||
}
|
||||
}
|
||||
|
||||
$clientLang = self::getClientLang();
|
||||
|
||||
Reference in New Issue
Block a user