You are here

public function EasyRdf_ParsedUri::resolve in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/ParsedUri.php \EasyRdf_ParsedUri::resolve()

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

File

vendor/easyrdf/easyrdf/lib/EasyRdf/ParsedUri.php, line 254

Class

EasyRdf_ParsedUri
A RFC3986 compliant URI parser

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
    ->normalise();
  return $target;
}