From 681e5eeac73f34054ff3dffb573f447398af6afd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 22 Sep 2016 11:06:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E9=85=8D=E7=BD=AE=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E7=94=9F=E6=88=90=20=E6=94=AF=E6=8C=81=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../think/console/command/optimize/Config.php | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/library/think/console/command/optimize/Config.php b/library/think/console/command/optimize/Config.php index 9ab5710a..cadfe5ee 100644 --- a/library/think/console/command/optimize/Config.php +++ b/library/think/console/command/optimize/Config.php @@ -10,9 +10,10 @@ // +---------------------------------------------------------------------- namespace think\console\command\optimize; +use think\Config as ThinkConfig; use think\console\Command; use think\console\Input; -use think\console\input\Option; +use think\console\input\Argument; use think\console\Output; class Config extends Command @@ -23,14 +24,14 @@ class Config extends Command protected function configure() { $this->setName('optimize:config') - ->addOption('module', null, Option::VALUE_REQUIRED, 'Build module config cache .') + ->addArgument('module', Argument::OPTIONAL, 'Build module config cache .') ->setDescription('Build config and common file cache.'); } protected function execute(Input $input, Output $output) { - if ($input->hasOption('module')) { - $module = $input->getOption('module') . DS; + if ($input->hasArgument('module')) { + $module = $input->getArgument('module') . DS; } else { $module = ''; } @@ -50,25 +51,30 @@ class Config extends Command { $content = ''; $path = realpath(APP_PATH . $module) . DS; - // 加载模块配置 - $config = \think\Config::load(CONF_PATH . $module . 'config' . CONF_EXT); - // 加载应用状态配置 - if ($module && $config['app_status']) { - $config = \think\Config::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT); - } + if ($module) { + // 加载模块配置 + $config = ThinkConfig::load(CONF_PATH . $module . 'config' . CONF_EXT); - // 读取扩展配置文件 - if ($module && $config['extra_config_list']) { - foreach ($config['extra_config_list'] as $name => $file) { - $filename = CONF_PATH . $module . $file . CONF_EXT; - \think\Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME)); + // 读取数据库配置文件 + $filename = CONF_PATH . $module . 'database' . CONF_EXT; + ThinkConfig::load($filename, 'database'); + + // 加载应用状态配置 + if ($config['app_status']) { + $config = ThinkConfig::load(CONF_PATH . $module . $config['app_status'] . CONF_EXT); + } + // 读取扩展配置文件 + if (is_dir(CONF_PATH . $module . 'extra')) { + $dir = CONF_PATH . $module . 'extra'; + $files = scandir($dir); + foreach ($files as $file) { + if (strpos($file, CONF_EXT)) { + $filename = $dir . DS . $file; + ThinkConfig::load($filename, pathinfo($file, PATHINFO_FILENAME)); + } + } } - } - - // 加载别名文件 - if (is_file(CONF_PATH . $module . 'alias' . EXT)) { - $content .= '\think\Loader::addClassMap(' . (var_export(include CONF_PATH . $module . 'alias' . EXT, true)) . ');' . PHP_EOL; } // 加载行为扩展文件 @@ -81,7 +87,7 @@ class Config extends Command $content .= substr(php_strip_whitespace($path . 'common' . EXT), 5) . PHP_EOL; } - $content .= '\think\Config::set(' . var_export(\think\Config::get(), true) . ');'; + $content .= '\think\Config::set(' . var_export(ThinkConfig::get(), true) . ');'; return $content; } }