Route

Maps URI patterns to actions and views.

Routes are declared through the interfaces provided by the \HotMelt\Route class. HotMelt will automatically load Site/routes.php, so you should use that file to declare routes.

property-read

The action to execute for this route.

property-read

The view to render the result of this route's action in. Either an instance of \HotMelt\View or null, if no view as been declared for this route.

see
see

Methods

Adds a route to the routing table.

add(string $expr, mixed $action, mixed $view = null, mixed $methods = false, mixed $options = false) : void
static
see \HotMelt\Action \HotMelt\View

Arguments

$expr

string

A regular expression to match against the request URI.

$action

mixed

The action to execute for the route. Can be either a subclass of \HotMelt\Action or a callable.

$view

mixed

The view that the data returned from the route's action should be rendered in. Can be either a subclass of \HotMelt\View or the name of a template to be rendered by an instance of \HotMelt\TemplateView. You may pass null if you know that the action will never return (because it will always throw an exception).

$methods

mixed

A string or an array of strings identifying valid HTTP methods for this route. You may pass false to allow requests with any HTTP method.

$options

mixed

The options for this route. Upon adding a route, these options are merged with any default options set with \HotMelt\Route::pushDefaultOptions().

Pushes (adds) a new set of options onto the default options stack.

pushDefaultOptions(array $options) : void
static

Any options pushed through this method will override options previously pushed.

Arguments

$options

array

An array of options to push onto the default options stack.

Pops (removes) a set of options from the top of the default options stack.

popDefaultOptions() : void
static

Returns the effective set of options by merging all sets of options on the default options stack.

effectiveOptions(array|bool $options = false) : array
static

Arguments

$options

array|bool

An array of options to merge with the options from the default options stack. Passing a set of options in this argument is conceptually similar to pushing that set onto the default options stack, then calling this method, and finally popping that set back off the stack, except the default options stack is not actually changed.

Response

array

A set of options.

Initialize a route.

__construct(string $expr, mixed $action, mixed $view, mixed $methods = false, mixed $options = false) 
see \HotMelt\Action \HotMelt\View

Arguments

$expr

string

A regular expression to match against the request URI.

$action

mixed

The action to execute for this route. Can be either a subclass of \HotMelt\Action or a callable.

$view

mixed

The view that the data returned from this route's action should be rendered in. Can be either a subclass of \HotMelt\View or the name of a template to be rendered by an instance of \HotMelt\TemplateView. You may pass null if you know that the action will never return (because it will always throw an exception).

$methods

mixed

A string or an array of strings identifying valid HTTP methods for this route. You may pass false to allow requests with any HTTP method.

$options

mixed

The options for this route. Upon adding a route, these options are merged with any default options set with \HotMelt\Route::pushDefaultOptions().

Returns the value for an option.

option(string $name) : mixed

Arguments

$name

string

An option name.

Response

mixed

Returns a snapshot of the routing table.

routes() : array
static

Response

array

Finds the best match for a request.

find(mixed $requestOrURI) : \HotMelt\Route
static

Arguments

$requestOrURI

mixed

Either a \HotMelt\Request object or a URI (represented as a string).

Response

\HotMelt\Route

The route that is the best match from the routing table or false if there was no match.

Returns `true` if a given HTTP method is valid for this route.

acceptsMethod(string $method) : \HotMelt\`true`,

Arguments

$method

string

The HTTP method to test.

Response

\HotMelt\`true`,

if the given method is valid for this route, or false, if it is not.

Gets or sets the error route.

error(mixed $action = null, mixed $view = null, mixed $options = null) : \HotMelt\Route
static

Call this method without any arguments to retrieve the error route previously set through this method. Call this method with at least the $action and $view arguments to set the error route.

Arguments

$action

mixed

The action to execute for the error route. Can be either a subclass of \HotMelt\Action or a callable.

$view

mixed

The view that the data returned from the error route's action should be rendered in. Can be either a subclass of \HotMelt\View or the name of a template to be rendered by an instance of \HotMelt\TemplateView. You may pass null if you know that the action will never return (because it will always throw an exception). You may pass false to allow requests with any HTTP method.

$options

mixed

The options for the error route. Upon adding a route, these options are merged with any default options set with \HotMelt\Route::pushDefaultOptions().

Response

\HotMelt\Route

The error route.

Returns the content types for which this route provides views.

contentTypes() : array

Response

array

Returns the best content type from a range of acceptable types.

negotiateContentType(mixed $acceptableTypes) : string

Arguments

$acceptableTypes

mixed

The types from which to select a match. If you pass false, the first content type declared for this route is returned.

Response

string

The best content type for this route.

Returns the best view for a request.

negotiateView(\HotMelt\Request $request) : \HotMelt\View
throws

if no matching content type is declared for this route.

Arguments

$request

\HotMelt\Request

The request for which to find the best view.

Response

\HotMelt\View

The best view for $request.

Properties

A regular expression to match against the request URI.

expr : string
var

A regular expression to match against the request URI.

Type(s)

string

action

action : \HotMelt\Action

The action to execute for this route.

Type(s)

\HotMelt\Action

view

view : mixed

The view to render the result of this route's action in. Either an instance of \HotMelt\View or null, if no view as been declared for this route.

Type(s)

mixed