You are here

public function Link::getUri in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/dom-crawler/Link.php \Symfony\Component\DomCrawler\Link::getUri()

Gets the URI associated with this link.

Return value

string The URI

1 call to Link::getUri()
Form::getUri in vendor/symfony/dom-crawler/Form.php
Gets the URI of the form.
1 method overrides Link::getUri()
Form::getUri in vendor/symfony/dom-crawler/Form.php
Gets the URI of the form.

File

vendor/symfony/dom-crawler/Link.php, line 81

Class

Link
Link represents an HTML link (an HTML a, area or link tag).

Namespace

Symfony\Component\DomCrawler

Code

public function getUri() {
  $uri = trim($this
    ->getRawUri());

  // absolute URL?
  if (null !== parse_url($uri, PHP_URL_SCHEME)) {
    return $uri;
  }

  // empty URI
  if (!$uri) {
    return $this->currentUri;
  }

  // an anchor
  if ('#' === $uri[0]) {
    return $this
      ->cleanupAnchor($this->currentUri) . $uri;
  }
  $baseUri = $this
    ->cleanupUri($this->currentUri);
  if ('?' === $uri[0]) {
    return $baseUri . $uri;
  }

  // absolute URL with relative schema
  if (0 === strpos($uri, '//')) {
    return preg_replace('#^([^/]*)//.*$#', '$1', $baseUri) . $uri;
  }
  $baseUri = preg_replace('#^(.*?//[^/]*)(?:\\/.*)?$#', '$1', $baseUri);

  // absolute path
  if ('/' === $uri[0]) {
    return $baseUri . $uri;
  }

  // relative path
  $path = parse_url(substr($this->currentUri, strlen($baseUri)), PHP_URL_PATH);
  $path = $this
    ->canonicalizePath(substr($path, 0, strrpos($path, '/')) . '/' . $uri);
  return $baseUri . ('' === $path || '/' !== $path[0] ? '/' : '') . $path;
}