phprs\util\Tree::visitNode PHP Method

visitNode() private method

遍历路径
private visitNode ( array $path, $vistor, boolean $exact_match = false, boolean $all_req_paths = false ) : boolean
$path array
$exact_match boolean 是否精确匹配,如果是,则通配符被认为与其他值不同
$all_req_paths boolean 是否要求查询路径的所有元素都必须遍历到
return boolean 变量完成返回true,遍历未完成时终止返回false
    private function visitNode($path, $vistor, $exact_match = false, $all_req_paths = false)
    {
        assert(count($path));
        $pos =& $this->arr;
        $next =& $pos;
        foreach ($path as $i) {
            if (is_null($next)) {
                return !$all_req_paths;
            }
            if (!array_key_exists($i, $next)) {
                if ($exact_match) {
                    return false;
                }
                if ($i == self::$end) {
                    return false;
                }
                //不要求完全匹配, 尝试匹配通配符
                if (!array_key_exists(self::$wildcard, $next)) {
                    return false;
                }
                $pos =& $next[self::$wildcard];
            } else {
                $pos =& $next[$i];
            }
            if (!$vistor($i, $pos)) {
                return false;
            }
            if (array_key_exists('next', $pos)) {
                $next =& $pos['next'];
            } else {
                $nul = null;
                $next =& $nul;
                //$next = null 会导致引用的对象被赋值,而不是next被赋值
            }
        }
        return true;
    }