public function HttpMethodMatcher::matchRequestPartial

Matches a request against multiple routes.

Parameters

\Symfony\Component\HttpFoundation\Request $request: A Request object against which to match.

Return value

\Symfony\Component\Routing\RouteCollection A RouteCollection of matched routes.

Overrides PartialMatcherInterface::matchRequestPartial

File

drupal/core/lib/Drupal/Core/Routing/HttpMethodMatcher.php, line 28
Definition of Drupal\Core\Routing\HttpMethodMatcher.

Class

HttpMethodMatcher
This class filters routes based on their HTTP Method.

Namespace

Drupal\Core\Routing

Code

public function matchRequestPartial(Request $request) {
  $possible_methods = array();
  $method = $request
    ->getMethod();
  $collection = new RouteCollection();
  foreach ($this->routes
    ->all() as $name => $route) {

    // _method could be a |-delimited list of allowed methods, or null. If
    // null, we accept any method.
    $allowed_methods = array_filter(explode('|', strtoupper($route
      ->getRequirement('_method'))));
    if (empty($allowed_methods) || in_array($method, $allowed_methods)) {
      $collection
        ->add($name, $route);
    }
    else {

      // Build a list of methods that would have matched. Note that we only
      // need to do this if a route doesn't match, because if even one route
      // passes then we'll never throw the exception that needs this array.
      $possible_methods += $allowed_methods;
    }
  }
  if (!count($collection
    ->all())) {
    throw new MethodNotAllowedException(array_unique($possible_methods));
  }
  return $collection;
}