class StructureHelper (View source)

Class StructureHelper

Methods

static array
loadFile(string $file, string $format = Format::JSON, array $options = array())

Load the contents of a file into the structure

static array
loadString(string $data, string $format = Format::JSON, array $options = array())

Load a string into the structure

static string
toString(array|object $data, string $format = Format::JSON, mixed $options = array())

Get a namespace in a given string format

static string|FormatInterface
getFormatClass(string $format)

getFormatClass

static boolean
isAssociativeArray(array $array)

Method to determine if an array is an associative array.

static mixed
getValue(array $array, string $name, mixed $default = null)

getValue

static object
toObject(array $array, string $class = 'stdClass')

Utility function to map an array to a stdClass object.

static mixed
getByPath(array $data, mixed $path, string $separator = '.')

Get data from array or object by path.

static boolean
setByPath(array $data, string $path, mixed $value, string $separator = '.')

setByPath

static array
getPathNodes(string $path, string $separator = '.')

Explode the structure path into an array and remove empty nodes that occur as a result of a double dot. ex: windwalker.

static array
flatten(array|object $array, string $separator = '.', string $prefix = '')

Method to recursively convert data to one dimension array.

static array
toArray(mixed $data, bool $recursive = false)

Utility function to convert all types to an array.

static array
dumpObjectValues(mixed $object)

dumpObjectValues

Details

at line line 36
static array loadFile(string $file, string $format = Format::JSON, array $options = array())

Load the contents of a file into the structure

Parameters

string $file Path to file to load
string $format Format of the file [optional: defaults to JSON]
array $options Options used by the formatter

Return Value

array Return parsed array.

at line line 66
static array loadString(string $data, string $format = Format::JSON, array $options = array())

Load a string into the structure

Parameters

string $data String to load into the structure
string $format Format of the string
array $options Options used by the formatter

Return Value

array Return parsed array.

at line line 85
static string toString(array|object $data, string $format = Format::JSON, mixed $options = array())

Get a namespace in a given string format

Parameters

array|object $data The structure data to convert to markup string.
string $format Format to return the string in
mixed $options Parameters used by the formatter, see formatters for more info

Return Value

string Namespace in string format

at line line 103
static string|FormatInterface getFormatClass(string $format)

getFormatClass

Parameters

string $format

Return Value

string|FormatInterface

Exceptions

DomainException

at line line 123
static boolean isAssociativeArray(array $array)

Method to determine if an array is an associative array.

Parameters

array $array An array to test.

Return Value

boolean True if the array is an associative array.

at line line 148
static mixed getValue(array $array, string $name, mixed $default = null)

getValue

Parameters

array $array
string $name
mixed $default

Return Value

mixed

at line line 163
static object toObject(array $array, string $class = 'stdClass')

Utility function to map an array to a stdClass object.

Parameters

array $array The array to map.
string $class Name of the class to create

Return Value

object The object mapped from the given array

at line line 195
static mixed getByPath(array $data, mixed $path, string $separator = '.')

Get data from array or object by path.

Example: StructureHelper::getByPath($array, 'foo.bar.yoo') equals to $array['foo']['bar']['yoo'].

Parameters

array $data An array or object to get value.
mixed $path The key path.
string $separator Separator of paths.

Return Value

mixed Found value, null if not exists.

at line line 241
static boolean setByPath(array $data, string $path, mixed $value, string $separator = '.')

setByPath

Parameters

array $data &$data
string $path
mixed $value
string $separator

Return Value

boolean

at line line 287
static array getPathNodes(string $path, string $separator = '.')

Explode the structure path into an array and remove empty nodes that occur as a result of a double dot. ex: windwalker.

.test Finally, re-key the array so they are sequential.

Parameters

string $path
string $separator

Return Value

array

at line line 301
static array flatten(array|object $array, string $separator = '.', string $prefix = '')

Method to recursively convert data to one dimension array.

Parameters

array|object $array The array or object to convert.
string $separator The key separator.
string $prefix Last level key prefix.

Return Value

array

at line line 339
static array toArray(mixed $data, bool $recursive = false)

Utility function to convert all types to an array.

Parameters

mixed $data The data to convert.
bool $recursive Recursive if data is nested.

Return Value

array The converted array.

at line line 376
static array dumpObjectValues(mixed $object)

dumpObjectValues

Parameters

mixed $object

Return Value

array