public function RequestMatcher::matches

@api

Overrides RequestMatcherInterface::matches

File

drupal/core/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/RequestMatcher.php, line 132

Class

RequestMatcher
RequestMatcher compares a pre-defined set of checks against a Request instance.

Namespace

Symfony\Component\HttpFoundation

Code

public function matches(Request $request) {
  if ($this->methods && !in_array($request
    ->getMethod(), $this->methods)) {
    return false;
  }
  foreach ($this->attributes as $key => $pattern) {
    if (!preg_match('{' . $pattern . '}', $request->attributes
      ->get($key))) {
      return false;
    }
  }
  if (null !== $this->path && !preg_match('{' . $this->path . '}', rawurldecode($request
    ->getPathInfo()))) {
    return false;
  }
  if (null !== $this->host && !preg_match('{' . $this->host . '}i', $request
    ->getHost())) {
    return false;
  }
  if (IpUtils::checkIp($request
    ->getClientIp(), $this->ips)) {
    return true;
  }

  // Note to future implementors: add additional checks above the
  // foreach above or else your check might not be run!
  return count($this->ips) === 0;
}