From 25831f77d80bc69380c0a54a1e1a0e8b8b112e73 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Tue, 5 Apr 2016 14:40:56 +0800 Subject: [PATCH 1/6] =?UTF-8?q?console=E6=A8=A1=E5=BC=8F=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=85=A5=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mode/console.php | 13 +-------- mode/console/App.php | 65 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/mode/console.php b/mode/console.php index a4aff296..5f0c488e 100644 --- a/mode/console.php +++ b/mode/console.php @@ -27,17 +27,6 @@ return [ 'think\Error' => MODE_PATH . 'console/Error' . EXT ], // 配置文件 - 'config' => [ - 'log' => [ - 'type' => 'File', // 支持 file socket trace sae - 'path' => LOG_PATH, - ], - 'cache' => [ - 'type' => 'File', - 'path' => CACHE_PATH, - 'prefix' => '', - 'expire' => 0, - ] - ] + 'config' => THINK_PATH . 'convention' . EXT ]; diff --git a/mode/console/App.php b/mode/console/App.php index 4c1c13fe..d3672af4 100644 --- a/mode/console/App.php +++ b/mode/console/App.php @@ -23,6 +23,8 @@ class App */ public static function run() { + self::init(); + // 实例化console $console = new Console('Think Console', '0.1'); // 读取指令集 @@ -40,4 +42,67 @@ class App // 运行 $console->run(); } + + private static function init() + { + // 加载初始化文件 + if (is_file(APP_PATH . 'init' . EXT)) { + include APP_PATH . 'init' . EXT; + + // 加载模块配置 + $config = Config::get(); + } else { + // 加载模块配置 + $config = Config::load(APP_PATH . 'config' . EXT); + + // 加载应用状态配置 + if ($config['app_status']) { + $config = Config::load(APP_PATH . $config['app_status'] . EXT); + } + + // 读取扩展配置文件 + if ($config['extra_config_list']) { + foreach ($config['extra_config_list'] as $name => $file) { + $filename = APP_PATH . $file . EXT; + Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME)); + } + } + + // 加载别名文件 + if (is_file(APP_PATH . 'alias' . EXT)) { + Loader::addMap(include APP_PATH . 'alias' . EXT); + } + + // 加载行为扩展文件 + if (APP_HOOK && is_file(APP_PATH . 'tags' . EXT)) { + Hook::import(include APP_PATH . 'tags' . EXT); + } + + // 加载公共文件 + if (is_file(APP_PATH . 'common' . EXT)) { + include APP_PATH . 'common' . EXT; + } + } + + // 注册根命名空间 + if (!empty($config['root_namespace'])) { + Loader::addNamespace($config['root_namespace']); + } + + // 加载额外文件 + if (!empty($config['extra_file_list'])) { + foreach ($config['extra_file_list'] as $file) { + $file = strpos($file, '.') ? $file : APP_PATH . $file . EXT; + if (is_file($file)) { + include_once $file; + } + } + } + + // 设置系统时区 + date_default_timezone_set($config['default_timezone']); + + // 监听app_init + APP_HOOK && Hook::listen('app_init'); + } } \ No newline at end of file From d9109654f37a6e6ac36dc133fd70baef3e09ce94 Mon Sep 17 00:00:00 2001 From: chunice Date: Tue, 5 Apr 2016 14:45:06 +0800 Subject: [PATCH 2/6] =?UTF-8?q?Console=20=E5=A2=9E=E5=8A=A0=E6=B8=85?= =?UTF-8?q?=E7=90=86=E7=BC=93=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Console.php | 3 +- library/think/console/command/cache/Clear.php | 62 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 library/think/console/command/cache/Clear.php diff --git a/library/think/Console.php b/library/think/Console.php index 24b85134..93d17c52 100644 --- a/library/think/Console.php +++ b/library/think/Console.php @@ -49,7 +49,8 @@ class Console "think\\console\\command\\Lists", "think\\console\\command\\Build", "think\\console\\command\\make\\Controller", - "think\\console\\command\\make\\Model" + "think\\console\\command\\make\\Model", + "think\\console\\command\\cache\\Clear" ]; public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') diff --git a/library/think/console/command/cache/Clear.php b/library/think/console/command/cache/Clear.php new file mode 100644 index 00000000..4babaa55 --- /dev/null +++ b/library/think/console/command/cache/Clear.php @@ -0,0 +1,62 @@ + +// +---------------------------------------------------------------------- + +namespace think\console\command\cache; + +use think\console\command\Command; +use think\console\Input; +use think\console\input\Option as InputOption; +use think\console\Output; + +class Clear extends Command +{ + /** + * {@inheritdoc} + */ + protected function configure() + { + $this->setName('cache:clear') + ->setDescription('Clear Application Runtime'); + } + + protected function execute(Input $input, Output $output) + { + if (APP_DEBUG) { + $output->writeln("Open debug, do not need clear."); + return; + } + $templateDir = RUNTIME_PATH . '\temp'; + if (!file_exists($templateDir)) { + $output->writeln("Runtime does not exist."); + return; + } + $this->rmdirs($templateDir); + $output->writeln("Clear done!"); + } + + protected function rmdirs($dir) + { + $dir_arr = scandir($dir); + foreach($dir_arr as $key=>$val){ + if($val == '.' || $val == '..'){} + else { + if(is_dir($dir.'/'.$val)) + { + if(@rmdir($dir.'/'.$val) == 'true'){} + else + rmdirs($dir.'/'.$val); + } + else + unlink($dir.'/'.$val); + } + } + } +} From 0eafee8a69b4d035465c11775d89a538452f915d Mon Sep 17 00:00:00 2001 From: Chino Chang Date: Tue, 5 Apr 2016 14:59:52 +0800 Subject: [PATCH 3/6] =?UTF-8?q?Revert=20"Console=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B8=85=E7=90=86=E7=BC=93=E5=AD=98=E5=8A=9F=E8=83=BD"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Console.php | 3 +- library/think/console/command/cache/Clear.php | 62 ------------------- 2 files changed, 1 insertion(+), 64 deletions(-) delete mode 100644 library/think/console/command/cache/Clear.php diff --git a/library/think/Console.php b/library/think/Console.php index 93d17c52..24b85134 100644 --- a/library/think/Console.php +++ b/library/think/Console.php @@ -49,8 +49,7 @@ class Console "think\\console\\command\\Lists", "think\\console\\command\\Build", "think\\console\\command\\make\\Controller", - "think\\console\\command\\make\\Model", - "think\\console\\command\\cache\\Clear" + "think\\console\\command\\make\\Model" ]; public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') diff --git a/library/think/console/command/cache/Clear.php b/library/think/console/command/cache/Clear.php deleted file mode 100644 index 4babaa55..00000000 --- a/library/think/console/command/cache/Clear.php +++ /dev/null @@ -1,62 +0,0 @@ - -// +---------------------------------------------------------------------- - -namespace think\console\command\cache; - -use think\console\command\Command; -use think\console\Input; -use think\console\input\Option as InputOption; -use think\console\Output; - -class Clear extends Command -{ - /** - * {@inheritdoc} - */ - protected function configure() - { - $this->setName('cache:clear') - ->setDescription('Clear Application Runtime'); - } - - protected function execute(Input $input, Output $output) - { - if (APP_DEBUG) { - $output->writeln("Open debug, do not need clear."); - return; - } - $templateDir = RUNTIME_PATH . '\temp'; - if (!file_exists($templateDir)) { - $output->writeln("Runtime does not exist."); - return; - } - $this->rmdirs($templateDir); - $output->writeln("Clear done!"); - } - - protected function rmdirs($dir) - { - $dir_arr = scandir($dir); - foreach($dir_arr as $key=>$val){ - if($val == '.' || $val == '..'){} - else { - if(is_dir($dir.'/'.$val)) - { - if(@rmdir($dir.'/'.$val) == 'true'){} - else - rmdirs($dir.'/'.$val); - } - else - unlink($dir.'/'.$val); - } - } - } -} From 7770dd04b4ff08b4af1a9c35561adc7a81e00465 Mon Sep 17 00:00:00 2001 From: "Mr.Wang" <281762391@qq.com> Date: Tue, 5 Apr 2016 19:21:42 +0800 Subject: [PATCH 4/6] =?UTF-8?q?Log::record($log,=20'error');=20=20//=20?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E7=9A=84=E9=94=99=E8=AF=AF=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E6=98=AF=E6=9C=AA=E4=BF=9D=E5=AD=98=20=20=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E9=94=99=E8=AF=AF=20=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=B7=9F=E8=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Error.php | 1 + 1 file changed, 1 insertion(+) diff --git a/library/think/Error.php b/library/think/Error.php index 0f237aed..7a5fb4db 100644 --- a/library/think/Error.php +++ b/library/think/Error.php @@ -69,6 +69,7 @@ class Error // 记录异常日志 Log::record($log, 'error'); + Log::save(); /* 非API模式下的部署模式,跳转到指定的 Error Page */ $error_page = Config::get('error_page'); From 1daf055f56a008ec2b4c970ee62b60dab019e338 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Wed, 6 Apr 2016 11:08:51 +0800 Subject: [PATCH 5/6] =?UTF-8?q?null=E4=B8=BAphp7=E7=9A=84=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/console/output/{Null.php => Nothing.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename library/think/console/output/{Null.php => Nothing.php} (98%) diff --git a/library/think/console/output/Null.php b/library/think/console/output/Nothing.php similarity index 98% rename from library/think/console/output/Null.php rename to library/think/console/output/Nothing.php index 4e8f355c..93ca6fe8 100644 --- a/library/think/console/output/Null.php +++ b/library/think/console/output/Nothing.php @@ -14,7 +14,7 @@ namespace think\console\output; use think\console\Output; -class Null extends Output +class Nothing extends Output { /** @noinspection PhpMissingParentConstructorInspection */ public function __construct() From 4ab1dbddd0b6e185bccdcfc1fd71e47012ea848e Mon Sep 17 00:00:00 2001 From: cos800 Date: Fri, 8 Apr 2016 16:05:21 +0800 Subject: [PATCH 6/6] =?UTF-8?q?hook=20return=5Fdata=20=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed https://github.com/top-think/think/issues/438 --- library/think/Response.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/library/think/Response.php b/library/think/Response.php index 45507c35..536be418 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -61,17 +61,11 @@ class Response $handler = !empty($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler'); $data = $handler . '(' . json_encode($data, JSON_UNESCAPED_UNICODE) . ');'; break; - case '': - case 'html': - case 'text': - // 不做处理 - break; - default: - // 用于扩展其他返回格式数据 - APP_HOOK && Hook::listen('return_data', $data); } } + APP_HOOK && Hook::listen('return_data', $data); + if ($return) { return $data; }