From 172da7553cba20eced70d4ec7e9532cc566b56c5 Mon Sep 17 00:00:00 2001 From: haszi Date: Sun, 17 Mar 2024 19:24:50 +0100 Subject: [PATCH] Add links to namespaced non-class constants (#111) Add links to namespaced non-class constants. Add namespaced non-class constants to tests. Co-authored-by: haszi --- phpdotnet/phd/Package/Generic/XHTML.php | 16 +++++++--------- tests/package/php/constant_links_001.phpt | 4 ++-- tests/package/php/data/constant_links.xml | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 284858bc..dc789933 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -1611,19 +1611,17 @@ public function format_constant($open, $name, $attrs) return ""; } 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); diff --git a/tests/package/php/constant_links_001.phpt b/tests/package/php/constant_links_001.phpt index 93380ad2..6e565248 100644 --- a/tests/package/php/constant_links_001.phpt +++ b/tests/package/php/constant_links_001.phpt @@ -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", ], [ @@ -58,7 +58,7 @@ Content:

%d. Existing constants

- DEFINITELY_EXISTS + Extension\Namespace\DEFINITELY_EXISTS

Vendor\Namespace::DEFINITELY_EXISTS2

diff --git a/tests/package/php/data/constant_links.xml b/tests/package/php/data/constant_links.xml index e5c9c643..eb13986b 100644 --- a/tests/package/php/data/constant_links.xml +++ b/tests/package/php/data/constant_links.xml @@ -3,7 +3,7 @@
1. Existing constants - DEFINITELY_EXISTS + Extension\Namespace\DEFINITELY_EXISTS Vendor\Namespace::DEFINITELY_EXISTS2