AutoRouter
in package
implements
AutoRouterInterface
Router for Auto-Routing
Table of Contents
Interfaces
- AutoRouterInterface
- Expected behavior of a AutoRouter.
Properties
- $cliRoutes : array<string, callable(mixed...): Array|string>
- List of CLI routes that do not contain '*' routes.
- $controller : string
- The name of the controller class.
- $defaultNamespace : string
- Default namespace for controllers.
- $directory : string|null
- Sub-directory that contains the requested controller class.
- $method : string
- The name of the method to use.
- $translateURIDashes : bool
- Whether dashes in URI's should be converted to underscores when determining method names.
Methods
- __construct() : mixed
- directory() : string
- Returns the name of the sub-directory the controller is in, if any. Relative to APPPATH.'Controllers'.
- getRoute() : array<string|int, mixed>
- Attempts to match a URI path against Controllers and directories found in APPPATH/Controllers, to find a matching route.
- setDirectory() : void
- Sets the sub-directory that the controller is in.
- setTranslateURIDashes() : self
- Tells the system whether we should translate URI dashes or not in the URI from a dash to an underscore.
- controllerName() : string
- isValidSegment() : bool
- Returns true if the supplied $segment string represents a valid PSR-4 compliant namespace/directory segment
- methodName() : string
- scanControllers() : array<string|int, mixed>
- Scans the controller directory, attempting to locate a controller matching the supplied uri $segments
Properties
$cliRoutes read-only
List of CLI routes that do not contain '*' routes.
private
array<string, callable(mixed...): Array|string>
$cliRoutes
[routeKey => handler]
$controller
The name of the controller class.
private
string
$controller
$defaultNamespace read-only
Default namespace for controllers.
private
string
$defaultNamespace
$directory
Sub-directory that contains the requested controller class.
private
string|null
$directory
= null
Primarily used by 'autoRoute'.
$method
The name of the method to use.
private
string
$method
$translateURIDashes
Whether dashes in URI's should be converted to underscores when determining method names.
private
bool
$translateURIDashes
Methods
__construct()
public
__construct(array<string|int, mixed> $cliRoutes, string $defaultNamespace, string $controller, string $method, bool $translateURIDashes) : mixed
Parameters
- $cliRoutes : array<string|int, mixed>
- $defaultNamespace : string
- $controller : string
- $method : string
- $translateURIDashes : bool
directory()
Returns the name of the sub-directory the controller is in, if any. Relative to APPPATH.'Controllers'.
public
directory() : string
This method should be removed.
Return values
stringgetRoute()
Attempts to match a URI path against Controllers and directories found in APPPATH/Controllers, to find a matching route.
public
getRoute(string $uri, string $httpVerb) : array<string|int, mixed>
Parameters
- $uri : string
- $httpVerb : string
-
HTTP verb like
GET
,POST
Return values
array<string|int, mixed> —[directory_name, controller_name, controller_method, params]
setDirectory()
Sets the sub-directory that the controller is in.
public
setDirectory([string|null $dir = null ][, bool $append = false ][, bool $validate = true ]) : void
This method should be removed.
Parameters
- $dir : string|null = null
- $append : bool = false
- $validate : bool = true
-
if true, checks to make sure $dir consists of only PSR4 compliant segments
setTranslateURIDashes()
Tells the system whether we should translate URI dashes or not in the URI from a dash to an underscore.
public
setTranslateURIDashes([bool $val = false ]) : self
This method should be removed.
Parameters
- $val : bool = false
Return values
selfcontrollerName()
private
controllerName() : string
Return values
stringisValidSegment()
Returns true if the supplied $segment string represents a valid PSR-4 compliant namespace/directory segment
private
isValidSegment(string $segment) : bool
regex comes from https://www.php.net/manual/en/language.variables.basics.php
Parameters
- $segment : string
Return values
boolmethodName()
private
methodName() : string
Return values
stringscanControllers()
Scans the controller directory, attempting to locate a controller matching the supplied uri $segments
private
scanControllers(array<string|int, mixed> $segments) : array<string|int, mixed>
Parameters
- $segments : array<string|int, mixed>
-
URI segments
Return values
array<string|int, mixed> —returns an array of remaining uri segments that don't map onto a directory