Q_Tree Class
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
CallableWill receive ($path, $value, $array, $context)
-
[$context=null]
Mixed optionalTo propagate some context to the callback
clear
-
$key1
-
$key2
Clears the value of a field, possibly deep inside the array
Parameters:
-
$key1
StringThe name of the first key in the configuration path
-
$key2
StringOptional. 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
CallableWill receive ($path, $value, $array, $context)
-
[$context=null]
Mixed optionalTo propagate some context to the callback
diff
-
$tree
Calculates a diff between this tree and another tree
Parameters:
-
$tree
Q_Tree
Returns:
This tree holds the results of the diff
expect
-
$key1
-
$key2
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
StringThe name of the first key in the tree path
-
$key2
StringOptional. 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:
Only returns non-null values
get
-
$key1
-
$key2
-
$default
Gets the value of a field, possibly deep inside the array
Parameters:
-
$key1
StringThe name of the first key in the configuration path
-
$key2
StringOptional. 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
MixedIf 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:
getAll
()
Array
Gets the array of all parameters
Returns:
load
-
$filename
-
$ignoreCache=false
Loads data from JSON found in a file
Parameters:
-
$filename
StringThe filename of the file to load.
-
$ignoreCache=false
BooleanDefaults 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:
Returns true if loaded, otherwise false.
merge
-
$second
Merges trees over the top of existing trees
Parameters:
-
$second
Array | Q_TreeThe array or Q_Tree to merge on top of the existing one
Returns:
save
-
$filename
-
[$array_path=array()]
-
[$flags=0]
Saves parameters to a file
Parameters:
-
$filename
StringName of file to save to. If tree was loaded, you can leave this blank to update that file.
-
[$array_path=array()]
Array optionalArray of keys identifying the path of the config subtree to save
-
[$flags=0]
Integer optionalAny additional flags for json_encode, such as JSON_PRETTY_PRINT
Returns:
Returns true if saved, otherwise false;
set
-
$key1
-
$key2
-
[$value=null]
Sets the value of a field, possibly deep inside the array
Parameters:
-
$key1
StringThe name of the first key in the configuration path
-
$key2
StringOptional. 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 optionalThe 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