Hawk - PHP documentation
  • Namespace
  • Class
  • Tree

Namespaces

  • Hawk
    • View
      • Plugins

Classes

  • App
  • ButtonInput
  • Cache
  • CheckboxInput
  • ColorInput
  • Conf
  • Controller
  • Crypto
  • DatabaseSessionHandler
  • DatetimeInput
  • DB
  • DBExample
  • DeleteInput
  • Dialogbox
  • EmailInput
  • ErrorHandler
  • Event
  • FileInput
  • FileSystem
  • FloatInput
  • Form
  • FormFieldset
  • FormInput
  • GenericModel
  • GifImage
  • HawkApi
  • HawkUpdater
  • HiddenInput
  • HtmlInput
  • HTTPRequest
  • Icon
  • Image
  • IntegerInput
  • ItemList
  • ItemListField
  • JpegImage
  • Lang
  • Language
  • LeftSidebarTab
  • Less
  • Logger
  • Mail
  • MenuItem
  • Model
  • NoSidebarTab
  • NumberInput
  • ObjectInput
  • Option
  • Panel
  • PasswordInput
  • Permission
  • Plugin
  • PluginInstaller
  • PngImage
  • ProfileQuestion
  • ProfileQuestionValue
  • RadioInput
  • Request
  • Response
  • RightSidebarTab
  • Role
  • RolePermission
  • Route
  • Router
  • SelectInput
  • Session
  • Singleton
  • SubmitInput
  • Tabs
  • TextareaInput
  • TextInput
  • Theme
  • TimeInput
  • Upload
  • User
  • View
  • ViewPlugin
  • Widget
  • WysiwygInput

Traits

  • Utils

Exceptions

  • AppStopException
  • DBExampleException
  • DBException
  • FileSystemException
  • HawkApiException
  • ImageException
  • MailException
  • UploadException
  • ViewException

Class Router

This class describes the application router. It is used in any plugin to route URIs to controllers methods

Hawk\Singleton
Extended by Hawk\Router
Final
Namespace: Hawk
Package: Core\Router
Located at Router.php

Methods summary

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

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

Hawk\Route
The current route
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

Hawk\Controller
The last instanciated controller
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

Get a route by action

Parameters

$name
The route name of the controller method, formatted like this : 'ControllerClass.method'

Returns

Hawk\Route
The route corresponding to research
public Hawk\Route
# getRouteByUri( string $path )

Find a route from an URI

Find a route from an URI

Parameters

$path
The path to search the associated route

Returns

Hawk\Route
the found route
public Hawk\Route
# getRouteByName( string $name )

Get a route by it name

Get a route by it name

Parameters

$name
The route name

Returns

Hawk\Route
The found route

Methods inherited from Hawk\Singleton

__construct(), getInstance()

Constants summary

string INVALID_URL

Invalid URL. This URI is displayed when no URI was found for a given route name

Invalid URL. This URI is displayed when no URI was found for a given route name

# '/INVALID_URL'

Properties summary

protected static $instance

The router instance

The router instance

#
Hawk - PHP documentation API documentation generated by ApiGen