getName(), $ref->getDeprecated() ? "(DEP)" : ""); } private static function tab(int $depth) { return str_repeat("\t", $depth); } public static function href(string $ltxt, string $lurl, string $desc = null) { $desc = $desc ? sprintf(' "%s"', $desc) : null; return sprintf("[%s](%s%s)", $ltxt, str_replace("\\", "_", $lurl), $desc); } public static function toc(array $tree, int $depth) { $append = (function(string &$into, int $depth, int $idx, string $from) { $into .= sprintf("%s%d. %s\n", self::tab($depth), $idx + 1, $from); }); $str = ""; foreach ($tree as $key => $elem) { $append($str, $depth, $key, self::href(is_string($elem[1]) ? $elem[1] : self::dep($elem), sprintf("#%s", $elem[1]), $elem[1])); if (isset($elem[2]) && !empty($elem[2])) { $last = array(); $pos = 0; foreach($elem[2] as $key2 => $elem2) { if (isset($elem2[2]) && !empty($elem2[2])) $last[$key2] = $elem2; else $append($str, ($depth+1), $pos++, self::href(self::dep($elem2[1]), sprintf("#%s", $elem2[1]), $elem2[1])); } foreach($last as $key2 => $elem2) { $append($str, ($depth+1), $pos + $key2, self::href(is_string($elem2[1]) ? $elem2[1] : self::dep($elem2[1]), sprintf("#%s", $elem2[1]), $elem2[1])); $str .= self::toc($elem2[2], ($depth+2)); } } } return $str; } } use Sami\Sami; use Sami\RemoteRepository\GitHubRemoteRepository; use Sami\Version\GitVersionCollection; use Symfony\Component\Finder\Finder; $iterator = Finder::create() ->files() ->name('*.php') ->in($dir = './src') ; $versions = GitVersionCollection::create($dir) ->add('master', 'master branch') ; $s = new Sami($iterator, array( 'theme' => 'markdown', 'template_dirs' => array( __DIR__ . '/markdown'), 'versions' => $versions, 'title' => 'Symfony2 API', 'build_dir' => __DIR__.'/build/%version%', 'cache_dir' => __DIR__.'/cache/%version%', )); $s["twig"]->addExtension(new Markdown_Sami_Twig_Extension()); return $s; ?>