ICanBoogie
  • Documentation
  • API Reference
  • Routing master
Namespaces
  • ICanBoogie
    • Routing
      • Controller
      • Route
      • RouteDispatcher
Classes
  • Controller
  • FormattedRoute
  • Helpers
  • Pattern
  • Route
  • RouteCollection
  • RouteDefinition
  • RouteDispatcher
  • RouteMaker
Interfaces
  • Exception
  • ToSlug
Exceptions
  • ActionNotDefined
  • ControllerNotDefined
  • PatternNotDefined
  • PatternRequiresValues
  • RouteNotDefined

Class RouteDispatcher

Dispatch requests among the defined routes.

If a route matching the request is found, the $route and $decontextualized_path properties are added to the ICanBoogie\HTTP\Request instance. $route holds the ICanBoogie\Routing\Route instance, $decontextualized_path holds the decontextualized path. The path is decontextualized using the decontextualize() function.

ICanBoogie\Routing\RouteDispatcher implements ICanBoogie\HTTP\Dispatcher uses ICanBoogie\Accessor\AccessorTrait (not available)
Namespace: ICanBoogie\Routing
Located at RouteDispatcher.php

Methods summary

protected get_routes( void )
public __construct( ICanBoogie\Routing\RouteCollection $routes = null )

Parameters

$routes
public __invoke( ICanBoogie\HTTP\Request $request ) : ICanBoogie\HTTP\Response|null

Parameters

$request

Returns

ICanBoogie\HTTP\Response|null
protected normalize_path( string $path ) : string

Normalizes request path.

Normalizes request path.

Parameters

$path

Returns

string
Decontextualized path with trimmed ending slash.
protected resolve_route( ICanBoogie\HTTP\Request $request, string $normalized_path, array & $captured ) : false|ICanBoogie\Routing\Route|null

Resolves route from request.

Resolves route from request.

Parameters

$request
$normalized_path
$captured

Returns

false|ICanBoogie\Routing\Route|null
protected alter_params( ICanBoogie\Routing\Route $route, ICanBoogie\HTTP\Request $request, array $captured )

Alters request parameters.

Alters request parameters.

Parameters

$route
$request
$captured
Parameters captured from the request's path.
protected alter_context( ICanBoogie\HTTP\Request\Context $context, ICanBoogie\Routing\Route $route, callable $controller )

Alters request context with route and controller.

Alters request context with route and controller.

Parameters

$context
$route
$controller
protected dispatch( ICanBoogie\Routing\Route $route, ICanBoogie\HTTP\Request $request ) : ICanBoogie\HTTP\Response|null

Dispatches the route.

Dispatches the route.

Parameters

$route
$request

Returns

ICanBoogie\HTTP\Response|null
protected respond( ICanBoogie\Routing\Route $route, ICanBoogie\HTTP\Request $request ) : ICanBoogie\HTTP\Response|mixed

Returns a response for the route and request.

Returns a response for the route and request.

If the controller's result is not null but is not in instance of ICanBoogie\HTTP\Response, its result is wrapped in a response instance with the status code 200 and the Content-Type "text/html; charset=utf-8".

Parameters

$route
$request

Returns

ICanBoogie\HTTP\Response|mixed
public rescue( ICanBoogie\Routing\Exception $exception, ICanBoogie\HTTP\Request $request ) : ICanBoogie\HTTP\Response

Fires \ICanBoogie\Routing\RouteDispatcher\RescueEvent and returns the response provided by third parties. If no response was provided, the exception (or the exception provided by third parties) is re-thrown.

Fires \ICanBoogie\Routing\RouteDispatcher\RescueEvent and returns the response provided by third parties. If no response was provided, the exception (or the exception provided by third parties) is re-thrown.

Parameters

$exception
The exception to rescue.
$request
The request being dispatched.

Returns

ICanBoogie\HTTP\Response

Throws

Exception
if the exception cannot be rescued.

Properties summary

protected $routes : ICanBoogie\Routing\RouteCollection

Route collection.

Route collection.


		

Magic properties

public read-only $routes : ICanBoogie\Routing\RouteCollection
Routing master – Check on GitHub – API documentation generated by ApiGen