public function UrlGenerator::setRequest

Implements \Drupal\Core\Routing\PathBasedGeneratorInterface::setRequest().

Overrides PathBasedGeneratorInterface::setRequest

File

drupal/core/lib/Drupal/Core/Routing/UrlGenerator.php, line 93
Contains Drupal\Core\Routing\UrlGenerator.

Class

UrlGenerator
A Generator creates URL strings based on a specified route.

Namespace

Drupal\Core\Routing

Code

public function setRequest(Request $request) {
  $this->request = $request;

  // Set some properties, based on the request, that are used during path-based
  // url generation.
  $this->basePath = $request
    ->getBasePath() . '/';
  $this->baseUrl = $request
    ->getSchemeAndHttpHost() . $this->basePath;
  $this->scriptPath = '';
  $base_path_with_script = $request
    ->getBaseUrl();
  $script_name = $request
    ->getScriptName();
  if (!empty($base_path_with_script) && strpos($base_path_with_script, $script_name) !== FALSE) {
    $length = strlen($this->basePath);
    $this->scriptPath = ltrim(substr($script_name, $length), '/') . '/';
  }
}