public
|
#
auth( boolean $auth, callable $action )
Add an authentication condition to match the routes defined inside $action callback.
For example, you can write something like :
Add an authentication condition to match the routes defined inside $action callback.
For example, you can write something like :
App::router()->auth(App::session()->getUser()->isAllowed('admin.all'), function(){
App::router()->get('test-route', '/test', array('action' => 'TestController.testMethod'));
});
If the user tries to access to /test without the necessary privileges,
then a HTTP code 403 (Forbidden) will be returned
Parameters
- $auth
- The authentication. If true, then the routes inside are accessible, else they're not
- $action
- The function that defines the routes under this authentication
|
public
|
#
setProperties( array $data, callable $action )
Set properties for all the routes that are defined in the $action callback.
It can be used to set a prefix to a set of routes, a namespace for all routes actions, ...
Set properties for all the routes that are defined in the $action callback.
It can be used to set a prefix to a set of routes, a namespace for all routes actions, ...
Parameters
- $data
- The properties to set
- $action
- The function that defines the routes with these properties
|
public
|
#
prefix( string $prefix, callable $action )
Set a prefix to routes URIs that are defined in $action callback
Set a prefix to routes URIs that are defined in $action callback
Parameters
- $prefix
- The prefix to set to the URIs
- $action
- The function that defined the routes with this prefix
|
public
|
#
get( string $name, string $path, array $param )
Add a route acessible by GET HTTP requests
Add a route acessible by GET HTTP requests
Parameters
- $name
- The route name. This name must be unique for each route
- $path
- The route path, defined like : /path/{param1}/to/{param2}
- $param
The route parameters. This array can have the following data :
- 'action' string (required) : The controller method to call when the route is matched,
formatted like this : 'ControllerClass.method'
- 'where' array (optionnal) : An array defining each parameter pattern,
where keys are the names of the route parameters,
and values are the regular expression to match (without delimiters).
- 'default' array (optionnal) : An array defining the default values of parameters.
This is useful to generate a URI from a route name (method getUri),
without giving all parameters values
|
public
|
#
post( string $name, string $path, array $param )
Add a route acessible by POST HTTP requests
Add a route acessible by POST HTTP requests
Parameters
- $name
- The route name. This name must be unique for each route
- $path
- The route path, defined like : /path/{param1}/to/{param2}
- $param
The route parameters. This array can have the following data :
- 'action' string (required) : The controller method to call when the route is matched,
formatted like this : 'ControllerClass.method'
- 'where' array (optionnal) : An array defining each parameter pattern,
where keys are the names of the route parameters,
and values are the regular expression to match (without delimiters).
- 'default' array (optionnal) : An array defining the default values of parameters.
This is useful to generate a URI from a route name (method getUri),
without giving all parameters values
|
public
|
#
put( string $name, string $path, array $param )
Add a route acessible by PUT HTTP requests
Add a route acessible by PUT HTTP requests
Parameters
- $name
- The route name. This name must be unique for each route
- $path
- The route path, defined like : /path/{param1}/to/{param2}
- $param
The route parameters. This array can have the following data :
- 'action' string (required) : The controller method to call when the route is matched,
formatted like this : 'ControllerClass.method'
- 'where' array (optionnal) : An array defining each parameter pattern,
where keys are the names of the route parameters,
and values are the regular expression to match (without delimiters).
- 'default' array (optionnal) : An array defining the default values of parameters.
This is useful to generate a URI from a route name (method getUri),
without giving all parameters values
|
public
|
#
delete( string $name, string $path, array $param )
Add a route acessible by DELETE HTTP requests
Add a route acessible by DELETE HTTP requests
Parameters
- $name
- The route name. This name must be unique for each route
- $path
- The route path, defined like : /path/{param1}/to/{param2}
- $param
The route parameters. This array can have the following data :
- 'action' string (required) : The controller method to call when the route is matched,
formatted like this : 'ControllerClass.method'
- 'where' array (optionnal) : An array defining each parameter pattern,
where keys are the names of the route parameters,
and values are the regular expression to match (without delimiters).
- 'default' array (optionnal) : An array defining the default values of parameters.
This is useful to generate a URI from a route name (method getUri),
without giving all parameters values
|
public
|
#
patch( string $name, string $path, array $param )
Add a route acessible by PATCH HTTP requests
Add a route acessible by PATCH HTTP requests
Parameters
- $name
- The route name. This name must be unique for each route
- $path
- The route path, defined like : /path/{param1}/to/{param2}
- $param
The route parameters. This array can have the following data :
- 'action' string (required) : The controller method to call when the route is matched,
formatted like this : 'ControllerClass.method'
- 'where' array (optionnal) : An array defining each parameter pattern,
where keys are the names of the route parameters,
and values are the regular expression to match (without delimiters).
- 'default' array (optionnal) : An array defining the default values of parameters.
This is useful to generate a URI from a route name (method getUri),
without giving all parameters values
|
public
|
#
any( string $name, string $path, array $param )
Add a route acessible by GET, POST OR DELETE HTTP requests
Add a route acessible by GET, POST OR DELETE HTTP requests
Parameters
- $name
- The route name. This name must be unique for each route
- $path
- The route path, defined like : /path/{param1}/to/{param2}
- $param
The route parameters. This array can have the following data :
- 'action' string (required) : The controller method to call when the route is matched,
formatted like this : 'ControllerClass.method'
- 'where' array (optionnal) : An array defining each parameter pattern,
where keys are the names of the route parameters,
and values are the regular expression to match (without delimiters).
- 'default' array (optionnal) : An array defining the default values of parameters.
This is useful to generate a URI from a route name (method getUri),
without giving all parameters values
|
public
|
#
route( )
Compute the routing, and execute the controller method associated to the URI
Compute the routing, and execute the controller method associated to the URI
|
public
array
|
#
getRoutes( )
Get all defined routes
Returns
array The defined routes
|
public
array
|
#
getActiveRoutes( )
Get the routes accessible for the current HTTP request method
Get the routes accessible for the current HTTP request method
Returns
array The list of the accessible routes
|
public
Hawk\Route
|
#
getCurrentRoute( )
Get the route corresponding to the current HTTP request
Get the route corresponding to the current HTTP request
Returns
|
public
string
|
#
getCurrentAction( )
Get the action parameter of the current route
Get the action parameter of the current route
Returns
string The action of the current route
|
public
Hawk\Controller
|
#
getCurrentController( )
Get the last instanciated controller
Get the last instanciated controller
Returns
|
public
string
|
#
getUri( string $name, array $args = array() )
Generate an URI from a given controller method (or route name) and its arguments.
Generate an URI from a given controller method (or route name) and its arguments.
Parameters
- $name
- The route name of the controller method, formatted like this : 'ControllerClass.method'
- $args
- The route arguments, where keys define the parameters names and values, the values to affect.
Returns
string The generated URI, or the current URI (if $method is not set)
|
public
string
|
#
getUrl( string $name = '', array $args = array() )
Generate a full URL from a given controller method (or route name) and its arguments.
Generate a full URL from a given controller method (or route name) and its arguments.
Parameters
- $name
- The route name of the controller method, formatted like this : 'ControllerClass.method'
- $args
- The route arguments, where keys define the parameters names and values, the values to affect.
Returns
string The generated URI, or the current URI (if $method is not set)
|
public
Hawk\Route
|
#
getRouteByAction( string $name )
Get a route by action
Parameters
- $name
- The route name of the controller method, formatted like this : 'ControllerClass.method'
Returns
|
public
Hawk\Route
|
#
getRouteByUri( string $path )
Find a route from an URI
Parameters
- $path
- The path to search the associated route
Returns
|
public
Hawk\Route
|
|