You are here

protected function Tracker::getRequestForUrl in Menu Entity Index 8

Matches an absolute URL in the router.

Parameters

string $url: The absolute URL to match.

Return value

\Symfony\Component\HttpFoundation\Request|null A populated request object or NULL if the path couldn't be matched.

1 call to Tracker::getRequestForUrl()
Tracker::updateEntity in src/Tracker.php
Updates database tracking for new or updated entities.

File

src/Tracker.php, line 422

Class

Tracker
Tracks menu links and their referenced entities.

Namespace

Drupal\menu_entity_index

Code

protected function getRequestForUrl($url) {

  // Work around 1433996, 2070185, 2529170, 2548095, 2568773, 2753591 and
  // other related core issues.
  $current_request = $this->requestStack
    ->getCurrentRequest();
  if (strpos($url, $current_request
    ->getSchemeAndHttpHost()) === 0) {
    $url = substr($url, strlen($current_request
      ->getSchemeAndHttpHost()));
  }
  if (!empty($current_request
    ->getBaseUrl()) && strpos($url, $current_request
    ->getBaseUrl()) === 0) {
    $url = substr($url, strlen($current_request
      ->getBaseUrl()));
  }

  // Don't try to track external URLs.
  $validated_url = $this->pathValidator
    ->getUrlIfValidWithoutAccessCheck($url);
  if (!$validated_url || $validated_url
    ->isExternal()) {
    return NULL;
  }
  $request = Request::create($url);

  // Performance optimization: set a short accept header to reduce overhead in
  // AcceptHeaderMatcher when matching the request.
  $request->headers
    ->set('Accept', 'text/html');

  // Find the system path by resolving aliases, language prefix, etc.
  $processed = $this->pathProcessor
    ->processInbound($url, $request);
  if (empty($processed)) {

    // This resolves to the front page.
    return NULL;
  }

  // Attempt to match this path to provide a fully built request.
  try {
    $request->attributes
      ->add($this->router
      ->matchRequest($request));
    return $request;
  } catch (ParamNotConvertedException $e) {
    return NULL;
  } catch (ResourceNotFoundException $e) {
    return NULL;
  } catch (MethodNotAllowedException $e) {
    return NULL;
  } catch (AccessDeniedHttpException $e) {
    return NULL;
  }
}