Skip to content

Commit 8ff5ea7

Browse files
committed
Use qualified name for namespace links in overview tree. Show full project namespace in nav tree.
1 parent 55f9b21 commit 8ff5ea7

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

src/Project.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(string $projectPath, array $config)
5656
$this->setConfig($config);
5757

5858
foreach ((array)$this->_config['namespaces'] as $namespace) {
59-
$this->namespaces[$namespace] = new ProjectNamespace($namespace);
59+
$this->namespaces[$namespace] = new ProjectNamespace($namespace, $namespace);
6060
}
6161

6262
$this->loader = new Loader($projectPath);
@@ -196,7 +196,7 @@ protected function createClassLoader(string $projectPath): ?ClassLoader
196196
protected function getNamespace(?string $qualifiedName): ProjectNamespace
197197
{
198198
if ($qualifiedName === null) {
199-
return $this->namespaces[''] ??= new ProjectNamespace(null);
199+
return $this->namespaces[''] ??= new ProjectNamespace('Global', null);
200200
}
201201

202202
$namespace = null;
@@ -222,7 +222,8 @@ protected function getNamespace(?string $qualifiedName): ProjectNamespace
222222
continue;
223223
}
224224

225-
$child = $namespace->children[$name] = new ProjectNamespace($namespace->qualifiedName . '\\' . $name);
225+
$child = new ProjectNamespace($name, $namespace->qualifiedName . '\\' . $name);
226+
$namespace->children[$name] = $child;
226227
ksort($namespace->children);
227228

228229
$namespace = $child;

src/ProjectNamespace.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,12 @@ class ProjectNamespace
6262
public array $traits = [];
6363

6464
/**
65+
* @param string $name Display name
6566
* @param string|null $qualifiedName Qualified name
6667
*/
67-
public function __construct(?string $qualifiedName)
68+
public function __construct(string $name, ?string $qualifiedName)
6869
{
69-
if (!$qualifiedName) {
70-
$this->name = $qualifiedName ?: 'Global';
71-
} else {
72-
$lastSlash = strrpos($qualifiedName, '\\');
73-
$this->name = substr($qualifiedName, $lastSlash + 1);
74-
}
70+
$this->name = $name;
7571
$this->qualifiedName = $qualifiedName;
7672
}
7773

templates/pages/namespace.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% extends 'page.twig' %}
22

3-
{% block title 'Namespace ' ~ namespace.name|default(namespace.name) %}
3+
{% block title 'Namespace ' ~ namespace.qualifiedName|default(namespace.name) %}
44

55
{% block content %}
66
<div class="section namespace">
@@ -12,7 +12,7 @@
1212
<ul class="summary-list">
1313
{% for child in namespace.children %}
1414
<li>
15-
<a href="{{ child.qualifiedName|namespace_to_url }}">{{ child.qualifiedName ?? child.name }}</a>
15+
<a href="{{ child.qualifiedName|namespace_to_url }}">{{ child.qualifiedName|default(child.name) }}</a>
1616
</li>
1717
{% endfor %}
1818
</ul>

templates/pages/overview.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<ul>
1111
{% macro showNamespace(namespace) %}
1212
<li>
13-
<a href="{{ namespace.name|namespace_to_url }}">{{ namespace.name|default(namespace.name) }}</a>
13+
<a href="{{ namespace.qualifiedName|namespace_to_url }}">{{ namespace.qualifiedName|default(namespace.name) }}</a>
1414
<ul>
1515
{% for child in namespace.children %}
1616
{{ _self.showNamespace(child) }}

0 commit comments

Comments
 (0)