A routes file must return an associative array of paths pointing to indicator entries. The only exception is the root entry, which has no path and begins directly with a method indicator.
The following pseudo-routes example demonstrates all possible combinations:
// improve readability
// use indicators as variables for highlighting
$get = "get";
$post = "post";
$regex = "regex";
return [
// root entry
// method indicator without path
$get => "entry",
// nested entry
// static path pointing to method indicator
"/slug" => [$post => "entry"],
// grouped entries
// multi-segment static path
"/group/slug" => [
"/slug" => [$post => "entry"],
// default parameter path without regex
"/:parameter" => [
$post => "entry",
$get => "entry",
// reset entry
"/slug" => [$get => null]
]
],
// individual parameter
"/individual/:parameter" => [
$regex => "[0-9]",
$get => "entry"
],
// alias parameter
"/:parameter" => [
// use regex of default parameter
$regex => ":parameter",
$get => "entry"
],
// reset path
"/whatever" => null
];
Path Segments
Predefine constructor values for specific parameters of a class. Whenever the container creates an instance, these defaults are automatically applied, reducing boilerplate and ensuring consistent object initialization.
On-Demand Arguments
- Must start with
/
- Segments are separated by
/
- A segment can be static or a parameter (prefixed with
:
) - Parameter names serve as associative keys
Indicator Types
regex
defines a custom regular expression or references an aliasget
,post
,put
,delete
,patch
,options
,head
represent HTTP method selectors
Entry Types
null
resets entries from previously loaded files- A regex string is used as the argument of
preg_match("/$regex/", $slug)
- Any other value is selectable by an HTTP method