Skip to content

Commit

Permalink
Add links to namespaced non-class constants (#111)
Browse files Browse the repository at this point in the history
Add links to namespaced non-class constants.
Add namespaced non-class constants to tests.

Co-authored-by: haszi <[email protected]>
  • Loading branch information
haszi and haszi authored Mar 17, 2024
1 parent 89216bc commit 172da75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
16 changes: 7 additions & 9 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -1611,19 +1611,17 @@ public function format_constant($open, $name, $attrs)
return "</code></strong>";
}
public function format_constant_text($value, $tag) {
$tempLinkValue = str_replace(
array("\\", "_"),
array("-", "-"),
strtolower(trim($value, "_"))
);
if (str_contains($value, '::')) {
// class constant
list($extensionAndClass, $constant) = explode(
"::",
str_replace(
array("\\", "_"),
array("-", "-"),
strtolower($value)
)
);
list($extensionAndClass, $constant) = explode("::", $tempLinkValue);
$normalizedLinkFormat = $extensionAndClass . ".constants." . trim($constant, "-");
} else {
$normalizedLinkFormat = 'constant.' . str_replace('_', '-', strtolower(trim($value, "_")));
$normalizedLinkFormat = 'constant.' . $tempLinkValue;
}
$link = $this->createLink($normalizedLinkFormat);

Expand Down
4 changes: 2 additions & 2 deletions tests/package/php/constant_links_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Config::init(["xml_file" => $xml_file]);

$indices = [
[
"docbook_id" => "constant.definitely-exists",
"docbook_id" => "constant.extension-namespace-definitely-exists",
"filename" => "extensionname.constantspage",
],
[
Expand Down Expand Up @@ -58,7 +58,7 @@ Content:

<div class="section">
<p class="para">%d. Existing constants</p>
<strong><code><a href="extensionname.constantspage.html#constant.definitely-exists">DEFINITELY_EXISTS</a></code></strong>
<strong><code><a href="extensionname.constantspage.html#constant.extension-namespace-definitely-exists">Extension\Namespace\DEFINITELY_EXISTS</a></code></strong>
<p class="para">
<strong><code><a href="extensionname2.constantspage2.html#vendor-namespace.constants.definitely-exists2">Vendor\Namespace::DEFINITELY_EXISTS2</a></code></strong>
</p>
Expand Down
2 changes: 1 addition & 1 deletion tests/package/php/data/constant_links.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<section>
<para>1. Existing constants</para>
<constant>DEFINITELY_EXISTS</constant>
<constant>Extension\Namespace\DEFINITELY_EXISTS</constant>
<para>
<constant>Vendor\Namespace::DEFINITELY_EXISTS2</constant>
</para>
Expand Down

0 comments on commit 172da75

Please sign in to comment.