Class RoutingMiddleware

Applies routing rules to the request and creates the controller instance if possible.

Constants summary

  • string
    ROUTE_COLLECTION_CACHE_KEY
    'routeCollection'

Properties summary

  • $app protected
    \Cake\Core\HttpApplicationInterface|null

    The application that will have its routing hook invoked.

  • $cacheConfig protected
    string|null

    The cache configuration name to use for route collection caching, null to disable caching

Method Summary

  • __construct() public

    Constructor

  • __invoke() public

    Apply routing and update the request.

  • buildRouteCollection() protected

    Check if route cache is enabled and use the configured Cache to 'remember' the route collection

  • loadRoutes() protected

    Trigger the application's routes() hook if the application exists and Router isn't initialized.

  • prepareRouteCollection() protected

    Generate the route collection using the builder

Method Detail

__construct() public

__construct(\Cake\Core\HttpApplicationInterface $app, mixed $cacheConfig)

Constructor

Parameters

\Cake\Core\HttpApplicationInterface|null $app optional

The application instance that routes are defined on.

string|null $cacheConfig optional

The cache config name to use or null to disable routes cache

__invoke() public

__invoke(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, mixed $next)

Apply routing and update the request.

Any route/path specific middleware will be wrapped around $next and then the new middleware stack will be invoked.

Parameters

\Psr\Http\Message\ServerRequestInterface $request

The request.

\Psr\Http\Message\ResponseInterface $response

The response.

callable $next

The next middleware to call.

Returns

\Psr\Http\Message\ResponseInterface

A response.

buildRouteCollection() protected

buildRouteCollection()

Check if route cache is enabled and use the configured Cache to 'remember' the route collection

Returns

\Cake\Routing\RouteCollection

loadRoutes() protected

loadRoutes()

Trigger the application's routes() hook if the application exists and Router isn't initialized.

Uses the routes cache if enabled via configuration param "Router.cache"

If the middleware is created without an Application, routes will be loaded via the automatic route loading that pre-dates the routes() hook.

prepareRouteCollection() protected

prepareRouteCollection()

Generate the route collection using the builder

Returns

\Cake\Routing\RouteCollection

Property Detail

$app protected

The application that will have its routing hook invoked.

Type

\Cake\Core\HttpApplicationInterface|null

$cacheConfig protected

The cache configuration name to use for route collection caching, null to disable caching

Type

string|null

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/class-Cake.Routing.Middleware.RoutingMiddleware.html