/** * Creates an index of classes and namespaces. * * I'm generating the actual markdown output here, which isn't great.. but * it will have to do. If I don't want to make things too complicated. * * @return array */ protected function createIndex() { $tree = array(); foreach ($this->classDefinitions as $className => $classInfo) { $current =& $tree; foreach (explode('\\', $className) as $part) { if (!isset($current[$part])) { $current[$part] = array(); } $current =& $current[$part]; } } $treeOutput = ''; $treeOutput = function ($item, $fullString = '', $depth = 0) use(&$treeOutput) { $output = ''; foreach ($item as $name => $subItems) { $fullName = $fullString ? $fullString . "\\" . $name : $name; $output .= str_repeat(' ', $depth * 4) . '* ' . Generator::classLink($fullName, $name) . "\n"; $output .= $treeOutput($subItems, $fullName, $depth + 1); } return $output; }; return $treeOutput($tree); }
/** * Creates an index of classes and namespaces. * * I'm generating the actual markdown output here, which isn't great...But it will have to do. * If I don't want to make things too complicated. * * @return array */ protected function createIndex() { $tree = array(); foreach ($this->classDefinitions as $className => $classInfo) { $current =& $tree; foreach (explode('\\', $className) as $part) { if (!isset($current[$part])) { $current[$part] = array(); } $current =& $current[$part]; } } /** * This will be a reference to the $treeOutput closure, so that it can be invoked * recursively. A string is used to trick static analysers into thinking this might be * callable. */ $treeOutput = ''; $treeOutput = function ($item, $fullString = '', $depth = 0) use(&$treeOutput) { $output = ''; foreach ($item as $name => $subItems) { $fullName = $name; if ($fullString) { $fullName = $fullString . '\\' . $name; } $output .= str_repeat(' ', $depth * 4) . '* ' . Generator::classLink($fullName, $name) . "\n"; $output .= $treeOutput($subItems, $fullName, $depth + 1); } return $output; }; return $treeOutput($tree); }