\Gishiki\Core\RouterRoute

This class represents a route that will resolve in a Controller call.

Summary

Methods
Properties
Constants
getURI()
getStatus()
getMethods()
matches()
matchURI()
__construct()
__invoke()
No public properties found
No constants found
paramCheck()
matchCheck()
$route
N/A
No private methods found
No private properties found
N/A

Properties

$route

$route : array

uri => string (begins with / example: "/do_something") status => integer (the HTTP return status code, used for error handling) verbs => string[] (the array of string of allowed/matchable HTTP methods)

Type

array — the route definition

Methods

getURI()

getURI() 

getStatus()

getStatus() 

getMethods()

getMethods() 

matches()

matches(string  $method, string  $url, array  $matchedExpr, array  $matchedGet) : boolean

Check if the given URL matches the route URI.

Also fill GET and expressions parameters.

Parameters

string $method

the HTTP method used on the Request

string $url

the URL invoked

array $matchedExpr

will be filled with an associative array of paramName => urlValue

array $matchedGet

will be filled with an associative array of paramName => urlValue (reserved for get parameters)

Returns

boolean —

true if the given method and url matches this route

matchURI()

matchURI(string  $uri, string  $url, array  $matchedExpr, array  $matchedGet) : boolean

Check if the given URL matches the given URI.

$matchedExpr is given as an associative array: name => value

Parameters

string $uri

the URI to be matched against the given URL

string $url

the URL to be matched

array $matchedExpr

the variable to be filled with matched parameters

array $matchedGet

the variable to be filled with GET options

Returns

boolean —

true if the URL matches the URI, false otherwise

__construct()

__construct(array  $options) 

Build a new route to be registered within a Router instance.

An usage example is: <?php $route = new Route([ "verbs" => [ RouteInterface::GET ], "uri" => "/", "status" => RouteInterface::OK, "controller" => MyController::class, "action" => "index", ]);

Parameters

array $options

The URI for the current route and more options

Throws

\Gishiki\Core\Router\RouterException

The route is malformed

__invoke()

__invoke(\Psr\Http\Message\RequestInterface  $request, \Psr\Http\Message\ResponseInterface  $response, \Gishiki\Algorithms\Collections\GenericCollection  $arguments, array  $controllerArgs = array(), \Gishiki\Core\Application|null  $app = null) 

Execute the route callback by instantiating the given controller class and calling the specified action.

This function is called AUTOMATICALLY by the framework when the route can be used to fulfill the given request.

Parameters

\Psr\Http\Message\RequestInterface $request

a copy of the request made to the application

\Psr\Http\Message\ResponseInterface $response

the action must filled, and what will be returned to the client

\Gishiki\Algorithms\Collections\GenericCollection $arguments

a list of reversed URI and GET parameters

array $controllerArgs

an array containing data created from the application initialization

\Gishiki\Core\Application|null $app

the current application instance

paramCheck()

paramCheck(  $urlSplit,   $type) : boolean

Check if a piece of URL matches a parameter of the given type.

List of types:

  • 0 unsigned integer
  • 1 signed integer
  • 2 float
  • 3 string
  • 4 email

Parameters

$urlSplit

string the piece of URL to be checked

$type

int the type of accepted parameter

Throws

\Gishiki\Core\Router\RouterException

the given type is invalid

Returns

boolean —

true on success, false otherwise

matchCheck()

matchCheck(string  $uriSplit, string  $urlSplit, mixed  $params) : boolean

Check weather a piece of an URL matches the corresponding piece of URI

Parameters

string $uriSplit

the slice of URI to be checked

string $urlSplit

the slice of URL to be checked

mixed $params

used to register the correspondence (if any)

Returns

boolean —

true if the URL slice matches the URI slice, false otherwise