Routable
in package
The routable class is the base class for both routers and router servers, which can both accept routes and store them. In order to do so, there is a predefined set of functions that are meant to be kept the way they are and a single abstract one that adds the route to the element the way this one decides.
Tags
Table of Contents
- $prefix : string
- This is the url prefix the router is connected to. Every time the addRoute method is invoked, this router will prefix the route to scope it to the router.
- $routes : mixed
- __construct() : mixed
- addRoute() : Route
- This method adds a route to the current object. You can use this to customize a certain set of methods for the route to rewrite.
- delete() : Route
- This method adds a route that will only rewrite the request if it's method is DELETE. Otherwise the request will be ignored.
- get() : Route
- This method adds a route that will only rewrite the request if it's method is GET. Otherwise the request will be ignored.
- getPrefix() : mixed
- getRoutes() : mixed
- options() : Route
- Adds a route to reply to OPTIONS requests, these are most commonly used by user-agents when they attempt to perform pre-flight CORS tests.
- post() : Route
- This method adds a route that will only rewrite the request if it's method is POST. Otherwise the request will be ignored.
- put() : Route
- This method adds a route that will only rewrite the request if it's method is PUT. Otherwise the request will be ignored.
- request() : Route
- This method adds a route for any request that is sent either via GET or POST this are the most standard and common behaviors and the ones recommended over PUT or DELETE due to it's behavior.
Properties
$prefix
This is the url prefix the router is connected to. Every time the addRoute method is invoked, this router will prefix the route to scope it to the router.
private
string
$prefix
Please note that forcing a router to accept a route that is not inside it's scope is likely to cause undefined behavior. Mostly because the router will reject every request that doesn't match it's namespace, but may generate urls that are outside it's scope.
$routes
private
mixed
$routes
Methods
__construct()
public
__construct(string $prefix) : mixed
Parameters
- $prefix : string
Return values
mixed —addRoute()
This method adds a route to the current object. You can use this to customize a certain set of methods for the route to rewrite.
public
addRoute(string $pattern, Closure|array<string|int, string> $target[, int $method = 0x3 ][, int $protocol = 0x3 ]) : Route
Parameters
- $pattern : string
-
A route valid pattern @link http://www.spitfirephp.com/wiki/index.php/Router/Patterns
- $target : Closure|array<string|int, string>
-
Where the content will be redirected to @link http://www.spitfirephp.com/wiki/index.php/Router/Target
- $method : int = 0x3
-
The current method, default: Route::METHOD_GET | Route::METHOD_POST
- $protocol : int = 0x3
-
Whether the request s sent HTTP or HTTPS
Tags
Return values
Route —The route that is generated by this
delete()
This method adds a route that will only rewrite the request if it's method is DELETE. Otherwise the request will be ignored.
public
delete(string $pattern, Closure|array<string|int, string> $target) : Route
Parameters
- $pattern : string
-
A route valid pattern @link http://www.spitfirephp.com/wiki/index.php/Router/Patterns
- $target : Closure|array<string|int, string>
-
Where the content will be redirected to @link http://www.spitfirephp.com/wiki/index.php/Router/Target
Return values
Route —The route that is generated by this
get()
This method adds a route that will only rewrite the request if it's method is GET. Otherwise the request will be ignored.
public
get(string $pattern, Closure|array<string|int, string> $target) : Route
Parameters
- $pattern : string
-
A route valid pattern @link http://www.spitfirephp.com/wiki/index.php/Router/Patterns
- $target : Closure|array<string|int, string>
-
Where the content will be redirected to @link http://www.spitfirephp.com/wiki/index.php/Router/Target
Return values
Route —The route that is generated by this
getPrefix()
public
getPrefix() : mixed
Return values
mixed —getRoutes()
public
getRoutes() : mixed
Return values
mixed —options()
Adds a route to reply to OPTIONS requests, these are most commonly used by user-agents when they attempt to perform pre-flight CORS tests.
public
options(string $pattern, Closure|array<string|int, string> $target) : Route
Options requests should therefore not be treated the same way as GET, POST or HEAD requests, since they do not assume that the user agent is enforcing CORS policies when sending them.
Parameters
- $pattern : string
-
A route valid pattern @link http://www.spitfirephp.com/wiki/index.php/Router/Patterns
- $target : Closure|array<string|int, string>
-
Where the content will be redirected to @link http://www.spitfirephp.com/wiki/index.php/Router/Target
Return values
Route —The route that is generated by this
post()
This method adds a route that will only rewrite the request if it's method is POST. Otherwise the request will be ignored.
public
post(string $pattern, Closure|array<string|int, string> $target) : Route
Parameters
- $pattern : string
-
A route valid pattern @link http://www.spitfirephp.com/wiki/index.php/Router/Patterns
- $target : Closure|array<string|int, string>
-
Where the content will be redirected to @link http://www.spitfirephp.com/wiki/index.php/Router/Target
Return values
Route —The route that is generated by this
put()
This method adds a route that will only rewrite the request if it's method is PUT. Otherwise the request will be ignored.
public
put(string $pattern, Closure|array<string|int, string> $target) : Route
Parameters
- $pattern : string
-
A route valid pattern @link http://www.spitfirephp.com/wiki/index.php/Router/Patterns
- $target : Closure|array<string|int, string>
-
Where the content will be redirected to @link http://www.spitfirephp.com/wiki/index.php/Router/Target
Return values
Route —The route that is generated by this
request()
This method adds a route for any request that is sent either via GET or POST this are the most standard and common behaviors and the ones recommended over PUT or DELETE due to it's behavior.
public
request(string $pattern, Closure|array<string|int, string> $target) : Route
Parameters
- $pattern : string
-
A route valid pattern @link http://www.spitfirephp.com/wiki/index.php/Router/Patterns
- $target : Closure|array<string|int, string>
-
Where the content will be redirected to @link http://www.spitfirephp.com/wiki/index.php/Router/Target
Return values
Route —The route that is generated by this