diff --git a/src/Annotate/Delete.php b/src/Annotate/Delete.php index 8f48578..db6eb50 100644 --- a/src/Annotate/Delete.php +++ b/src/Annotate/Delete.php @@ -19,7 +19,7 @@ class Delete extends AbstractRequestMethod implements InjectRouteInterface * @param string $path * @param string $version */ - public function __construct(readonly public string $path, readonly public string $version = 'v1') + public function __construct(readonly public string $path, readonly public string $version = '') { } @@ -35,7 +35,9 @@ class Delete extends AbstractRequestMethod implements InjectRouteInterface { // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); - + if (!empty($this->version)) { + $path = '/' . trim($this->version) . $path; + } Router::addRoute(RequestMethod::REQUEST_DELETE, $path, [$class, $method]); } diff --git a/src/Annotate/Get.php b/src/Annotate/Get.php index c00ff2f..8af551b 100644 --- a/src/Annotate/Get.php +++ b/src/Annotate/Get.php @@ -19,7 +19,7 @@ class Get extends AbstractRequestMethod implements InjectRouteInterface * @param string $path * @param string $version */ - public function __construct(readonly public string $path, readonly public string $version = 'v1') + public function __construct(readonly public string $path, readonly public string $version = '') { } @@ -35,7 +35,9 @@ class Get extends AbstractRequestMethod implements InjectRouteInterface { // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); - + if (!empty($this->version)) { + $path = '/' . trim($this->version) . $path; + } Router::addRoute(RequestMethod::REQUEST_GET, $path, [$class, $method]); } diff --git a/src/Annotate/Head.php b/src/Annotate/Head.php index a7a0e69..c0a39b6 100644 --- a/src/Annotate/Head.php +++ b/src/Annotate/Head.php @@ -18,7 +18,7 @@ class Head extends AbstractRequestMethod implements InjectRouteInterface * @param string $path * @param string $version */ - public function __construct(readonly public string $path, readonly public string $version = 'v1') + public function __construct(readonly public string $path, readonly public string $version = '') { } @@ -34,7 +34,9 @@ class Head extends AbstractRequestMethod implements InjectRouteInterface { // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); - + if (!empty($this->version)) { + $path = '/' . trim($this->version) . $path; + } Router::addRoute(RequestMethod::REQUEST_HEAD, $path, [$class, $method]); } diff --git a/src/Annotate/Options.php b/src/Annotate/Options.php index 19e7b19..640efb3 100644 --- a/src/Annotate/Options.php +++ b/src/Annotate/Options.php @@ -18,7 +18,7 @@ class Options extends AbstractRequestMethod implements InjectRouteInterface * @param string $path * @param string $version */ - public function __construct(readonly public string $path, readonly public string $version = 'v1') + public function __construct(readonly public string $path, readonly public string $version = '') { } @@ -34,7 +34,9 @@ class Options extends AbstractRequestMethod implements InjectRouteInterface { // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); - + if (!empty($this->version)) { + $path = '/' . trim($this->version) . $path; + } Router::addRoute(RequestMethod::REQUEST_OPTIONS, $path, [$class, $method]); } diff --git a/src/Annotate/Post.php b/src/Annotate/Post.php index f2cd758..671ccc3 100644 --- a/src/Annotate/Post.php +++ b/src/Annotate/Post.php @@ -19,7 +19,7 @@ class Post extends AbstractRequestMethod implements InjectRouteInterface * @param string $path * @param string $version */ - public function __construct(readonly public string $path, readonly public string $version = 'v1') + public function __construct(readonly public string $path, readonly public string $version = '') { } @@ -35,7 +35,9 @@ class Post extends AbstractRequestMethod implements InjectRouteInterface { // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); - + if (!empty($this->version)) { + $path = '/' . trim($this->version) . $path; + } Router::addRoute(RequestMethod::REQUEST_POST, $path, [$class, $method]); } diff --git a/src/Annotate/Put.php b/src/Annotate/Put.php index 4023587..836543f 100644 --- a/src/Annotate/Put.php +++ b/src/Annotate/Put.php @@ -19,7 +19,7 @@ class Put extends AbstractRequestMethod implements InjectRouteInterface * @param string $path * @param string $version */ - public function __construct(readonly public string $path, readonly public string $version = 'v1') + public function __construct(readonly public string $path, readonly public string $version = '') { } @@ -35,7 +35,9 @@ class Put extends AbstractRequestMethod implements InjectRouteInterface { // TODO: Implement dispatch() method. $path = '/' . ltrim($this->path, '/'); - + if (!empty($this->version)) { + $path = '/' . trim($this->version) . $path; + } Router::addRoute(RequestMethod::REQUEST_PUT, $path, [$class, $method]); } diff --git a/src/Annotate/Route.php b/src/Annotate/Route.php index c4d55ba..1a1cb5d 100644 --- a/src/Annotate/Route.php +++ b/src/Annotate/Route.php @@ -17,22 +17,24 @@ class Route extends AbstractRequestMethod implements InjectRouteInterface * @param RequestMethod $method * @param string $version */ - public function __construct(readonly public string $path, readonly public RequestMethod $method, readonly public string $version = 'v1') - { - } + public function __construct(readonly public string $path, readonly public RequestMethod $method, readonly public string $version = '') + { + } - /** - * @param object $class - * @param string $method - * @return void - * @throws ReflectionException - */ - public function dispatch(object $class, string $method): void - { - // TODO: Implement dispatch() method. - $path = '/' . ltrim($this->path, '/'); - - Router::addRoute([$this->method], $path, [$class, $method]); - } + /** + * @param object $class + * @param string $method + * @return void + * @throws ReflectionException + */ + public function dispatch(object $class, string $method): void + { + // TODO: Implement dispatch() method. + $path = '/' . ltrim($this->path, '/'); + if (!empty($this->version)) { + $path = '/' . trim($this->version) . $path; + } + Router::addRoute([$this->method], $path, [$class, $method]); + } }