Skip to content
docsv0.1.0

UrlGeneratorInterface

Reverse routing: build a URL for a named route from its parameters. Kept as its own interface (not bolted onto {@see RouterInterface}) to hold one responsibility per type — matching is request→route, generation is name→URI.

UrlGeneratorInterface::generate()

abstract public function generate(string $name, array $parameters = [], Milpa\Http\Routing\UrlReferenceType $referenceType = Milpa\Http\Routing\UrlReferenceType::ABSOLUTE_PATH): string

Build the URL for a named route.

Parameters

Parameters of generate()
NameTypeDescription
$namestring
$parametersarray<string, (string | int)>path-param values (surplus values become query string)
$referenceTypeUrlReferenceTypehow the reference is rendered

Throws

RouteNotFoundException when no route is registered under $name

MissingRouteParametersException when a required path parameter is not supplied