public static function RouteMatch::createFromRequest

public static RouteMatch::createFromRequest(Request $request)

Creates a RouteMatch from a request.

Parameters

Request $request: A request object.

Return value

\Drupal\Core\Routing\RouteMatchInterface A new RouteMatch object if there's a matched route for the request. A new NullRouteMatch object otherwise (e.g., on a 404 page or when invoked prior to routing).

File

core/lib/Drupal/Core/Routing/RouteMatch.php, line 78

Class

RouteMatch
Default object representing the results of routing.

Namespace

Drupal\Core\Routing

Code

public static function createFromRequest(Request $request) {
  if ($request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) {
    $raw_variables = array();
    if ($raw = $request->attributes->get('_raw_variables')) {
      $raw_variables = $raw->all();
    }
    return new static(
    $request->attributes->get(RouteObjectInterface::ROUTE_NAME), 
    $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT), 
    $request->attributes->all(), 
    $raw_variables);
  }
  else {
    return new NullRouteMatch();
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Routing!RouteMatch.php/function/RouteMatch::createFromRequest/8.1.x