Looking at the 'Router.php' from giwt, there are a bunch of public functions to take note of.
__construct(Kernel $kernel = null)
In case a Kernel instance is passed to the constructor the routes saved under $kernel['config']['routes']
will initialize the protected $routes array of the Router-class which represents a list of all known routes (see: 'route config' below).
public function addRoutes($routes)
This function takes an array of routes and adds them to the known routes. In case the array contains an already known route an 'Exception` will be thrown.
public function getRoute($name)
Given the name of a route, this function will return a new Route
-instance. In case the name doesn't match to any known route an 'Exception` will be thrown.
public function match(Request $request)
This function takes a Request
as input and returns all the data belonging to the first route which matches the request path.
The data for a route is an array with the following entries:
_controller
entry for the route.public function build(Request $request, $name, array $variables = array(), $absolute = false, array $query = array())
This method builds and returns an url for the given parameters.
$request
: The request.$name
: Name of the route.$variables
: Array containing path variables. For a pattern like '/{a}/{b}', this would be an array like [ 'a' => 'value of a', 'b' => 'value of b'].$absolute
: Boolean indicating whether a relative or abolute url should be created.$query
: Array containing query parameters. A request like /Sebi?A?B would look like ['A' => 'value of A', 'B' => 'value of B'].Here's a small roundup of what defines a route in giwt..
public function __construct($name, $pattern, array $defaults = array(), array $requirements = array())
The constuctor of Graphit\Core\Route
shows there are two required arguments and two optional.
$name
: Is a string representing the name of the route. (required)$pattern
: Is a string containing the pattern for the route. (required)$defaults
: the _default
information for this route. (optional)$requirements
: the _requirements
information for this route. (optional)
So the contructor takes all the information of a route that can be provided through the routes.json-file.