diff --git a/composer.json b/composer.json index 2e18e6e1..0d8a7207 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,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": { @@ -101,6 +102,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..a0bff9e4 --- /dev/null +++ b/src/Globals/global_class_alias.php @@ -0,0 +1,14 @@ +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(); } }