class Resolve (View source)

The Resolve class holds all methods to modulate URLs and file paths.

Since all page URLs are not URLs to real directories, all non-absolute links and file paths have to be resolved, to point to a valid location. For example a relative file name to an image wouldn't be a valid link, since the URL of the page is not the real file system path to the page's files.

Methods

static string
absoluteUrlToDomain(string $url)

Resolve absolute URLs (starting with a slash) to the domain.

static string
absoluteUrlToRoot(string $url)

Resolve absolute URLs (starting with a slash) to root in case Automad is installed within a subdirectory.

static string
filePath(string $pagePath, string $filePath)

Resolve a file path or glob pattern according to its type (root relative or relative).

static string
relativeUrlToBase(string $url, Page $Page)

Resolve relative URLs (starting with a character or .) to be absolute URLs, using the base directory (where Automad is installed) as root.

Details

static string absoluteUrlToDomain(string $url)

Resolve absolute URLs (starting with a slash) to the domain.

Example: /page -> https://domain/base-url/index.php/page or /page -> https://domain/base-url/page

Parameters

string $url

Return Value

string The resolved URL

static string absoluteUrlToRoot(string $url)

Resolve absolute URLs (starting with a slash) to root in case Automad is installed within a subdirectory.

Example: /page -> /base-url/index.php/page or /page -> /base-url/page

Parameters

string $url

Return Value

string The resolved URL

static string filePath(string $pagePath, string $filePath)

Resolve a file path or glob pattern according to its type (root relative or relative).

If a file path begins with a '/', it is treated like a root relative path and the only AM_BASE_DIR gets prepended. In all other cases, the full path to the page gets prepended. For example a file called 'image.jpg' becomes '/basedir/pages/pagedir/image.jpg' and '/shared/image.jpg' becomes '/basedir/shared/image.jpg'.

Parameters

string $pagePath
string $filePath

Return Value

string The resolved file path

static string relativeUrlToBase(string $url, Page $Page)

Resolve relative URLs (starting with a character or .) to be absolute URLs, using the base directory (where Automad is installed) as root.

Example: image.png -> /pages/path/image.png or subpage -> /parent/subpage or ../ -> /parent

Parameters

string $url
Page $Page

Return Value

string The resolved URL