|
| $routes = null |
|
| $hooks = null |
|
| $logger = null |
|
| $addQueryParams = [] |
|
| $segBasedMatch |
|
Class constructor
Set retrieved Routes Container, Hooks Container, and the Logger to the internal properties.
- Parameters
-
\SlaxWeb\Router\Container | $routes | Routes container |
\SlaxWeb\Hooks\Container | $hooks | Hooks container |
\Psr\Log\LoggerInterface | $logger | Logger implementing PSR3 |
SlaxWeb\Router\Dispatcher::addParams |
( |
array |
$matches | ) |
|
|
protected |
Add additional parameters
Prepares the found matches from the URI and injects them into the 'addQueryParams' property.
- Parameters
-
array | $matches | Regex matches |
- Returns
- void
SlaxWeb\Router\Dispatcher::checkContainer |
( |
int |
$method, |
|
|
string |
$uri |
|
) |
| |
|
protected |
Check Routes Container
Iterates the routes container and tries to match the request to a Route in the container. Returns the matching Route object if found, or null otherwise.
- Parameters
-
- Returns
- |null
SlaxWeb\Router\Dispatcher::dispatch |
( |
Request |
$request, |
|
|
Response |
$response |
|
) |
| |
Dispatch Request
Dispatch the Request to the propper Route. Tries to find a matching Route for the retrieved Request object, and calls that Routes action callable along with Response, and any other input parameters as arguments for the action. If Segment based URI matching is enabled, the dispatcher will try to route the incoming request to a matched controller and method.
- Parameters
-
\SlaxWeb\Router\Request | $request | Request object |
\SlaxWeb\Router\Reponse | $response | Response object |
mixed | $unknown | Any further parameter is sent to Route action |
- Returns
- void
SlaxWeb\Router\Dispatcher::dispatchController |
( |
string |
$uri | ) |
|
|
protected |
Dispatch request to controller
Try and match the Request URI with an existing controller and its method. If such match is found, dispatch the request to said controller and method, and return bool(true) upon successful execution. If a match is not found bool(false) is returned.
- Parameters
-
- Returns
- bool
SlaxWeb\Router\Dispatcher::dispatchRoute |
( |
Route |
$route, |
|
|
array |
$params |
|
) |
| |
|
protected |
Dispatch route
Dispatch the route by executing its action.
- Parameters
-
\SlaxWeb\Router\Route | $route | Route object |
array | $params | Array of parameters for the Route action |
- Returns
- void
SlaxWeb\Router\Dispatcher::enableSegMatch |
( |
string |
$namespace, |
|
|
array |
$params = [] , |
|
|
string |
$prepend = "" , |
|
|
string |
$defaultMethod = "index" |
|
) |
| |
Enable segment Based URI Matching
Enables the segment based URI matching, sets the Controller namespace, and the default method to call if the second segment is not found in the URI. Default method has the default value of string("index").
- Parameters
-
string | $namespace | Controller namespace |
array | $params | Controller constructor parameters |
string | $prepend | URI prepend for segment based URI matching |
string | $defaultMethod | Default controller method for single segment URIs |
- Returns
SlaxWeb\Router\Dispatcher::findRoute |
( |
int |
$method, |
|
|
string |
$uri |
|
) |
| |
|
protected |
Find matching Route
Try and obtain the route that bests fits the request and return it. If no such route is found, and no 404 route exists, nor is one returned from a 'routeNotFound' hook execution, null is returned.
- Parameters
-
- Returns
- |null
SlaxWeb\Router\Dispatcher::handleNoMatch |
( |
| ) |
|
|
protected |
Handle No Matching Route Found
Execute the Route Not Found Hook definition with the help of the Hook component and return a valid Route object if it is found in the Hook execution return data. If no valid route is returned by the hook, try to obtain the 404 route from the Route Container object and return it.
- Returns
- |null
SlaxWeb\Router\Dispatcher::posix2Pcre |
( |
string |
$regex, |
|
|
array |
$names = ["params" , |
|
|
"named"] |
|
|
) |
| |
|
protected |
POSIX named class to PCRE capturing group
Replace the special POSIX named classes with normal named capturing groups.
- Parameters
-
string | $regex | Raw regexp string |
array | $names | POSIX class names array, default: ["params", "named"] |
- Returns
- string Replaced regexp string
SlaxWeb\Router\Dispatcher::$segBasedMatch |
|
protected |
SlaxWeb\Router\Dispatcher::uriPrepend |
Initial value:=> "",
"controller" => [
"namespace" => "",
"defaultMethod" => "",
"params" => []
]
]
The documentation for this class was generated from the following file:
- /opt/slax0rDev/slaxweb/router/src/Dispatcher.php