Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

(no description)

File Size: 211 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

UriResolver:: (5 methods):
  removeDotSegments()
  resolve()
  relativize()
  getRelativePath()
  __construct()


Class: UriResolver  - X-Ref

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

removeDotSegments(string $path)   X-Ref
Removes dot segments from a path and returns the new path.


resolve(UriInterface $base, UriInterface $rel)   X-Ref
Converts the relative URI into a new URI that is resolved against the base URI.


relativize(UriInterface $base, UriInterface $target)   X-Ref
Returns the target URI as a relative reference from the base URI.

This method is the counterpart to resolve():

(string) $target === (string) UriResolver::resolve($base, UriResolver::relativize($base, $target))

One use-case is to use the current request URI as base URI and then generate relative links in your documents
to reduce the document size or offer self-contained downloadable document archives.

$base = new Uri('http://example.com/a/b/');
echo UriResolver::relativize($base, new Uri('http://example.com/a/b/c'));  // prints 'c'.
echo UriResolver::relativize($base, new Uri('http://example.com/a/x/y'));  // prints '../x/y'.
echo UriResolver::relativize($base, new Uri('http://example.com/a/b/?q')); // prints '?q'.
echo UriResolver::relativize($base, new Uri('http://example.org/a/b/'));   // prints '//example.org/a/b/'.

This method also accepts a target that is already relative and will try to relativize it further. Only a
relative-path reference will be returned as-is.

echo UriResolver::relativize($base, new Uri('/a/b/c'));  // prints 'c' as well

getRelativePath(UriInterface $base, UriInterface $target)   X-Ref
No description

__construct()   X-Ref
No description