From 58b5963170f1bcfa8d2158dfd0e4eacd634b77b4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 24 May 2024 10:26:38 +0900 Subject: [PATCH] fix!: add missing methods to RouteCollectionInterface --- system/Router/RouteCollectionInterface.php | 80 ++++++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/system/Router/RouteCollectionInterface.php b/system/Router/RouteCollectionInterface.php index bc6ca022bf93..3c34a9be2d8a 100644 --- a/system/Router/RouteCollectionInterface.php +++ b/system/Router/RouteCollectionInterface.php @@ -22,9 +22,6 @@ * A Route Collection's sole job is to hold a series of routes. The required * number of methods is kept very small on purpose, but implementors may * add a number of additional methods to customize how the routes are defined. - * - * The RouteCollection provides the Router with the routes so that it can determine - * which controller should be run. */ interface RouteCollectionInterface { @@ -62,11 +59,19 @@ public function addPlaceholder($placeholder, ?string $pattern = null); */ public function setDefaultNamespace(string $value); + /** + * Returns the default namespace. + */ + public function getDefaultNamespace(): string; + /** * Sets the default controller to use when no other controller has been * specified. * * @return RouteCollectionInterface + * + * @TODO The default controller is only for auto-routing. So this should be + * removed in the future. */ public function setDefaultController(string $value); @@ -86,6 +91,9 @@ public function setDefaultMethod(string $value); * doesn't work well with PHP method names.... * * @return RouteCollectionInterface + * + * @TODO This method is only for auto-routing. So this should be removed in + * the future. */ public function setTranslateURIDashes(bool $value); @@ -96,6 +104,9 @@ public function setTranslateURIDashes(bool $value); * defined routes. * * If FALSE, will stop searching and do NO automatic routing. + * + * @TODO This method is only for auto-routing. So this should be removed in + * the future. */ public function setAutoRoute(bool $value): self; @@ -107,6 +118,9 @@ public function setAutoRoute(bool $value): self; * This setting is passed to the Router class and handled there. * * @param callable|null $callable + * + * @TODO This method is not related to the route collection. So this should + * be removed in the future. */ public function set404Override($callable = null): self; @@ -115,6 +129,9 @@ public function set404Override($callable = null): self; * or the controller/string. * * @return (Closure(string): (ResponseInterface|string|void))|string|null + * + * @TODO This method is not related to the route collection. So this should + * be removed in the future. */ public function get404Override(); @@ -122,6 +139,9 @@ public function get404Override(); * Returns the name of the default controller. With Namespace. * * @return string + * + * @TODO The default controller is only for auto-routing. So this should be + * removed in the future. */ public function getDefaultController(); @@ -136,6 +156,9 @@ public function getDefaultMethod(); * Returns the current value of the translateURIDashes setting. * * @return bool + * + * @TODO This method is only for auto-routing. So this should be removed in + * the future. */ public function shouldTranslateURIDashes(); @@ -143,15 +166,38 @@ public function shouldTranslateURIDashes(); * Returns the flag that tells whether to autoRoute URI against Controllers. * * @return bool + * + * @TODO This method is only for auto-routing. So this should be removed in + * the future. */ public function shouldAutoRoute(); /** * Returns the raw array of available routes. * - * @return array + * @param non-empty-string|null $verb HTTP verb like `GET`,`POST` or `*` or `CLI`. + * @param bool $includeWildcard Whether to include '*' routes. + */ + public function getRoutes(?string $verb = null, bool $includeWildcard = true): array; + + /** + * Returns one or all routes options + * + * @param string|null $from The route path (with placeholders or regex) + * @param string|null $verb HTTP verb like `GET`,`POST` or `*` or `CLI`. + * + * @return array [key => value] */ - public function getRoutes(); + public function getRoutesOptions(?string $from = null, ?string $verb = null): array; + + /** + * Sets the current HTTP verb. + * + * @param string $verb HTTP verb + * + * @return $this + */ + public function setHTTPVerb(string $verb); /** * Returns the current HTTP Verb being used. @@ -194,4 +240,28 @@ public function getRedirectCode(string $routeKey): int; * Get the flag that limit or not the routes with {locale} placeholder to App::$supportedLocales */ public function shouldUseSupportedLocalesOnly(): bool; + + /** + * Checks a route (using the "from") to see if it's filtered or not. + * + * @param string|null $verb HTTP verb like `GET`,`POST` or `*` or `CLI`. + */ + public function isFiltered(string $search, ?string $verb = null): bool; + + /** + * Returns the filters that should be applied for a single route, along + * with any parameters it might have. Parameters are found by splitting + * the parameter name on a colon to separate the filter name from the parameter list, + * and the splitting the result on commas. So: + * + * 'role:admin,manager' + * + * has a filter of "role", with parameters of ['admin', 'manager']. + * + * @param string $search routeKey + * @param string|null $verb HTTP verb like `GET`,`POST` or `*` or `CLI`. + * + * @return list filter_name or filter_name:arguments like 'role:admin,manager' + */ + public function getFiltersForRoute(string $search, ?string $verb = null): array; }