Router class manages HTTP method routing, parses registered routes, and handles the current requested URI. It provides a fluent interface for defining routes and middleware.
Static route methods
Define routes using static HTTP method calls.get()
Register a GET route.The URI pattern to match (supports parameters like
{id})Callback function or controller method to handle the request
Returns a Route instance for method chaining
post()
Register a POST route.The URI pattern to match
Callback function or controller method
Returns a Route instance
put()
Register a PUT route.The URI pattern to match
Callback function or controller method
Returns a Route instance
patch()
Register a PATCH route.The URI pattern to match
Callback function or controller method
Returns a Route instance
delete()
Register a DELETE route.The URI pattern to match
Callback function or controller method
Returns a Route instance
Instance methods
addRoute()
Register a Route object manually.HTTP method (GET, POST, PUT, PATCH, DELETE)
Route instance to register
Returns the registered Route instance
dispatch()
Dispatch the content for the current route and method.Returns the handler response content
getRoute()
Get the current route being processed.Returns the current Route instance
match()
Confirm if a URI and HTTP method match any registered route.HTTP method to match
URI to match against registered routes
Returns Route instance if matched, false otherwise
getUriParts()
Parse a URI and return its parts and subdomain.URI to parse
Array containing ‘parts’ and ‘subdomain’ keys
parseRoute()
Deconstruct a route to extract URI parts and subdomain.Route instance to parse
Modifies the route object in place
getRoutes()
Get all registered routes, optionally filtered by method and subdomain.HTTP method to filter by
Subdomain to filter by
Array of registered routes
Static utility methods
group()
Group routes to apply middleware to multiple routes.Comma-separated string or array of middleware names
Callback function containing route definitions
Routes defined in callback will have middleware applied
runMiddlewares()
Execute an array of middleware classes.Array of middleware class names
Executes each middleware in sequence
loadRequestedRoutes()
Load routes based on the current environment and URI.Loads appropriate route files for web or CLI environment
validateRequestedRoutesByFile()
Load routes from a specific route file.Name of the route file to load (without .php extension)
Returns true if routes were loaded successfully