Documentation

Route extends RewriteRule
in package

A route is a class that rewrites a URL path (route) that matches a route or pattern (old_route) into a new route that the system can use (new_route) to handle the current request.

A Route will only accept Closures, Responses or Paths (including arrays that can be interpreted as Paths by the translation class) as the target.

Tags
author

César de la Cal cesar@magic3w.com

Table of Contents

METHOD_DELETE  = 0x8
METHOD_GET  = 0x1
METHOD_HEAD  = 0x10
METHOD_OPTIONS  = 0x20
METHOD_POST  = 0x2
METHOD_PUT  = 0x4
PROTO_ANY  = 0x3
PROTO_HTTP  = 0x1
PROTO_HTTPS  = 0x2
$method  : mixed
$name  : string
The name of a route allows the application to quickly look up the route from a list of available routes when building URLs to other parts of the application.
$newRoute  : RequestHandlerInterface
$pattern  : URIPattern
__construct()  : mixed
A route is a pattern Spitfire uses to redirect an URL to something else.
getName()  : string
getSource()  : URIPattern
getTarget()  : RequestHandlerInterface
rewrite()  : void
setName()  : Route
test()  : mixed
testMethod()  : bool
Checks whether a certain method applies to this route. The route can accept as many protocols as it wants. The protocols are converted to hex integers and are AND'd to check whether the selected protocol is included in the list of admitted ones.
testProto()  : bool
Tests whether the requested protocol (HTTPS or not) is accepted by this route. We use once again binary masks to test the protocol. This means that we can either use HTTP (01), HTTPS (10) or both (11) which will translate into an integer 1, 2 and 3.

Constants

METHOD_DELETE

public mixed METHOD_DELETE = 0x8

METHOD_GET

public mixed METHOD_GET = 0x1

METHOD_HEAD

public mixed METHOD_HEAD = 0x10

METHOD_OPTIONS

public mixed METHOD_OPTIONS = 0x20

METHOD_POST

public mixed METHOD_POST = 0x2

METHOD_PUT

public mixed METHOD_PUT = 0x4

PROTO_ANY

public mixed PROTO_ANY = 0x3

PROTO_HTTP

public mixed PROTO_HTTP = 0x1

PROTO_HTTPS

public mixed PROTO_HTTPS = 0x2

Properties

$name

The name of a route allows the application to quickly look up the route from a list of available routes when building URLs to other parts of the application.

private string $name = null

By default, Spitfire will set the controller::action combination as the name of the route, making it quick to find anonymous routes.

Methods

__construct()

A route is a pattern Spitfire uses to redirect an URL to something else.

public __construct(URIPattern $pattern, RequestHandlerInterface $new_route, string $method[, int $proto = Route::PROTO_ANY ]) : mixed

It can 'redirect' (without it being a 302) a request to a new URL, it can directly send back a response or assign a custom controller, action and object to the request.

Parameters
$pattern : URIPattern
$new_route : RequestHandlerInterface
$method : string
$proto : int = Route::PROTO_ANY
Return values
mixed

getName()

public getName() : string
Return values
string

getTarget()

public getTarget() : RequestHandlerInterface
Return values
RequestHandlerInterface

rewrite()

public rewrite(ServerRequestInterface $request) : void
Parameters
$request : ServerRequestInterface
Return values
void

setName()

public setName(string $name) : Route
Parameters
$name : string
Return values
Route

test()

public test(mixed $URI, mixed $method) : mixed
Parameters
$URI : mixed
$method : mixed
Return values
mixed

testMethod()

Checks whether a certain method applies to this route. The route can accept as many protocols as it wants. The protocols are converted to hex integers and are AND'd to check whether the selected protocol is included in the list of admitted ones.

public testMethod(string|int $method) : bool
Parameters
$method : string|int
Return values
bool

testProto()

Tests whether the requested protocol (HTTPS or not) is accepted by this route. We use once again binary masks to test the protocol. This means that we can either use HTTP (01), HTTPS (10) or both (11) which will translate into an integer 1, 2 and 3.

public testProto(bool $protocol) : bool

This way the user can quickly decide whether he wants to use any or both of them to match a route.

Parameters
$protocol : bool
Tags
deprecated

We're letting the web server care about https

Return values
bool

Search results