Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UriResolver.php

function UriResolver::resolve

Same name in this branch
  1. 11.1.x vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriResolver.php \JsonSchema\Uri\UriResolver::resolve()
  2. 11.1.x vendor/symfony/dom-crawler/UriResolver.php \Symfony\Component\DomCrawler\UriResolver::resolve()

Converts the relative URI into a new URI that is resolved against the base URI.

See also

https://datatracker.ietf.org/doc/html/rfc3986#section-5.2

1 call to UriResolver::resolve()
Uri::isSameDocumentReference in vendor/guzzlehttp/psr7/src/Uri.php
Whether the URI is a same-document reference.

File

vendor/guzzlehttp/psr7/src/UriResolver.php, line 58

Class

UriResolver
Resolves a URI reference in the context of a base URI and the opposite way.

Namespace

GuzzleHttp\Psr7

Code

public static function resolve(UriInterface $base, UriInterface $rel) : UriInterface {
    if ((string) $rel === '') {
        // we can simply return the same base URI instance for this same-document reference
        return $base;
    }
    if ($rel->getScheme() != '') {
        return $rel->withPath(self::removeDotSegments($rel->getPath()));
    }
    if ($rel->getAuthority() != '') {
        $targetAuthority = $rel->getAuthority();
        $targetPath = self::removeDotSegments($rel->getPath());
        $targetQuery = $rel->getQuery();
    }
    else {
        $targetAuthority = $base->getAuthority();
        if ($rel->getPath() === '') {
            $targetPath = $base->getPath();
            $targetQuery = $rel->getQuery() != '' ? $rel->getQuery() : $base->getQuery();
        }
        else {
            if ($rel->getPath()[0] === '/') {
                $targetPath = $rel->getPath();
            }
            else {
                if ($targetAuthority != '' && $base->getPath() === '') {
                    $targetPath = '/' . $rel->getPath();
                }
                else {
                    $lastSlashPos = strrpos($base->getPath(), '/');
                    if ($lastSlashPos === false) {
                        $targetPath = $rel->getPath();
                    }
                    else {
                        $targetPath = substr($base->getPath(), 0, $lastSlashPos + 1) . $rel->getPath();
                    }
                }
            }
            $targetPath = self::removeDotSegments($targetPath);
            $targetQuery = $rel->getQuery();
        }
    }
    return new Uri(Uri::composeComponents($base->getScheme(), $targetAuthority, $targetPath, $targetQuery, $rel->getFragment()));
}
RSS feed
Powered by Drupal