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

Breadcrumb

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

function UriResolver::combineRelativePathWithBasePath

Tries to glue a relative path onto an absolute one

Parameters

string $relativePath:

string $basePath:

Return value

string Merged path

Throws

UriResolverException

2 calls to UriResolver::combineRelativePathWithBasePath()
UriResolver::resolve in vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriResolver.php
Resolves a URI
UriRetriever::resolve in vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriRetriever.php
Resolves a URI

File

vendor/justinrainbow/json-schema/src/JsonSchema/Uri/UriResolver.php, line 125

Class

UriResolver
Resolves JSON Schema URIs

Namespace

JsonSchema\Uri

Code

public static function combineRelativePathWithBasePath($relativePath, $basePath) {
    $relativePath = self::normalizePath($relativePath);
    if ($relativePath == '') {
        return $basePath;
    }
    if ($relativePath[0] == '/') {
        return $relativePath;
    }
    $basePathSegments = explode('/', $basePath);
    preg_match('|^/?(\\.\\./(?:\\./)*)*|', $relativePath, $match);
    $numLevelUp = strlen($match[0]) / 3 + 1;
    if ($numLevelUp >= count($basePathSegments)) {
        throw new UriResolverException(sprintf("Unable to resolve URI '%s' from base '%s'", $relativePath, $basePath));
    }
    $basePathSegments = array_slice($basePathSegments, 0, -$numLevelUp);
    $path = preg_replace('|^/?(\\.\\./(\\./)*)*|', '', $relativePath);
    return implode('/', $basePathSegments) . '/' . $path;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal