+
+ // search for missing namespace (the given name is a leaf)
+ $leaf = array_shift($p);
+ $args = count($p) ? '/' . implode('/', $p) : '';
+ if (isset($leafs[$leaf]) && !is_array($leafs[$leaf]) && $leafs[$leaf] != $this->path) {
+ return $leafs[$leaf] . $args;
+ }
+ unset($val);
+ $best = null;
+ foreach ($leafs as $k=>&$path) {
+ if (is_array($path)) {
+ continue;
+ }
+ $lev = levenshtein($leaf, $k);
+
+ if ((!isset($val) || $lev < $val)
+ && ($lev <= strlen($k)/2 || strpos($k, $leaf) !== false || strpos($leaf, $k) !== false)) {
+ $val = $lev;
+ $best = $path;
+ }
+ }
+ return $best == null ? ( $link ? $link : null ) : $best . $args;