feat: 同步下新环境
This commit is contained in:
@@ -10,13 +10,15 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\console\command\optimize;
|
||||
|
||||
use think\App;
|
||||
use think\Config;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Container;
|
||||
|
||||
class Autoload extends Command
|
||||
{
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('optimize:autoload')
|
||||
@@ -35,14 +37,20 @@ class Autoload extends Command
|
||||
return [
|
||||
|
||||
EOF;
|
||||
$app = Container::get('app');
|
||||
|
||||
$namespacesToScan = [
|
||||
$app->getNamespace() . '\\' => realpath(rtrim($app->getAppPath())),
|
||||
'think\\' => $app->getThinkPath() . 'library/think',
|
||||
'traits\\' => $app->getThinkPath() . 'library/traits',
|
||||
'' => realpath(rtrim($app->getRootPath() . 'extend')),
|
||||
App::$namespace . '\\' => realpath(rtrim(APP_PATH)),
|
||||
'think\\' => LIB_PATH . 'think',
|
||||
'behavior\\' => LIB_PATH . 'behavior',
|
||||
'traits\\' => LIB_PATH . 'traits',
|
||||
'' => realpath(rtrim(EXTEND_PATH)),
|
||||
];
|
||||
|
||||
$root_namespace = Config::get('root_namespace');
|
||||
foreach ($root_namespace as $namespace => $dir) {
|
||||
$namespacesToScan[$namespace . '\\'] = realpath($dir);
|
||||
}
|
||||
|
||||
krsort($namespacesToScan);
|
||||
$classMap = [];
|
||||
foreach ($namespacesToScan as $namespace => $dir) {
|
||||
@@ -51,7 +59,7 @@ EOF;
|
||||
continue;
|
||||
}
|
||||
|
||||
$namespaceFilter = '' === $namespace ? null : $namespace;
|
||||
$namespaceFilter = $namespace === '' ? null : $namespace;
|
||||
$classMap = $this->addClassMapCode($dir, $namespaceFilter, $classMap);
|
||||
}
|
||||
|
||||
@@ -60,12 +68,12 @@ EOF;
|
||||
$classmapFile .= ' ' . var_export($class, true) . ' => ' . $code;
|
||||
}
|
||||
$classmapFile .= "];\n";
|
||||
$runtimePath = $app->getRuntimePath();
|
||||
if (!is_dir($runtimePath)) {
|
||||
@mkdir($runtimePath, 0755, true);
|
||||
|
||||
if (!is_dir(RUNTIME_PATH)) {
|
||||
@mkdir(RUNTIME_PATH, 0755, true);
|
||||
}
|
||||
|
||||
file_put_contents($runtimePath . 'classmap.php', $classmapFile);
|
||||
file_put_contents(RUNTIME_PATH . 'classmap' . EXT, $classmapFile);
|
||||
|
||||
$output->writeln('<info>Succeed!</info>');
|
||||
}
|
||||
@@ -92,33 +100,40 @@ EOF;
|
||||
|
||||
protected function getPathCode($path)
|
||||
{
|
||||
|
||||
$baseDir = '';
|
||||
$app = Container::get('app');
|
||||
$appPath = $this->normalizePath(realpath($app->getAppPath()));
|
||||
$libPath = $this->normalizePath(realpath($app->getThinkPath() . 'library'));
|
||||
$extendPath = $this->normalizePath(realpath($app->getRootPath() . 'extend'));
|
||||
$libPath = $this->normalizePath(realpath(LIB_PATH));
|
||||
$appPath = $this->normalizePath(realpath(APP_PATH));
|
||||
$extendPath = $this->normalizePath(realpath(EXTEND_PATH));
|
||||
$rootPath = $this->normalizePath(realpath(ROOT_PATH));
|
||||
$path = $this->normalizePath($path);
|
||||
|
||||
if (strpos($path, $libPath . '/') === 0) {
|
||||
$path = substr($path, strlen($app->getThinkPath() . 'library'));
|
||||
$baseDir = "'" . $libPath . "/'";
|
||||
} elseif (strpos($path, $appPath . '/') === 0) {
|
||||
if ($libPath !== null && strpos($path, $libPath . '/') === 0) {
|
||||
$path = substr($path, strlen(LIB_PATH));
|
||||
$baseDir = 'LIB_PATH';
|
||||
} elseif ($appPath !== null && strpos($path, $appPath . '/') === 0) {
|
||||
$path = substr($path, strlen($appPath) + 1);
|
||||
$baseDir = "'" . $appPath . "/'";
|
||||
} elseif (strpos($path, $extendPath . '/') === 0) {
|
||||
$baseDir = 'APP_PATH';
|
||||
} elseif ($extendPath !== null && strpos($path, $extendPath . '/') === 0) {
|
||||
$path = substr($path, strlen($extendPath) + 1);
|
||||
$baseDir = "'" . $extendPath . "/'";
|
||||
$baseDir = 'EXTEND_PATH';
|
||||
} elseif ($rootPath !== null && strpos($path, $rootPath . '/') === 0) {
|
||||
$path = substr($path, strlen($rootPath) + 1);
|
||||
$baseDir = 'ROOT_PATH';
|
||||
}
|
||||
|
||||
if (false !== $path) {
|
||||
if ($path !== false) {
|
||||
$baseDir .= " . ";
|
||||
}
|
||||
|
||||
return $baseDir . ((false !== $path) ? var_export($path, true) : "");
|
||||
return $baseDir . (($path !== false) ? var_export($path, true) : "");
|
||||
}
|
||||
|
||||
protected function normalizePath($path)
|
||||
{
|
||||
if ($path === false) {
|
||||
return;
|
||||
}
|
||||
$parts = [];
|
||||
$path = strtr($path, '\\', '/');
|
||||
$prefix = '';
|
||||
@@ -237,7 +252,7 @@ EOF;
|
||||
// strip leading non-php code if needed
|
||||
if (substr($contents, 0, 2) !== '<?') {
|
||||
$contents = preg_replace('{^.+?<\?}s', '<?', $contents, 1, $replacements);
|
||||
if (0 === $replacements) {
|
||||
if ($replacements === 0) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -264,9 +279,9 @@ EOF;
|
||||
$namespace = str_replace([' ', "\t", "\r", "\n"], '', $matches['nsname'][$i]) . '\\';
|
||||
} else {
|
||||
$name = $matches['name'][$i];
|
||||
if (':' === $name[0]) {
|
||||
if ($name[0] === ':') {
|
||||
$name = 'xhp' . substr(str_replace(['-', ':'], ['_', '__'], $name), 1);
|
||||
} elseif ('enum' === $matches['type'][$i]) {
|
||||
} elseif ($matches['type'][$i] === 'enum') {
|
||||
$name = rtrim($name, ':');
|
||||
}
|
||||
$classes[] = ltrim($namespace . $name, '\\');
|
||||
|
||||
Reference in New Issue
Block a user