private function doVisit($path, $value, $when)
    {
        foreach ($this->visitors as $visitor) {
            if ($visitor[0] === $when && call_user_func($visitor[1], $path, $value)) {
                try {
                    $value = call_user_func($visitor[2], $path, $value);
                } catch (\Exception $e) {
                    if ($path) {
                        $path = join('.', $path);
                    }
                    $path = json_encode($path);
                    $value = json_encode($value);
                    throw new \RuntimeException("While visiting value '{$value}' at path {$path}", 0, $e);
                }
            }
        }
        return $value;
    }