• PHP reference
  • Sandbox

Route

class Sandbox\Route

Makes it ease to separate requests based on path.

Example:


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

Route::catch(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 Route::reset() first.

Methods

static get(string $path, callable $callable = null)

Executes $callable when $path expression matches current path for an HTTP GET request.

Parameters

  • string $path
  • callable $callable

static post(string $path, callable $callable = null)

Executes $callable when $path expression matches current path for an HTTP POST request.

Parameters

  • string $path
  • callable $callable

static put(string $path, callable $callable = null)

Executes $callable when $path expression matches current path for an HTTP PUT request.

Parameters

  • string $path
  • callable $callable

static delete(string $path, callable $callable = null)

Executes $callable when $path expression matches current path for an HTTP DELETE request.

Parameters

  • string $path
  • callable $callable

static patch(string $path, callable $callable = null)

Executes $callable when $path expression matches current path for an HTTP PATCH request.

Parameters

  • string $path
  • callable $callable

static head(string $path, callable $callable = null)

Executes $callable when $path expression matches current path for an HTTP HEAD request.

Parameters

  • string $path
  • callable $callable

static options(string $path, callable $callable = null)

Executes $callable when $path expression matches current path for an HTTP OPTIONS request.

Parameters

  • string $path
  • callable $callable

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

Executes $callable when $path expression matches current path for any type of HTTP request.

Parameters

  • string $path
  • callable $callable

static catch(callable $callable = null)

When no earlier routes have matched the current path, this method's callback will be executed as a catch-all.

Parameters

  • callable $callable

static reset()

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

static boolean hasMatched()

Whether a route was matched.

Return Value

  • boolean