Router class
Framework\Routing\Router
Class Router.
Implements:
JsonSerializable
Defined in libraries/routing/src/Router.php
Properties #
- $defaultRouteActionMethod
- -
- $defaultRouteNotFound
- -
- $placeholders
- -
- $collections
- -
- $matchedCollection
- -
- $matchedRoute
- -
- $matchedOrigin
- -
- $matchedOriginArguments
- -
- $matchedPath
- -
- $matchedPathArguments
- -
- $autoOptions
- -
- $autoMethods
- -
- $response
- -
- $language
- -
- $debugCollector
- -
$defaultRouteActionMethod
$defaultRouteNotFound
$placeholders
$collections
$matchedCollection
$matchedRoute
$matchedOrigin
$matchedOriginArguments
$matchedPath
$matchedPathArguments
$autoOptions
$autoMethods
$response
$language
$debugCollector
Methods #
- __construct()
- Router constructor.
- __get()
- -
- addPlaceholder()
- Adds Router placeholders.
- fillPlaceholders()
- Fills argument values into a string with placeholders.
- getCollections()
- Gets all Route Collections.
- getDebugCollector()
- -
- getDefaultRouteActionMethod()
- Gets the default route action method.
- getLanguage()
- -
- getMatchedCollection()
- Gets the matched Route Collection.
- getMatchedOrigin()
- Gets the matched URL Origin.
- getMatchedOriginArguments()
- Gets the matched URL Origin arguments.
- getMatchedPath()
- Gets the matched URL Path.
- getMatchedPathArguments()
- Gets the matched URL Path arguments.
- getMatchedRoute()
- Gets the matched Route.
- getMatchedUrl()
- Gets the matched URL.
- getNamedRoute()
- Gets a named route.
- getPlaceholders()
- Gets all Router placeholders.
- getResponse()
- Gets the HTTP Response instance.
- getRouteNotFound()
- Gets the Route Not Found.
- getRoutes()
- Gets all routes, except the not found.
- hasNamedRoute()
- Tells if it has a named route.
- isAutoMethods()
- Tells if auto methods is enabled.
- isAutoOptions()
- Tells if auto options is enabled.
- jsonSerialize()
- -
- match()
- Match HTTP Method and URL against RouteCollections to process the request.
- replacePlaceholders()
- Replaces string placeholders with patterns or patterns with placeholders.
- serve()
- Serves a RouteCollection to a specific Origin.
- setAutoMethods()
- Enable/disable the feature of auto-detect and show HTTP allowed methods via the Allow header when a route with the requested method does not exist.
- setAutoOptions()
- Enable/disable the feature of auto-detect and show HTTP allowed methods via the Allow header when the Request has the OPTIONS method.
- setDebugCollector()
- -
- setDefaultRouteActionMethod()
- Set the class method name to be called when a Route action is set without a method.
- setDefaultRouteNotFound()
- Sets the Default Route Not Found action.
- setLanguage()
- -
- addCollection()
- -
- addServedCollection()
- -
- getAllowedMethods()
- -
- getAlternativeRoute()
- -
- getDefaultRouteNotFound()
- -
- getRouteWithAllowHeader()
- -
- makeMatchedRoute()
- -
- makePath()
- Creates a path without a trailing slash to be able to match both with and without a slash at the end.
- matchCollection()
- -
- matchRoute()
- -
- setMatchedCollection()
- -
- setMatchedOrigin()
- -
- setMatchedOriginArguments()
- -
- setMatchedPath()
- -
- setMatchedPathArguments()
- -
- setMatchedRoute()
- -
__construct()
Router constructor.
- \Framework\HTTP\Response $response
- ?\Framework\Language\Language $language
__get()
- string $property
addPlaceholder()
Adds Router placeholders.
- array|string $placeholder
- ?string $pattern
fillPlaceholders()
Fills argument values into a string with placeholders.
- string $string - The input string
- string $arguments
getCollections()
Gets all Route Collections.
getDebugCollector()
getDefaultRouteActionMethod()
Gets the default route action method.
Normally, it is "index".
getLanguage()
getMatchedCollection()
Gets the matched Route Collection.
Note: Will return null if no URL Origin was matched in a Route Collection
getMatchedOrigin()
Gets the matched URL Origin.
getMatchedOriginArguments()
Gets the matched URL Origin arguments.
getMatchedPath()
Gets the matched URL Path.
getMatchedPathArguments()
Gets the matched URL Path arguments.
getMatchedRoute()
Gets the matched Route.
getMatchedUrl()
Gets the matched URL.
Note: This method does not return the URL query. If it is needed, get
with {@see Request::getUrl()}.
getNamedRoute()
Gets a named route.
- string $name
getPlaceholders()
Gets all Router placeholders.
getResponse()
Gets the HTTP Response instance.
getRouteNotFound()
Gets the Route Not Found.
Must be called after {@see Router::match()} and will return the Route
Not Found from the matched collection or the Default Route Not Found
from the router.
getRoutes()
Gets all routes, except the not found.
hasNamedRoute()
Tells if it has a named route.
- string $name
isAutoMethods()
Tells if auto methods is enabled.
isAutoOptions()
Tells if auto options is enabled.
jsonSerialize()
match()
Match HTTP Method and URL against RouteCollections to process the request.
replacePlaceholders()
Replaces string placeholders with patterns or patterns with placeholders.
- string $string - The string with placeholders or patterns
- bool $flip - Set true to replace patterns with placeholders
serve()
Serves a RouteCollection to a specific Origin.
- ?string $origin - URL Origin. A string in the following format: `{scheme}://{hostname}[:{port}]`. Null to auto-detect.
- callable $callable - A function receiving an instance of RouteCollection as the first parameter
- ?string $collectionName - The RouteCollection name
setAutoMethods()
Enable/disable the feature of auto-detect and show HTTP allowed methods via the Allow header when a route with the requested method does not exist.
A response with code 405 "Method Not Allowed" will trigger.
- bool $enabled - true to enable, false to disable
setAutoOptions()
Enable/disable the feature of auto-detect and show HTTP allowed methods via the Allow header when the Request has the OPTIONS method.
- bool $enabled - true to enable, false to disable
setDebugCollector()
- \Framework\Routing\Debug\RoutingCollector $debugCollector
setDefaultRouteActionMethod()
Set the class method name to be called when a Route action is set without a method.
- string $action
setDefaultRouteNotFound()
Sets the Default Route Not Found action.
- Closure|string $action - the function to run when no Route path is found
setLanguage()
- ?\Framework\Language\Language $language
addCollection()
- \Framework\Routing\RouteCollection $collection
addServedCollection()
- ?string $origin
- callable $callable
- ?string $collectionName
getAllowedMethods()
- \Framework\Routing\RouteCollection $collection
getAlternativeRoute()
- string $method
- \Framework\Routing\RouteCollection $collection
getDefaultRouteNotFound()
getRouteWithAllowHeader()
- \Framework\Routing\RouteCollection $collection
- int $code
makeMatchedRoute()
makePath()
Creates a path without a trailing slash to be able to match both with and without a slash at the end.
- string $path
matchCollection()
- string $origin
matchRoute()
- string $method
- \Framework\Routing\RouteCollection $collection
- string $path
setMatchedCollection()
- \Framework\Routing\RouteCollection $matchedCollection
setMatchedOrigin()
- string $origin
setMatchedOriginArguments()
- array $arguments
setMatchedPath()
- string $path
setMatchedPathArguments()
- array $arguments
setMatchedRoute()
- \Framework\Routing\Route $route