protected static function RequestHandler::getNormalizedRequestMethod in Drupal 10
Same name and namespace in other branches
- 8 core/modules/rest/src/RequestHandler.php \Drupal\rest\RequestHandler::getNormalizedRequestMethod()
- 9 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.
File
- core/
modules/ rest/ src/ RequestHandler.php, line 119
Class
- RequestHandler
- Acts as intermediate request forwarder for resource plugins.
Namespace
Drupal\restCode
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;
}