public function encode_file($path, $base) { $rpath = self::relativePath($path, $base); if (preg_match('/\\.(php|phtml)$/', $path)) { echo " [34mPHP[0m: {$rpath}..."; //移除脚本中的注释和回车 $content = file_get_contents($path); $total = strlen($content); // 预编译代码 if (class_exists('\\Gini\\Dev\\Macro')) { $content = Macro::compile($content); } // 混淆变量 if (class_exists('\\Gini\\Dev\\Obfuscator')) { $ob = new Obfuscator($content); $ob->set_reserved_keywords(['$config', '$lang']); $content = $ob->format(); } $converted = strlen($content); $percentage = round($converted * 100 / $total, 1); echo " {$percentage}%"; } elseif (fnmatch("*.js", $path)) { echo " [32mJS[0m: {$rpath}..."; $content = @file_get_contents($path); $total = strlen($content); $content = shell_exec('uglifyjs ' . escapeshellarg($path) . ' 2>&1'); $converted = strlen($content); $percentage = round($converted * 100 / $total, 1); echo " {$percentage}%"; } elseif (fnmatch('*.css', $path)) { echo " [35mCSS[0m: {$rpath}..."; $content = @file_get_contents($path); $total = strlen($content); $content = \CSSMin::minify($content); $converted = strlen($content); $percentage = round($converted * 100 / $total, 1); echo " {$percentage}%"; } else { echo " DUP: {$rpath}..."; //复制相关文件 $content = @file_get_contents($path); $total = strlen($content); echo "{$total} bytes"; } if ($content) { $this->phar[$rpath] = $content; } else { echo "... EMPTY"; } echo "\n"; }