• PHP reference
  • Includable

Router

class Includable\HTTP\Router

Makes it ease to separate requests based on path.

Example:


$router = new \Includable\HTTP\Router();

$router->get('project/:project/tasks/:task', function($args) {
   return 'Here is project ' . $args['project'] . ' task ' . $args['task'];
});

$router->any(function() {
   $url = Request::instance()->base_url . '/project/123/task/456';
   return 'Try going <a href="' . $url . '">here</a> instead.';
});

Note: only the first callback on any of these functions that has a matching path is called, unless you call $router->reset() first.

Methods

__construct(string $prefix = '', Router $parentRoute = null)

Route constructor.

Parameters

  • string $prefix
  • Router $parentRoute

mixed withPrefix($prefix, $callable)

Get a new router with a specific prefix.

Parameters

  • $prefix
  • $callable

Return Value

  • mixed

Exceptions

mixed use($callable)

Apply a certain function to the router.

Parameters

  • $callable

Return Value

  • mixed

Exceptions

string getNamespace()

Return Value

  • string

Router setNamespace(string $namespace)

Parameters

  • string $namespace

Return Value

boolean __call(string $method, array $arguments)

Executes $callable when $path expression matches current path for an HTTP request with a specific method.

Parameters

  • string $method
  • array $arguments

Return Value

  • boolean

Exceptions

reset()

Reset whether the class has matched any route, in order to be able to use it again.

boolean foundMatch()

Whether the router found a match.

Return Value

  • boolean

bool get(string $path, string $callable)

Executes $callable when $path expression

Parameters

  • string $path
  • string $callable

Return Value

  • bool

bool post(string $path, string $callable)

Executes $callable when $path expression

Parameters

  • string $path
  • string $callable

Return Value

  • bool

bool put(string $path, string $callable)

Executes $callable when $path expression

Parameters

  • string $path
  • string $callable

Return Value

  • bool

bool delete(string $path, string $callable)

Executes $callable when $path

Parameters

  • string $path
  • string $callable

Return Value

  • bool

bool options(string $path, string $callable)

Executes $callable when $path

Parameters

  • string $path
  • string $callable

Return Value

  • bool

bool head(string $path, string $callable)

Executes $callable when $path expression

Parameters

  • string $path
  • string $callable

Return Value

  • bool

bool any(callable $path = null, string $callable)

Executes $callable when

Parameters

  • callable $path
  • string $callable

Return Value

  • bool