class StringUtils (View source)

Methods

static array
csvToArray($args)

Convert a csv string, or an array of items which may contain csv strings, into an array of items.

static string
interpolate(string $message, array $context = [])

Replace placeholders in a string.

static string
replaceTilde($path, $home)

Replace tilde in a path with the HOME directory.

static string
generatePassword(int $length = 10)

Generate a random alphanumeric password. Copied from user.module.

Details

static array csvToArray($args)

Convert a csv string, or an array of items which may contain csv strings, into an array of items.

Parameters

$args A simple csv string; e.g. 'a,b,c' or a simple list of items; e.g. array('a','b','c') or some combination; e.g. array('a,b','c') or array('a,','b,','c,')

Return Value

array A simple list of items (e.g. array('a','b','c')

static string interpolate(string $message, array $context = [])

Replace placeholders in a string.

Examples: interpolate('Hello, {var}', ['var' => 'world']) ==> 'Hello, world' interpolate('Do !what', ['!what' => 'work']) ==> 'Do work'

Parameters

string $message The string with placeholders to be interpolated.
array $context An associative array of values to be inserted into the message.

Return Value

string The resulting string with all placeholders filled in.

static string replaceTilde($path, $home)

Replace tilde in a path with the HOME directory.

Parameters

$path A path that may contain a ~ at front.
$home The effective home dir for this request.

Return Value

string The path with tilde replaced, if applicable. The path with tilde replaced, if applicable.

static string generatePassword(int $length = 10)

Generate a random alphanumeric password. Copied from user.module.

Parameters

int $length

Return Value

string