From c2d9250be91a30b1d52a11ae25cd6201c50aead2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 15 Dec 2020 12:24:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Annotation/After.php | 33 --------------- Annotation/IAnnotation.php | 5 ++- Annotation/Interceptor.php | 33 --------------- Annotation/Limits.php | 33 --------------- Annotation/Middleware.php | 33 --------------- Annotation/RequestValidator.php | 23 +++++++++++ Annotation/Route/Node.php | 32 +++++++++++++++ Annotation/{ => Route}/Route.php | 16 +++----- Annotation/Route/Socket.php | 70 ++++++++++++++++++++++++++++++++ Annotation/Socket.php | 52 ------------------------ 10 files changed, 134 insertions(+), 196 deletions(-) delete mode 100644 Annotation/After.php delete mode 100644 Annotation/Interceptor.php delete mode 100644 Annotation/Limits.php delete mode 100644 Annotation/Middleware.php create mode 100644 Annotation/RequestValidator.php create mode 100644 Annotation/Route/Node.php rename Annotation/{ => Route}/Route.php (78%) create mode 100644 Annotation/Route/Socket.php delete mode 100644 Annotation/Socket.php diff --git a/Annotation/After.php b/Annotation/After.php deleted file mode 100644 index 2c63417f..00000000 --- a/Annotation/After.php +++ /dev/null @@ -1,33 +0,0 @@ -handler; - } - - -} diff --git a/Annotation/IAnnotation.php b/Annotation/IAnnotation.php index fd5b3e88..00639a1c 100644 --- a/Annotation/IAnnotation.php +++ b/Annotation/IAnnotation.php @@ -11,10 +11,11 @@ interface IAnnotation /** - * @param array|Closure $closure + * @param array|Closure $handler + * @param array $attributes * @return mixed */ - public function setHandler(array|Closure $closure): mixed; + public function setHandler(array|Closure $handler, array $attributes): mixed; } diff --git a/Annotation/Interceptor.php b/Annotation/Interceptor.php deleted file mode 100644 index 77531faf..00000000 --- a/Annotation/Interceptor.php +++ /dev/null @@ -1,33 +0,0 @@ -handler; - } - - -} diff --git a/Annotation/Limits.php b/Annotation/Limits.php deleted file mode 100644 index 19f167bb..00000000 --- a/Annotation/Limits.php +++ /dev/null @@ -1,33 +0,0 @@ -handler; - } - - -} diff --git a/Annotation/Middleware.php b/Annotation/Middleware.php deleted file mode 100644 index 5bff8a95..00000000 --- a/Annotation/Middleware.php +++ /dev/null @@ -1,33 +0,0 @@ -handler; - } - - -} diff --git a/Annotation/RequestValidator.php b/Annotation/RequestValidator.php new file mode 100644 index 00000000..edcc6c42 --- /dev/null +++ b/Annotation/RequestValidator.php @@ -0,0 +1,23 @@ +middleware)) { + $node->addMiddleware($this->middleware); + } + if (!empty($this->interceptor)) { + $node->addInterceptor($this->interceptor); + } + if (!empty($this->limits)) { + $node->addLimits($this->limits); + } + if (!empty($this->after)) { + $node->addAfter($this->after); + } + return $node; + } + +} diff --git a/Annotation/Route.php b/Annotation/Route/Route.php similarity index 78% rename from Annotation/Route.php rename to Annotation/Route/Route.php index 3e073ff6..48bffebb 100644 --- a/Annotation/Route.php +++ b/Annotation/Route/Route.php @@ -1,18 +1,21 @@ addRoute($this->uri, $handler, $this->method); - foreach ($attributes as $name => $attribute) { - $first = 'add' . ucfirst($attribute); - $_handler = is_array($handler) ? $handler[0] : $handler; - if (!method_exists($_handler, $first)) { - continue; - } - $node->$first($attribute); - } - return $node; + return $this->add($node); } diff --git a/Annotation/Route/Socket.php b/Annotation/Route/Socket.php new file mode 100644 index 00000000..bdad21fb --- /dev/null +++ b/Annotation/Route/Socket.php @@ -0,0 +1,70 @@ +getRouter(); + // TODO: Implement setHandler() method. + + $method = $this->event . '::' . ($this->uri ?? 'event'); + $node = $router->addRoute($method, $handler, 'sw::socket'); + + return $this->add($node); + } + +} diff --git a/Annotation/Socket.php b/Annotation/Socket.php deleted file mode 100644 index aec9fccd..00000000 --- a/Annotation/Socket.php +++ /dev/null @@ -1,52 +0,0 @@ -getRouter(); - // TODO: Implement setHandler() method. - - $method = $this->event . '::' . ($this->uri ?? 'event'); - - return $router->addRoute($method, $closure, 'sw::socket'); - } - -}