This commit is contained in:
xl
2023-11-14 00:09:52 +08:00
parent cde7fe3f2d
commit ef3fb24ba4
7 changed files with 42 additions and 28 deletions
+4 -2
View File
@@ -19,7 +19,7 @@ class Delete extends AbstractRequestMethod implements InjectRouteInterface
* @param string $path * @param string $path
* @param string $version * @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. // TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/'); $path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_DELETE, $path, [$class, $method]); Router::addRoute(RequestMethod::REQUEST_DELETE, $path, [$class, $method]);
} }
+4 -2
View File
@@ -19,7 +19,7 @@ class Get extends AbstractRequestMethod implements InjectRouteInterface
* @param string $path * @param string $path
* @param string $version * @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. // TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/'); $path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_GET, $path, [$class, $method]); Router::addRoute(RequestMethod::REQUEST_GET, $path, [$class, $method]);
} }
+4 -2
View File
@@ -18,7 +18,7 @@ class Head extends AbstractRequestMethod implements InjectRouteInterface
* @param string $path * @param string $path
* @param string $version * @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. // TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/'); $path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_HEAD, $path, [$class, $method]); Router::addRoute(RequestMethod::REQUEST_HEAD, $path, [$class, $method]);
} }
+4 -2
View File
@@ -18,7 +18,7 @@ class Options extends AbstractRequestMethod implements InjectRouteInterface
* @param string $path * @param string $path
* @param string $version * @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. // TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/'); $path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_OPTIONS, $path, [$class, $method]); Router::addRoute(RequestMethod::REQUEST_OPTIONS, $path, [$class, $method]);
} }
+4 -2
View File
@@ -19,7 +19,7 @@ class Post extends AbstractRequestMethod implements InjectRouteInterface
* @param string $path * @param string $path
* @param string $version * @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. // TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/'); $path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_POST, $path, [$class, $method]); Router::addRoute(RequestMethod::REQUEST_POST, $path, [$class, $method]);
} }
+4 -2
View File
@@ -19,7 +19,7 @@ class Put extends AbstractRequestMethod implements InjectRouteInterface
* @param string $path * @param string $path
* @param string $version * @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. // TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/'); $path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute(RequestMethod::REQUEST_PUT, $path, [$class, $method]); Router::addRoute(RequestMethod::REQUEST_PUT, $path, [$class, $method]);
} }
+4 -2
View File
@@ -17,7 +17,7 @@ class Route extends AbstractRequestMethod implements InjectRouteInterface
* @param RequestMethod $method * @param RequestMethod $method
* @param string $version * @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 = '')
{ {
} }
@@ -32,7 +32,9 @@ class Route extends AbstractRequestMethod implements InjectRouteInterface
{ {
// TODO: Implement dispatch() method. // TODO: Implement dispatch() method.
$path = '/' . ltrim($this->path, '/'); $path = '/' . ltrim($this->path, '/');
if (!empty($this->version)) {
$path = '/' . trim($this->version) . $path;
}
Router::addRoute([$this->method], $path, [$class, $method]); Router::addRoute([$this->method], $path, [$class, $method]);
} }
} }