You are here

public function EasyRdf_ParsedUri::resolve in Drupal 8

Resolves a relative URI using this URI as the base URI.

File

core/modules/rdf/tests/src/Traits/EasyRdf_ParsedUri.php, line 266

Class

EasyRdf_ParsedUri
A RFC3986 compliant URI parser

Namespace

Drupal\Tests\rdf\Traits

Code

public function resolve($relUri) {

  // If it is a string, then convert it to a parsed object
  if (is_string($relUri)) {
    $relUri = new EasyRdf_ParsedUri($relUri);
  }

  // This code is based on the pseudocode in section 5.2.2 of RFC3986
  $target = new EasyRdf_ParsedUri();
  if ($relUri->scheme) {
    $target->scheme = $relUri->scheme;
    $target->authority = $relUri->authority;
    $target->path = $relUri->path;
    $target->query = $relUri->query;
  }
  else {
    if ($relUri->authority) {
      $target->authority = $relUri->authority;
      $target->path = $relUri->path;
      $target->query = $relUri->query;
    }
    else {
      if (empty($relUri->path)) {
        $target->path = $this->path;
        if ($relUri->query) {
          $target->query = $relUri->query;
        }
        else {
          $target->query = $this->query;
        }
      }
      else {
        if (substr($relUri->path, 0, 1) == '/') {
          $target->path = $relUri->path;
        }
        else {
          $path = $this->path;
          $lastSlash = strrpos($path, '/');
          if ($lastSlash !== false) {
            $path = substr($path, 0, $lastSlash + 1);
          }
          else {
            $path = '/';
          }
          $target->path .= $path . $relUri->path;
        }
        $target->query = $relUri->query;
      }
      $target->authority = $this->authority;
    }
    $target->scheme = $this->scheme;
  }
  $target->fragment = $relUri->fragment;
  $target
    ->normalize();
  return $target;
}