Skip to content

Commit

Permalink
fix!: add missing methods to RouteCollectionInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed May 24, 2024
1 parent f8e9438 commit 58b5963
Showing 1 changed file with 75 additions and 5 deletions.
80 changes: 75 additions & 5 deletions system/Router/RouteCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -115,13 +129,19 @@ 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();

/**
* 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();

Expand All @@ -136,22 +156,48 @@ 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();

/**
* 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<string, int|string> [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.
Expand Down Expand Up @@ -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<string> filter_name or filter_name:arguments like 'role:admin,manager'
*/
public function getFiltersForRoute(string $search, ?string $verb = null): array;
}

0 comments on commit 58b5963

Please sign in to comment.