Jet\Data_Forest
Sometimes one tree is not enough and you need a whole forest :-) Why spend a little ...
Seriously. Now and then you need to export several trees at once (of course trees related to each other and similar). Or you need to use several trees as selection options. For example, a good example is the selection of allowed operations in the authorization roles management (if you want to see a specific usage, look for example in the JetApplication\Auth_Administrator_Role class in the sample application).
Simply put, Jet\Data_Forest is used to combine related trees into a single unit that can be browsed and exported at once, just as it is possible with individual trees.
WARNING! Each tree must be identified somehow. The identifier of the tree is the identifier of its root node. It is therefore necessary that each tree in the forest has its own unique root node identifier.
Method Overview
Method | Meaning of |
---|---|
public appendTree( Data_Tree $tree ) : void |
Adds a tree to the forest. The tree must not yet be in the forest (otherwise an exception is thrown). |
public getTrees( ) : Data_Tree[] |
It'll bring back all the storms that are in the forest. |
public getTree( string $tree_id ) : Data_Tree |
Returns a tree based on an identifier (tree identifier: see above) |
public removeTree( string $tree_id ) : void |
Deletes a tree based on an identifier (tree identifier: see above) |
public getTreeExists( string $tree_id ) : bool |
Finds out if a given tree is in the forest based on an identifier (tree identifier: see above) |
public toArray( int|null $max_depth=null ) : array |
Quite identically to tree, the forest can be exported as an array. |
public toJSON( ) : string |
Identical to tree, the forest can be exported to JSON format |
public jsonSerialize( ) : array |
Quite identical to tree, it is also possible to export the forest to JSON format. This method is used by the json_encode function. |
public current( ) : Data_Tree_Node |
See PHP Iterator Just as a foreach can be used to traverse an entire tree, or a branch of it, so can a lest. The order of the trees is then determined by the order in which they are added. |
public key( ) : string |
|
public next( ) : void |
|
public valid( ) : bool |
|
public rewind( ) : void |
|
public count( ) : int |
See PHP Countable |