本文整理汇总了PHP中tree::addChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP tree::addChildren方法的具体用法?PHP tree::addChildren怎么用?PHP tree::addChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree
的用法示例。
在下文中一共展示了tree::addChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_children_from
private function get_children_from($tokens, $start, $end, $parent_node, &$last_node = null, $foroutput = false)
{
$branch_points = array('T_IF', 'T_FOR', 'T_FOREACH', 'T_WHILE', 'T_SWITCH', 'T_DO', 'T_BOOLEAN_OR', 'T_BOOLEAN_AND');
$tp = $start;
$tree = new tree();
$current_node_id = $parent_node;
$this->break_nodes = $this->return_nodes = $this->continue_nodes = array();
while ($tp < $end) {
$token_name = $this->token_name($tokens[$tp]);
if ($token_name == 'T_FUNCTION') {
if ($blockstart = $this->search_token($tokens, $tp, '{', array(';'))) {
if ($tp = $this->get_pair($tokens, $blockstart)) {
$tp++;
continue;
}
}
} elseif ($token_name == 'T_BREAK') {
$level = $this->get_break_level($tokens, $tp);
$break_target = $this->break_levels[count($this->break_levels) - $level];
$this->jumps[$break_target][] = $current_node_id;
$this->break_nodes[] = $current_node_id;
} elseif ($token_name == 'T_CONTINUE') {
$this->continue_nodes[] = $current_node_id;
} elseif ($token_name == 'T_RETURN' || $token_name == 'T_THROW') {
$this->return_nodes[] = $current_node_id;
} elseif (in_array($token_name, $branch_points)) {
if ($token_name == 'T_SWITCH') {
/*
$trace = debug_backtrace(false);
foreach ($trace as $t) var_dump($t['function']);
*/
$node_children = $this->get_children_from_switch($tokens, $tp, $current_node_id, $current_node_id, $foroutput);
$tree->addChildren($node_children);
} elseif (in_array($token_name, array('T_IF'))) {
$temp = $current_node_id;
$node_children = $this->get_children_from_if($tokens, $tp, $current_node_id, $current_node_id, $foroutput);
$tree->addChildren($node_children);
} elseif ($token_name == 'T_DO') {
if ($node_children = $this->get_children_from_do($tokens, $tp, $current_node_id, $current_node_id, $foroutput)) {
$tree->addChildren($node_children);
}
} elseif (in_array($token_name, array('T_BOOLEAN_AND', 'T_BOOLEAN_OR'))) {
$boolright = $this->get_right_of_boolean($tokens, $tp);
if ($node_children = $this->get_children_from_boolean($tokens, $tp, $boolright, $current_node_id, $current_node_id, $current_node_id, $foroutput)) {
$tree->addChildren($node_children);
}
} else {
if ($node_children = $this->get_children_from_loop($tokens, $tp, $current_node_id, $current_node_id, $foroutput)) {
$tree->addChildren($node_children);
}
}
}
$tp++;
}
$last_node = $current_node_id;
return $tree;
}