function RequestHandler::getNormalizedRequestMethod

Same name in other branches
  1. 9 core/modules/rest/src/RequestHandler.php \Drupal\rest\RequestHandler::getNormalizedRequestMethod()
  2. 8.9.x core/modules/rest/src/RequestHandler.php \Drupal\rest\RequestHandler::getNormalizedRequestMethod()
  3. 10 core/modules/rest/src/RequestHandler.php \Drupal\rest\RequestHandler::getNormalizedRequestMethod()

Gets the normalized HTTP request method of the matched route.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.

Return value

string The normalized HTTP request method.

2 calls to RequestHandler::getNormalizedRequestMethod()
RequestHandler::delegateToRestResourcePlugin in core/modules/rest/src/RequestHandler.php
Delegates an incoming request to the appropriate REST resource plugin.
RequestHandler::deserialize in core/modules/rest/src/RequestHandler.php
Deserializes request body, if any.

File

core/modules/rest/src/RequestHandler.php, line 119

Class

RequestHandler
Acts as intermediate request forwarder for resource plugins.

Namespace

Drupal\rest

Code

protected static function getNormalizedRequestMethod(RouteMatchInterface $route_match) {
    // Symfony is built to transparently map HEAD requests to a GET request. In
    // the case of the REST module's RequestHandler though, we essentially have
    // our own light-weight routing system on top of the Drupal/symfony routing
    // system. So, we have to respect the decision that the routing system made:
    // we look not at the request method, but at the route's method. All REST
    // routes are guaranteed to have _method set.
    // Response::prepare() will transform it to a HEAD response at the very last
    // moment.
    // @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4
    // @see \Symfony\Component\Routing\Matcher\UrlMatcher::matchCollection()
    // @see \Symfony\Component\HttpFoundation\Response::prepare()
    $method = strtolower($route_match->getRouteObject()
        ->getMethods()[0]);
    assert(count($route_match->getRouteObject()
        ->getMethods()) === 1);
    return $method;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.