diff --git a/src/Indexer.php b/src/Indexer.php index d6b9ae44..713f9145 100644 --- a/src/Indexer.php +++ b/src/Indexer.php @@ -18,6 +18,7 @@ class Indexer private const TYPE_CLASS = 1; private const TYPE_METHOD = 2; private const TYPE_NAMESPACE = 3; + private const TYPE_FUNCTION = 4; public function getIndex(Project $project) { @@ -43,6 +44,11 @@ public function getIndex(Project $project) } } + foreach ($project->getProjectFunctions() as $function) { + $index['searchIndex'][] = $this->getSearchString((string) $function); + $index['info'][] = [self::TYPE_FUNCTION, $function]; + } + return $index; } diff --git a/src/Renderer/Renderer.php b/src/Renderer/Renderer.php index 237de01d..be2b6007 100644 --- a/src/Renderer/Renderer.php +++ b/src/Renderer/Renderer.php @@ -120,6 +120,7 @@ protected function renderGlobalTemplates(Project $project, $callback = null) 'namespaces' => $project->getNamespaces(), 'interfaces' => $project->getProjectInterfaces(), 'classes' => $project->getProjectClasses(), + 'functions' => $project->getProjectFunctions(), 'items' => $this->getIndex($project), 'index' => $this->indexer->getIndex($project), 'tree' => $this->getTree($project), diff --git a/src/Renderer/TwigExtension.php b/src/Renderer/TwigExtension.php index 1c6a2756..f575ff37 100644 --- a/src/Renderer/TwigExtension.php +++ b/src/Renderer/TwigExtension.php @@ -76,9 +76,10 @@ public function setCurrentDepth(int $depth): void $this->currentDepth = $depth; } - public function pathForFunction(array $context, string $function): string + public function pathForFunction(array $context, FunctionReflection $function): string { - return $this->relativeUri($this->currentDepth) . '#function_' . str_replace('\\', '', $function); + $namespace = $this->pathForNamespace($context, $function->getNamespace()); + return $this->relativeUri($this->currentDepth) . $namespace . '#function_' . str_replace('\\', '', $function->getName()); } public function pathForClass(array $context, string $class): string diff --git a/src/Resources/themes/default/doctum.js.twig b/src/Resources/themes/default/doctum.js.twig index 94360cd4..148f805a 100644 --- a/src/Resources/themes/default/doctum.js.twig +++ b/src/Resources/themes/default/doctum.js.twig @@ -90,6 +90,16 @@ -}}, {{ add_class_methods_index(class, prettyJsonOptions) }} {% endfor %} + {% for function in functions -%} + {{- + { + type: 'Function'|trans, + link: function_path(function), + name: function.__toString(), + doc: function.shortdesc|desc(function)|md_to_html, + }|json_encode(prettyJsonOptions)|raw + -}}, + {% endfor %} {# Override this block, search_index_extra, to add custom search entries! #} {% block search_index_extra '' %} // Fix trailing commas in the index