3
declare(strict_types=1);
6
* This file is part of CodeIgniter 4 framework.
8
* (c) CodeIgniter Foundation <admin@codeigniter.com>
10
* For the full copyright and license information, please view
11
* the LICENSE file that was distributed with this source code.
14
namespace CodeIgniter\Router;
17
use CodeIgniter\HTTP\ResponseInterface;
20
* Interface RouteCollectionInterface
22
* A Route Collection's sole job is to hold a series of routes. The required
23
* number of methods is kept very small on purpose, but implementors may
24
* add a number of additional methods to customize how the routes are defined.
26
* The RouteCollection provides the Router with the routes so that it can determine
27
* which controller should be run.
29
interface RouteCollectionInterface
32
* Adds a single route to the collection.
34
* @param string $from The route path (with placeholders or regex)
35
* @param array|(Closure(mixed...): (ResponseInterface|string|void))|string $to The route handler
36
* @param array|null $options The route options
38
* @return RouteCollectionInterface
40
public function add(string $from, $to, ?array $options = null);
43
* Registers a new constraint with the system. Constraints are used
44
* by the routes as placeholders for regular expressions to make defining
45
* the routes more human-friendly.
47
* You can pass an associative array as $placeholder, and have
48
* multiple placeholders added at once.
50
* @param array|string $placeholder
51
* @param string|null $pattern The regex pattern
53
* @return RouteCollectionInterface
55
public function addPlaceholder($placeholder, ?string $pattern = null);
58
* Sets the default namespace to use for Controllers when no other
59
* namespace has been specified.
61
* @return RouteCollectionInterface
63
public function setDefaultNamespace(string $value);
66
* Sets the default controller to use when no other controller has been
69
* @return RouteCollectionInterface
71
public function setDefaultController(string $value);
74
* Sets the default method to call on the controller when no other
75
* method has been set in the route.
77
* @return RouteCollectionInterface
79
public function setDefaultMethod(string $value);
82
* Tells the system whether to convert dashes in URI strings into
83
* underscores. In some search engines, including Google, dashes
84
* create more meaning and make it easier for the search engine to
85
* find words and meaning in the URI for better SEO. But it
86
* doesn't work well with PHP method names....
88
* @return RouteCollectionInterface
90
public function setTranslateURIDashes(bool $value);
93
* If TRUE, the system will attempt to match the URI against
94
* Controllers by matching each segment against folders/files
95
* in APPPATH/Controllers, when a match wasn't found against
98
* If FALSE, will stop searching and do NO automatic routing.
100
public function setAutoRoute(bool $value): self;
103
* Sets the class/method that should be called if routing doesn't
104
* find a match. It can be either a closure or the controller/method
105
* name exactly like a route is defined: Users::index
107
* This setting is passed to the Router class and handled there.
109
* @param callable|null $callable
111
public function set404Override($callable = null): self;
114
* Returns the 404 Override setting, which can be null, a closure
115
* or the controller/string.
117
* @return (Closure(string): (ResponseInterface|string|void))|string|null
119
public function get404Override();
122
* Returns the name of the default controller. With Namespace.
126
public function getDefaultController();
129
* Returns the name of the default method to use within the controller.
133
public function getDefaultMethod();
136
* Returns the current value of the translateURIDashes setting.
140
public function shouldTranslateURIDashes();
143
* Returns the flag that tells whether to autoRoute URI against Controllers.
147
public function shouldAutoRoute();
150
* Returns the raw array of available routes.
154
public function getRoutes();
157
* Returns the current HTTP Verb being used.
161
public function getHTTPVerb();
164
* Attempts to look up a route based on its destination.
168
* 'path/(:any)/(:any)' => 'Controller::method/$1/$2'
170
* This method allows you to know the Controller and method
171
* and get the route that leads to it.
173
* // Equals 'path/$param1/$param2'
174
* reverseRoute('Controller::method', $param1, $param2);
176
* @param string $search Named route or Controller::method
177
* @param int|string ...$params
179
* @return false|string The route (URI path relative to baseURL) or false if not found.
181
public function reverseRoute(string $search, ...$params);
184
* Determines if the route is a redirecting route.
186
public function isRedirect(string $routeKey): bool;
189
* Grabs the HTTP status code from a redirecting Route.
191
public function getRedirectCode(string $routeKey): int;
194
* Get the flag that limit or not the routes with {locale} placeholder to App::$supportedLocales
196
public function shouldUseSupportedLocalesOnly(): bool;