\Gishiki\Core\RouterRouter

This component represents the application as a set of HTTP rules.

Summary

Methods
Properties
Constants
add()
register()
run()
No public properties found
No constants found
search()
checkNotAllowed()
loadErrorHandlers()
No protected properties found
N/A
No private methods found
$routes
N/A

Properties

$routes

$routes : array

Type

array — a list of registered Gishiki\Core\Route ordered my method to allow faster search

Methods

register()

register(\Gishiki\Core\Router\RouteInterface  $route) 

Register a route within this router.

Parameters

\Gishiki\Core\Router\RouteInterface $route

the route to be registered

run()

run(\Psr\Http\Message\RequestInterface  $requestToFulfill, \Psr\Http\Message\ResponseInterface  $response, array  $controllerArgs = array(), \Gishiki\Core\Application|null  $app = null) 

Run the router and serve the current request.

This function is CALLED INTERNALLY and, therefore it MUST NOT be called by the user!

Parameters

\Psr\Http\Message\RequestInterface $requestToFulfill

the request to be served/fulfilled

\Psr\Http\Message\ResponseInterface $response

the response to be filled

array $controllerArgs

an associative array with more parameters to be passed to the called controller

\Gishiki\Core\Application|null $app

the current application instance

search()

search(string  $method, string  $url, array  $params, array  $get) : null|\Gishiki\Core\Router\Route

Check if the given url and method match a route (even a non-200 OK route is allowed).

Parameters

string $method

the HTTP used verb

string $url

the url decoded string of the called url

array $params

will contains matched url slices

array $get

will contains matched url get options

Returns

null|\Gishiki\Core\Router\Route

the matched route or null

checkNotAllowed()

checkNotAllowed(string  $requestURL, string  $requestMethod) : boolean

Check if the given URL matches a rule in a HTTP method different from the one used to perform the request.

Parameters

string $requestURL

the HTTP used address

string $requestMethod

the HTTP method used to query the resource

Returns

boolean —

true if the given url is matched in some other methods

loadErrorHandlers()

loadErrorHandlers(string  $method) : array

Load error-handling routes to be used when a bad request is sent to the server.

Parameters

string $method

the HTTP verb of the request

Returns

array —

the list of error-handling routes