diff --git a/src/owoframe/console/Console.php b/src/owoframe/console/Console.php index c494ed7..9d78752 100644 --- a/src/owoframe/console/Console.php +++ b/src/owoframe/console/Console.php @@ -108,7 +108,7 @@ public function monitor(array $input = []) : void if($command instanceof CommandBase) { if(!$command->execute($input)) { - $command->getUsage(); + System::getMainLogger()->info($command->getUsage()); // System::getMainLogger()->debug("Command '{$inputCommand}' may not execute successfully, please check the issue."); } } else { diff --git a/src/owoframe/console/command/AppGeneratorCommand.php b/src/owoframe/console/command/AppGeneratorCommand.php index 8ff53d6..c61cdd4 100644 --- a/src/owoframe/console/command/AppGeneratorCommand.php +++ b/src/owoframe/console/command/AppGeneratorCommand.php @@ -11,7 +11,7 @@ * @Author : HanskiJay * @Date : 2023-02-15 18:49:38 * @LastEditors : HanskiJay - * @LastEditTime : 2023-02-15 19:04:39 + * @LastEditTime : 2023-02-20 05:46:56 * @E-Mail : support@owoblog.com * @Telegram : https://t.me/HanskiJay * @GitHub : https://github.com/Tommy131 @@ -22,7 +22,6 @@ use owoframe\console\CommandBase; -use owoframe\System; class AppGeneratorCommand extends CommandBase { @@ -34,7 +33,7 @@ public function execute(array $params) : bool } $appName = strtolower($appName); $upAppName = ucfirst($appName); - $appPath = \owo\application_path($appName); + $appPath = \owo\application_path($appName, true); $ctlPath = $appPath . 'controller' . DIRECTORY_SEPARATOR; $viewPath = $appPath . 'view' . DIRECTORY_SEPARATOR; $staticPath = $viewPath . 'static' . DIRECTORY_SEPARATOR; @@ -49,12 +48,14 @@ public function execute(array $params) : bool if(!is_dir($staticPath)) mkdir($staticPath, 755, true); // Make application main info class file - file_put_contents($appPath . $upAppName . 'App.php', str_replace(['{appName_s}', '{appName_u}'], [$appName, $upAppName], base64_decode('PD9waHAKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCSBfX19fXyAgIF8gICAgICAgICAgX18gIF9fX19fICAgX19fX18gICBfICAgICAgIF9fX19fIC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pYyBzdGF0aWMgZnVuY3Rpb24gYXV0b1RvNDA0UGFnZSgpIDogYm9vbAoJewoJCXJldHVybiB0cnVlOwoJfQoKCXB1YmxpYyBzdGF0aWMgZnVuY3Rpb24gaXNDTElPbmx5KCkgOiBib29sCgl7CgkJcmV0dXJuIGZhbHNlOwoJfQoKCXB1YmxpYyBzdGF0aWMgZnVuY3Rpb24gZ2V0QXV0aG9yKCkgOiBzdHJpbmcKCXsKCQlyZXR1cm4gJyc7Cgl9CgoJcHVibGljIHN0YXRpYyBmdW5jdGlvbiBnZXREZXNjcmlwdGlvbigpIDogc3RyaW5nCgl7CgkJcmV0dXJuICcnOwoJfQp9Cj8+'))); + $appFile = $appPath . $upAppName . 'App.php'; + file_put_contents($appFile, str_replace(['applicationName', 'className'], [$appName, $upAppName . 'App'], file_get_contents(\owo\s_template_path('DefaultAppTemplate.php')))); // Make application default controller file - file_put_contents($ctlPath . $upAppName . '.php', str_replace(['{appName_s}', '{appName_u}'], [$appName, $upAppName], base64_decode('PD9waHAKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioKCSBfX19fXyAgIF8gICAgICAgICAgX18gIF9fX19fICAgX19fX18gICBfICAgICAgIF9fX19fICAgX19fX18KCS8gIF8gIFwgfCB8ICAgICAgICAvIC8gLyAgXyAgXCB8ICBfICBcIHwgfCAgICAgLyAgXyAgXCAvICBfX198Cgl8IHwgfCB8IHwgfCAgX18gICAvIC8gIHwgfCB8IHwgfCB8X3wgfCB8IHwgICAgIHwgfCB8IHwgfCB8Cgl8IHwgfCB8IHwgfCAvICB8IC8gLyAgIHwgfCB8IHwgfCAgXyAgeyB8IHwgICAgIHwgfCB8IHwgfCB8ICBfCgl8IHxffCB8IHwgfC8gICB8LyAvICAgIHwgfF98IHwgfCB8X3wgfCB8IHxfX18gIHwgfF98IHwgfCB8X3wgfAoJXF9fX19fLyB8X19fL3xfX18vICAgICBcX19fX18vIHxfX19fXy8gfF9fX19ffCBcX19fX18vIFxfX19fXy8KCgkqIENvcHlyaWdodCAoYykgMjAxNS0yMDIxIE93T0Jsb2ctREdNVC4KCSogRGV2ZWxvcGVyOiBIYW5za2lKYXkoVG9tbXkxMzEpCgkqIFRlbGVncmFtOiAgaHR0cHM6Ly90Lm1lL0hhbnNraUpheQoJKiBFLU1haWw6ICAgIHN1cHBvcnRAb3dvYmxvZy5jb20KCSogR2l0SHViOiAgICBodHRwczovL2dpdGh1Yi5jb20vVG9tbXkxMzEKCioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCgpkZWNsYXJlKHN0cmljdF90eXBlcz0xKTsKbmFtZXNwYWNlIGFwcGxpY2F0aW9uXHthcHBOYW1lX3N9XGNvbnRyb2xsZXI7CgpjbGFzcyB7YXBwTmFtZV91fSBleHRlbmRzIFxvd29mcmFtZVxhcHBsaWNhdGlvblxDb250cm9sbGVyQmFzZQp7CglwdWJsaWMgZnVuY3Rpb24ge2FwcE5hbWVfdX0oKQoJewoJCXJldHVybiAnSGVsbG8gd29ybGQhIFRoaXMgYXBwbGljYXRpb24gd2FzIGdlbmVyYXRlZCBieSBPd09GcmFtZTo6UXVpY2tBcHBGcmFtR2VuZXJhdG9yLCB3ZWxjb21lIHRvIHVzZSBpdCA6KSc7Cgl9Cn0KPz4='))); + $controllerFile = $ctlPath . $upAppName . '.php'; + file_put_contents($controllerFile, str_replace(['applicationName', 'className'], [$appName, $upAppName], file_get_contents(\owo\s_template_path('DefaultControllerTemplate.php')))); - if(System::getApplication($appName)) { + if(is_dir($appPath) && is_file($appFile) && is_file($controllerFile)) { $this->getLogger()->success("Generated empty AppFrame '{$upAppName}' successfully. Please check the app path '{$appPath}' to develop it."); return true; } else { diff --git a/src/owoframe/console/command/ClearCommand.php b/src/owoframe/console/command/ClearCommand.php index fcfad5e..eeb0ad4 100644 --- a/src/owoframe/console/command/ClearCommand.php +++ b/src/owoframe/console/command/ClearCommand.php @@ -52,6 +52,11 @@ public function execute(array $params) : bool $this->getLogger()->info($param); } else { $files = iterator_to_array(new FI(\owo\log_path(), FI::CURRENT_AS_PATHNAME | FI::SKIP_DOTS), false); + if(count($files) === 1) { + $this->getLogger()->info('No files to delete.'); + return true; + } + foreach($files as $file) { $baseName = basename($file); $ext = @end(explode('.', $baseName)); diff --git a/src/owoframe/console/command/RemoveAppCommand.php b/src/owoframe/console/command/RemoveAppCommand.php index 7058dbf..e372818 100644 --- a/src/owoframe/console/command/RemoveAppCommand.php +++ b/src/owoframe/console/command/RemoveAppCommand.php @@ -11,7 +11,7 @@ * @Author : HanskiJay * @Date : 2023-02-15 18:49:38 * @LastEditors : HanskiJay - * @LastEditTime : 2023-02-15 19:29:40 + * @LastEditTime : 2023-02-20 05:56:08 * @E-Mail : support@owoblog.com * @Telegram : https://t.me/HanskiJay * @GitHub : https://github.com/Tommy131 @@ -22,6 +22,7 @@ use owoframe\console\CommandBase; +use owoframe\object\Pipe; use owoframe\System; class RemoveAppCommand extends CommandBase @@ -39,15 +40,19 @@ public function execute(array $params) : bool return true; } - $answer = (string) \owo\ask('ARE YOU SURE THAT YOU WANT TO DELETE/REMOVE THIS APPLICATION? THIS OPERATION IS IRREVERSIBLE! [Y/N]', 'N', '[WARNING] '); - if(strtolower($answer) === 'y') { - $this->getLogger()->warning('Now will remove this application forever...'); - if(\owo\remove_dir(\owo\application_path(strtolower($appName)))) { - $this->getLogger()->success("Removed Application '{$appName}' successfully."); + \owo\pipe_ask('ARE YOU SURE THAT YOU WANT TO DELETE/REMOVE THIS APPLICATION? THIS OPERATION IS IRREVERSIBLE! [Y/N]', ['y', 'Y', 'yes', 'YES']) + ->do(function(Pipe $object) use ($appName) { + if($object->isContinue()) { + $this->getLogger()->warning('Now will remove this application forever...'); + if(\owo\remove_dir(\owo\application_path(strtolower($appName)))) { + $this->getLogger()->success("Removed Application '{$appName}' successfully."); + } else { + $this->getLogger()->error('Somewhere was wrong that cannot remove this application!'); + } } else { - $this->getLogger()->error('Somewhere was wrong that cannot remove this application!'); + $this->getLogger()->info('Cancelled.'); } - } + }); return true; } diff --git a/src/owoframe/object/Pipe.php b/src/owoframe/object/Pipe.php index 14bdb6b..3451e57 100644 --- a/src/owoframe/object/Pipe.php +++ b/src/owoframe/object/Pipe.php @@ -11,7 +11,7 @@ * @Author : HanskiJay * @Date : 2023-02-20 03:05:15 * @LastEditors : HanskiJay - * @LastEditTime : 2023-02-20 04:19:27 + * @LastEditTime : 2023-02-20 06:18:41 * @E-Mail : support@owoblog.com * @Telegram : https://t.me/HanskiJay * @GitHub : https://github.com/Tommy131 @@ -106,6 +106,17 @@ public function then() : Pipe return $this; } + /** + * 立刻执行此操作, 不检测 + * + * @return Pipe + */ + public function do(callable $callback) : Pipe + { + $this->lastResult = $callback($this); + return $this; + } + /** * 最终执行方法 * @@ -114,7 +125,11 @@ public function then() : Pipe */ public function finally(callable $callback) : Pipe { - $this->finalResult = $callback($this); + if($this->isContinue()) { + $this->finalResult = $callback($this); + } else { + $this->lastResult = null; + } return $this; } diff --git a/src/owoframe/template/default/DefaultAppTemplate.php b/src/owoframe/template/default/DefaultAppTemplate.php new file mode 100644 index 0000000..11c232d --- /dev/null +++ b/src/owoframe/template/default/DefaultAppTemplate.php @@ -0,0 +1,50 @@ + 'applicationName', + # 基本信息 + 'author' => 'OwOTeam', + 'version' => '1.0.0', + 'description' => 'default description', + # 允许应用程序在PHP模式下加载 (CGI, CLI) + 'loadMode' => ['cgi', 'cli'] + ]; + + + public function initialize() : void + { + } +} +?> \ No newline at end of file diff --git a/src/owoframe/template/default/DefaultControllerTemplate.php b/src/owoframe/template/default/DefaultControllerTemplate.php new file mode 100644 index 0000000..af3fe81 --- /dev/null +++ b/src/owoframe/template/default/DefaultControllerTemplate.php @@ -0,0 +1,33 @@ + \ No newline at end of file diff --git a/src/script/systemFunctions.php b/src/script/systemFunctions.php index f7e1f96..399735e 100644 --- a/src/script/systemFunctions.php +++ b/src/script/systemFunctions.php @@ -11,7 +11,7 @@ * @Author : HanskiJay * @Date : 2023-02-01 20:34:03 * @LastEditors : HanskiJay - * @LastEditTime : 2023-02-20 04:04:18 + * @LastEditTime : 2023-02-20 06:13:56 * @E-Mail : support@owoblog.com * @Telegram : https://t.me/HanskiJay * @GitHub : https://github.com/Tommy131 @@ -581,11 +581,17 @@ function pipe_ask(string $question, $expect) : Pipe if(!is_array($expect)) { return (is_string($expect) && is_string($result) && str_is_regex($expect) && preg_match_all($expect, $result)) ? true : ($result === $expect) || (is_string($expect) && (strtolower($expect) === $allowAll)); } else { - return isset($expect[array_search($result, $expect)]); + return in_array($result, $expect); } }); } - $object->setExpectingResults($expect)->then($question); + + if(is_array($expect)) { + $object->setExpectingResults($expect); + } else { + $object->setExpectingResult($expect); + } + $object->then($question); return $object; }