Documentation

Paths

Class Paths

Table of Contents

Constants

DEFAULT_PATH  = 'civicrm.files'
DEFAULT_URL  = 'cms.root'

Properties

$variableFactory  : mixed
$variables  : array<string|int, mixed>

Methods

__construct()  : mixed
Class constructor.
getPath()  : mixed|string
Determine the absolute path to a file, given that the file is most likely in a given particular variable.
getUrl()  : false|string
Determine the URL to a file.
getVariable()  : mixed
hasVariable()  : bool
Does the variable exist.
register()  : Paths
Register a new URL/file path mapping.
toAbsoluteUrl()  : string

Constants

DEFAULT_PATH

public mixed DEFAULT_PATH = 'civicrm.files'

DEFAULT_URL

public mixed DEFAULT_URL = 'cms.root'

Properties

$variableFactory

private mixed $variableFactory = []

$variables

private array<string|int, mixed> $variables = []

Array(string $name => array(url => $, path => $)).

Methods

__construct()

Class constructor.

public __construct() : mixed

getPath()

Determine the absolute path to a file, given that the file is most likely in a given particular variable.

public getPath(string $value) : mixed|string
Parameters
$value : string

The file path. Use "." to reference to default file root. Values may begin with a variable, e.g. "[civicrm.files]/upload".

Return values
mixed|string

getUrl()

Determine the URL to a file.

public getUrl(string $value[, string $preferFormat = 'relative' ][, bool|null $ssl = NULL ]) : false|string
Parameters
$value : string

The file path. The path may begin with a variable, e.g. "[civicrm.files]/upload".

This function was designed for locating files under a given tree, and the the result for a straight variable expressions ("[foo.bar]") was not originally defined. You may wish to use one of these:

  • getVariable('foo.bar', 'url') => Lookup variable by itself
  • getUrl('[foo.bar]/') => Get the variable (normalized with a trailing "/").
  • getUrl('[foo.bar]/.') => Get the variable (normalized without a trailing "/").
$preferFormat : string = 'relative'

The preferred format ('absolute', 'relative'). The result data may not meet the preference -- if the setting refers to an external domain, then the result will be absolute (regardless of preference).

$ssl : bool|null = NULL

NULL to autodetect. TRUE to force to SSL.

Return values
false|string

The URL for $value (string), or FALSE if the $value is not specified.

getVariable()

public getVariable(string $name, string $attr) : mixed
Parameters
$name : string

Ex: 'civicrm.root'.

$attr : string

Ex: 'url', 'path'.

hasVariable()

Does the variable exist.

public hasVariable(string $name) : bool
Parameters
$name : string
Return values
bool

register()

Register a new URL/file path mapping.

public register(string $name, callable $factory) : Paths
Parameters
$name : string

The name of the variable.

$factory : callable

Function which returns an array with keys:

  • path: string.
  • url: string.
Return values
Paths

toAbsoluteUrl()

private toAbsoluteUrl(string $url, string $for) : string
Parameters
$url : string

Ex: 'https://example.com:8000/foobar' or '/foobar'

$for : string

Ex: 'civicrm.root' or 'civicrm.packages'

Return values
string

        
On this page

Search results