Show:

Q_Tree Class

Module: Q

Used to hold arbitrary-dimensional lists of parameters in Q

Constructor

Q_Tree

(
  • [$linked_array=null]
)

Parameters:

  • [$linked_array=null] &array optional

Methods

breadthFirst

(
  • $callback
  • [$context=null]
)

Traverse the tree breadth-first and call the callback

Parameters:

  • $callback Callable

    Will receive ($path, $value, $array, $context)

  • [$context=null] Mixed optional

    To propagate some context to the callback

clear

(
  • $key1
  • $key2
)

Clears the value of a field, possibly deep inside the array

Parameters:

  • $key1 String

    The name of the first key in the configuration path

  • $key2 String

    Optional. The name of the second key in the configuration path. You can actually pass as many keys as you need, delving deeper and deeper into the configuration structure. All but the second-to-last parameter are interpreted as keys.

depthFirst

(
  • $callback
  • [$context=null]
)

Traverse the tree depth-first and call the callback

Parameters:

  • $callback Callable

    Will receive ($path, $value, $array, $context)

  • [$context=null] Mixed optional

    To propagate some context to the callback

diff

(
  • $tree
)
Q_Tree

Calculates a diff between this tree and another tree

Parameters:

Returns:

Q_Tree:

This tree holds the results of the diff

expect

(
  • $key1
  • $key2
)
Mixed static

Gets the value of a field in the tree. If it is null or not set, throws an exception. Otherwise, it is guaranteed to return a non-null value.

Parameters:

  • $key1 String

    The name of the first key in the tree path

  • $key2 String

    Optional. The name of the second key in the tree path. You can actually pass as many keys as you need, delving deeper and deeper into the expect structure. All but the second-to-last parameter are interpreted as keys.

Returns:

Mixed:

Only returns non-null values

get

(
  • $key1
  • $key2
  • $default
)
Mixed

Gets the value of a field, possibly deep inside the array

Parameters:

  • $key1 String

    The name of the first key in the configuration path

  • $key2 String

    Optional. The name of the second key in the configuration path. You can actually pass as many keys as you need, delving deeper and deeper into the configuration structure. If more than one argument is passed, but the last argument are interpreted as keys.

  • $default Mixed

    If only one argument is passed, the default is null Otherwise, the last argument is the default value to return in case the requested field was not found.

Returns:

Mixed:

getAll

() Array

Gets the array of all parameters

Returns:

Array:

load

(
  • $filename
  • $ignoreCache=false
)
Boolean

Loads data from JSON found in a file

Parameters:

  • $filename String

    The filename of the file to load.

  • $ignoreCache=false Boolean

    Defaults to false. If true, then this function ignores the cached value, if any, and attempts to search for the file. It will cache the new value.

Returns:

Boolean:

Returns true if loaded, otherwise false.

merge

(
  • $second
)
Boolean

Merges trees over the top of existing trees

Parameters:

  • $second Array | Q_Tree

    The array or Q_Tree to merge on top of the existing one

Returns:

Boolean:

save

(
  • $filename
  • [$array_path=array()]
  • [$flags=0]
)
Boolean

Saves parameters to a file

Parameters:

  • $filename String

    Name of file to save to. If tree was loaded, you can leave this blank to update that file.

  • [$array_path=array()] Array optional

    Array of keys identifying the path of the config subtree to save

  • [$flags=0] Integer optional

    Any additional flags for json_encode, such as JSON_PRETTY_PRINT

Returns:

Boolean:

Returns true if saved, otherwise false;

set

(
  • $key1
  • $key2
  • [$value=null]
)

Sets the value of a field, possibly deep inside the array

Parameters:

  • $key1 String

    The name of the first key in the configuration path

  • $key2 String

    Optional. The name of the second key in the configuration path. You can actually pass as many keys as you need, delving deeper and deeper into the configuration structure. All but the second-to-last parameter are interpreted as keys.

  • [$value=null] Mixed optional

    The value to set the field to. The last parameter should not be omitted unless the first parameter is an array.

Properties

$cache

Array protected static

$parameters

Array protected

array options

Unknown

Events

Q/tree/load

Before

Event Payload:

  • filename String