function UriResolver::combineRelativePathWithBasePath
Tries to glue a relative path onto an absolute one
Parameters
string $relativePath:
string $basePath:
Return value
string Merged path
Throws
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\UriCode
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;
}