From ac6964025369a1f250bfbc30c41134c61831f407 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 21 Aug 2022 20:15:55 +0800 Subject: [PATCH 1/3] add alias --- composer.json | 5 +-- src/Globals/global_class_alias.php | 12 +++++++ src/ZM/Annotation/AnnotationBase.php | 24 ++++++++++++-- src/ZM/Annotation/Middleware/HandleAfter.php | 21 ------------ src/ZM/Annotation/Middleware/HandleBefore.php | 21 ------------ .../Annotation/Middleware/HandleException.php | 31 ------------------ .../Annotation/Middleware/MiddlewareClass.php | 32 ------------------- src/ZM/InstantApplication.php | 25 +++++++++++++-- 8 files changed, 59 insertions(+), 112 deletions(-) create mode 100644 src/Globals/global_class_alias.php delete mode 100644 src/ZM/Annotation/Middleware/HandleAfter.php delete mode 100644 src/ZM/Annotation/Middleware/HandleBefore.php delete mode 100644 src/ZM/Annotation/Middleware/HandleException.php delete mode 100644 src/ZM/Annotation/Middleware/MiddlewareClass.php diff --git a/composer.json b/composer.json index e81639f5..f8d89a34 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,8 @@ }, "files": [ "src/Globals/global_functions.php", - "src/Globals/global_defines_app.php" + "src/Globals/global_defines_app.php", + "src/GLobals/global_class_alias.php" ] }, "autoload-dev": { @@ -102,6 +103,6 @@ ], "analyse": "phpstan analyse --memory-limit 300M", "cs-fix": "php-cs-fixer fix", - "test": "bin/phpunit-swoole --no-coverage" + "test": "bin/phpunit-zm --no-coverage" } } diff --git a/src/Globals/global_class_alias.php b/src/Globals/global_class_alias.php new file mode 100644 index 00000000..a7a0d1ed --- /dev/null +++ b/src/Globals/global_class_alias.php @@ -0,0 +1,12 @@ +method = $method; return $this; @@ -54,4 +59,19 @@ abstract class AnnotationBase implements IteratorAggregate { return new ArrayIterator($this); } + + public function isInGroup(string $name): bool + { + return in_array($name, $this->group); + } + + public function addGroup(string $name) + { + $this->group[] = $name; + } + + public function getGroups(): array + { + return $this->group; + } } diff --git a/src/ZM/Annotation/Middleware/HandleAfter.php b/src/ZM/Annotation/Middleware/HandleAfter.php deleted file mode 100644 index 1cb9ddc4..00000000 --- a/src/ZM/Annotation/Middleware/HandleAfter.php +++ /dev/null @@ -1,21 +0,0 @@ -class_name = $class_name; - } -} diff --git a/src/ZM/Annotation/Middleware/MiddlewareClass.php b/src/ZM/Annotation/Middleware/MiddlewareClass.php deleted file mode 100644 index 6d926d01..00000000 --- a/src/ZM/Annotation/Middleware/MiddlewareClass.php +++ /dev/null @@ -1,32 +0,0 @@ -name = $name; - } -} diff --git a/src/ZM/InstantApplication.php b/src/ZM/InstantApplication.php index 02b5bda1..6076aee1 100644 --- a/src/ZM/InstantApplication.php +++ b/src/ZM/InstantApplication.php @@ -5,12 +5,18 @@ declare(strict_types=1); namespace ZM; use Exception; +use ZM\Command\Server\ServerStartCommand; +use ZM\Config\ZMConfig; use ZM\Exception\InitException; use ZM\Plugin\InstantPlugin; class InstantApplication extends InstantPlugin { - private static $obj; + /** @var null|InstantApplication 存储单例类的变量 */ + private static ?InstantApplication $obj; + + /** @var array 存储要传入的args */ + private array $args = []; /** * @param null|mixed $dir @@ -22,7 +28,20 @@ class InstantApplication extends InstantPlugin throw new InitException(zm_internal_errcode('E00069') . 'Initializing another Application is not allowed!'); } self::$obj = $this; // 用于标记已经初始化完成 - parent::__construct($dir ?? __DIR__); + parent::__construct($dir ?? (__DIR__ . '/../..')); + $this->args = ServerStartCommand::exportOptionArray(); + } + + public function withConfig(array $config): InstantApplication + { + // TODO: 完成patch config + return $this; + } + + public function withArgs(array $args): InstantApplication + { + $this->args = ZMConfig::smartPatch($this->args, $args); + return $this; } /** @@ -30,6 +49,6 @@ class InstantApplication extends InstantPlugin */ public function run() { - (new Framework())->init()->start(); + (new Framework($this->args))->init()->start(); } } From 67ba8340cc772d66c7f4d236efa1eec611367656 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 21 Aug 2022 20:17:05 +0800 Subject: [PATCH 2/3] cs fix --- src/Globals/global_class_alias.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Globals/global_class_alias.php b/src/Globals/global_class_alias.php index a7a0d1ed..a0bff9e4 100644 --- a/src/Globals/global_class_alias.php +++ b/src/Globals/global_class_alias.php @@ -1,5 +1,7 @@ Date: Mon, 22 Aug 2022 15:32:29 +0800 Subject: [PATCH 3/3] fix typo --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f8d89a34..4fa29273 100644 --- a/composer.json +++ b/composer.json @@ -57,7 +57,7 @@ "files": [ "src/Globals/global_functions.php", "src/Globals/global_defines_app.php", - "src/GLobals/global_class_alias.php" + "src/Globals/global_class_alias.php" ] }, "autoload-dev": {