RouteMap
in package
Route mapping and parameter extraction for HTTP requests.
This class represents a single route definition within the routing system, handling URL pattern matching, dynamic parameter extraction, and route execution with integrated filter support.
Key responsibilities:
- Parse route templates with dynamic parameters (e.g., /users/:id)
- Extract parameters from incoming URIs that match the route pattern
- Execute the associated callable with extracted parameters
- Integrate with the filter system for pre/post processing
- Handle route-specific parameter validation and type conversion
Route patterns support:
- Static segments: /users/profile
- Dynamic parameters: /users/:id, /posts/:slug
- Mixed patterns: /users/:id/posts/:post_id
Tags
Table of Contents
Properties
- $Filters : array<string|int, mixed>
- $Function : mixed
- $Name : string
- $Parameters : array<string|int, mixed>
- $Path : string
- $Payload : array<string|int, mixed>
- $_method : string|null
- $_router : Router|null
Methods
- __construct() : mixed
- RouteMap constructor.
- execute() : mixed
- getFilter() : string|null
- Legacy method for backward compatibility
- getFilters() : array<string|int, mixed>
- Get filters for this route
- getFunction() : callable
- getName() : mixed
- getParameters() : null
- getPath() : string
- parseParams() : array<string|int, mixed>
- Extracts the template array from the route definition.
- setFilter() : RouteMap
- Legacy method for backward compatibility
- setFilters() : RouteMap
- Set filters for this route
- setFunction() : RouteMap
- setName() : RouteMap
- Set the name for this route and register it with the router for duplicate detection.
- setParameters() : RouteMap
- setPath() : RouteMap
- setRouterContext() : RouteMap
- Set the router and method for this route (used for name duplicate detection)
- checkForDuplicateParams() : void
Properties
$Filters
public
array<string|int, mixed>
$Filters
$Function
public
mixed
$Function
$Name
public
string
$Name
$Parameters
public
array<string|int, mixed>
$Parameters
$Path
public
string
$Path
$Payload
public
array<string|int, mixed>
$Payload
$_method
private
string|null
$_method
= null
HTTP method for this route (GET, POST, etc.)
$_router
private
Router|null
$_router
= null
Reference to router for name validation
Methods
__construct()
RouteMap constructor.
public
__construct(mixed $path, mixed $function[, mixed $filters = '' ]) : mixed
Parameters
- $path : mixed
-
string route path i.e. /part/new or /part/:id
- $function : mixed
-
callable the function to call on a matching route.
- $filters : mixed = ''
-
string|array the name(s) of the filter(s) to match with this route.
Tags
execute()
public
execute(Router $router) : mixed
Parameters
- $router : Router
Tags
getFilter()
Legacy method for backward compatibility
public
getFilter() : string|null
Use getFilters() instead
Return values
string|nullgetFilters()
Get filters for this route
public
getFilters() : array<string|int, mixed>
Return values
array<string|int, mixed>getFunction()
public
getFunction() : callable
Return values
callablegetName()
public
getName() : mixed
getParameters()
public
getParameters() : null
Return values
nullgetPath()
public
getPath() : string
Return values
stringparseParams()
Extracts the template array from the route definition.
public
parseParams() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>setFilter()
Legacy method for backward compatibility
public
setFilter(string $filter) : RouteMap
Use setFilters() instead
Parameters
- $filter : string
Return values
RouteMapsetFilters()
Set filters for this route
public
setFilters(string|array<string|int, mixed> $filters) : RouteMap
Parameters
- $filters : string|array<string|int, mixed>
Return values
RouteMapsetFunction()
public
setFunction(callable $function) : RouteMap
Parameters
- $function : callable
Return values
RouteMapsetName()
Set the name for this route and register it with the router for duplicate detection.
public
setName(string $name) : RouteMap
Parameters
- $name : string
Tags
Return values
RouteMapsetParameters()
public
setParameters(array<string|int, mixed> $parameters) : RouteMap
Parameters
- $parameters : array<string|int, mixed>
Return values
RouteMapsetPath()
public
setPath(string $path) : RouteMap
Parameters
- $path : string
Return values
RouteMapsetRouterContext()
Set the router and method for this route (used for name duplicate detection)
public
setRouterContext(Router $router, string $method) : RouteMap
Parameters
- $router : Router
- $method : string
-
HTTP method (GET, POST, PUT, DELETE)
Return values
RouteMapcheckForDuplicateParams()
protected
checkForDuplicateParams(mixed $param, mixed $params) : void
Parameters
- $param : mixed
- $params : mixed