PHP Class kahlan\util\Text

Datei anzeigen Open project: crysalead/kahlan Class Usage Examples

Public Methods

Method Description
clean ( string $str, array $options = [] ) : string Cleans up a Text::insert() formatted string with given $options depending on the 'clean' option. The goal of this function is to replace all whitespace and unneeded mark-up around place-holders that did not get replaced by Text::insert().
dump ( mixed $value, $quote = '"' ) : string Dump some scalar data using a string representation
insert ( string $str, array $data, array $options = [] ) : string Replaces variable placeholders inside a string with any given data. Each key in the $data array corresponds to a variable placeholder name in $str.
toString ( string $value, array $options = [] ) : string Generate a string representation of arbitrary data.

Protected Methods

Method Description
_arrayToString ( array $datas, array $options ) : string Generate a string representation of an array.
_dump ( string $string ) : string Expands escape sequences and escape special chars in a string.
_objectToString ( array $value, $options ) : string Generate a string representation of an object.

Method Details

_arrayToString() protected static method

Generate a string representation of an array.
protected static _arrayToString ( array $datas, array $options ) : string
$datas array An array.
$options array An array of options.
return string The dumped string.

_dump() protected static method

Expands escape sequences and escape special chars in a string.
protected static _dump ( string $string ) : string
$string string A string which contain escape sequence.
return string A valid double quotable string.

_objectToString() protected static method

Generate a string representation of an object.
protected static _objectToString ( array $value, $options ) : string
$value array The object.
return string The dumped string.

clean() public static method

Cleans up a Text::insert() formatted string with given $options depending on the 'clean' option. The goal of this function is to replace all whitespace and unneeded mark-up around place-holders that did not get replaced by Text::insert().
public static clean ( string $str, array $options = [] ) : string
$str string The string to clean.
$options array Available options are: - `'before'`: characters marking the start of targeted substring. - `'after'`: characters marking the end of targeted substring. - `'escape'`: The character or string used to escape the before character or string (defaults to `'\\'`). - `'gap'`: Regular expression matching gaps. - `'word'`: Regular expression matching words. - `'replacement'`: String to use for cleaned substrings (defaults to `''`).
return string The cleaned string.

dump() public static method

Dump some scalar data using a string representation
public static dump ( mixed $value, $quote = '"' ) : string
$value mixed The scalar data to dump
return string The dumped string.

insert() public static method

Usage: {{{ Text::insert( 'My name is {:name} and I am {:age} years old.', ['name' => 'Bob', 'age' => '65'] ); }}}
public static insert ( string $str, array $data, array $options = [] ) : string
$str string A string containing variable place-holders.
$data array A key, value array where each key stands for a place-holder variable name to be replaced with value.
$options array Available options are: - `'before'`: The character or string in front of the name of the variable place-holder (defaults to `'{:'`). - `'after'`: The character or string after the name of the variable place-holder (defaults to `}`). - `'escape'`: The character or string used to escape the before character or string (defaults to `'\\'`). - `'clean'`: A boolean or array with instructions for `Text::clean()`.
return string

toString() public static method

Generate a string representation of arbitrary data.
public static toString ( string $value, array $options = [] ) : string
$value string The data to dump in string.
$options array Available options are: - `'quote'` : dump will quote string data if true (default `true`). - `'object'`: dump options for objects. - `'method'`: default method to call on string instance (default `__toString`). - `'array'` : dump options for arrays. - `'indent'`: level of indent (defaults to `1`). - `'char'`: indentation character. - `'multiplier'`: number of indentation character per indent (default `4`)
return string The dumped string.