1<?php
2
3namespace ComboStrap;
4
5
6class TreeVisit
7{
8
9    public static function visit(TreeNode $tree, Callable $function, int $level = 0)
10    {
11        call_user_func($function, $tree, $level);
12        if ($tree->hasChildren()) {
13            $childLevel = $level + 1;
14            foreach ($tree->getChildren() as $child) {
15                self::visit($child, $function, $childLevel);
16            }
17        }
18
19    }
20
21}
22