This commit is contained in:
2023-04-19 12:35:39 +08:00
parent a16bb3a19c
commit aa8fb228cc
12 changed files with 151 additions and 55 deletions
+6 -3
View File
@@ -5,6 +5,7 @@ namespace Kiri\Router\Annotate;
use Kiri\Router\Constrict\RequestMethod;
use Kiri\Router\Interface\InjectRouteInterface;
use Kiri\Router\Router;
use ReflectionException;
#[\Attribute(\Attribute::TARGET_METHOD)]
class Route extends AbstractRequestMethod implements InjectRouteInterface
@@ -15,7 +16,7 @@ class Route extends AbstractRequestMethod implements InjectRouteInterface
* @param string $path
* @param RequestMethod $method
*/
public function __construct(readonly public string $path, readonly public RequestMethod $method)
public function __construct(readonly public string $path, readonly public RequestMethod $method, readonly public string $version = 'v1')
{
}
@@ -24,11 +25,13 @@ class Route extends AbstractRequestMethod implements InjectRouteInterface
* @param object $class
* @param string $method
* @return void
* @throws \ReflectionException
* @throws ReflectionException
*/
public function dispatch(object $class, string $method): void
{
// TODO: Implement dispatch() method.
Router::addRoute($this->method, $this->path, [$class, $method]);
$path = $this->version . '/' . ltrim($this->path, '/');
Router::addRoute([$this->method], $path, [$class, $method]);
}
}