diff --git a/phpdotnet/phd/Package/PHP/XHTML.php b/phpdotnet/phd/Package/PHP/XHTML.php index c185336a..6d8a4bec 100644 --- a/phpdotnet/phd/Package/PHP/XHTML.php +++ b/phpdotnet/phd/Package/PHP/XHTML.php @@ -125,6 +125,10 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML { 'classsynopsis' => 'format_classsynopsis_oo_name_text', ] ], + 'enumidentifier' => [ + /* DEFAULT */ 'format_enumidentifier_text', + 'enumsynopsis' => false, + ], 'methodname' => array( /* DEFAULT */ 'format_function_text', 'constructorsynopsis' => array( @@ -898,6 +902,25 @@ public function format_classname_text($value, $tag) { return '' .$value. ''; } + public function format_enumidentifier_text($value, $tag) { + if (!str_contains($value, '::')) { + return $value; + } + + list($enumName) = explode('::', $value); + $t = strtr($this->normalizeFQN($enumName), ["_" => "-", "\\" => "-"]); + $href = Format::getFilename("enum.$t"); + + if ($href === false) { + return $value; + } + + if ($this->chunked) { + return '' . $value . ''; + } + return '' . $value . ''; + } + /*Chunk Functions*/ private function isChunkedByAttributes(array $attributes): bool { diff --git a/tests/package/php/data/enumidentifier_link_rendering.xml b/tests/package/php/data/enumidentifier_link_rendering.xml new file mode 100644 index 00000000..c628be9a --- /dev/null +++ b/tests/package/php/data/enumidentifier_link_rendering.xml @@ -0,0 +1,34 @@ + + + +
+ 1. Enum case inside enumsynopsis (no link - definition context) + + TestEnum + + CaseDefinition + + +
+ +
+ 2. Enum case reference with FQN (linked) + Enum\Namespace\Existing_Enum::SomeCase +
+ +
+ 3. Enum case reference with FQN and leading backslash (linked) + \Enum\Namespace\Existing_Enum::AnotherCase +
+ +
+ 4. Enum case without namespace separator (no link) + JustCaseName +
+ +
+ 5. Enum case for non-existent enum (no link) + NonExistent\Enum::SomeCase +
+ +
diff --git a/tests/package/php/enumidentifier_link_rendering.phpt b/tests/package/php/enumidentifier_link_rendering.phpt new file mode 100644 index 00000000..96268f84 --- /dev/null +++ b/tests/package/php/enumidentifier_link_rendering.phpt @@ -0,0 +1,64 @@ +--TEST-- +Enum case (enumidentifier) link rendering +--FILE-- +xmlFile = __DIR__ . "/data/enumidentifier_link_rendering.xml"; + +$format = new TestPHPChunkedXHTML($config, $outputHandler); +$format->SQLiteIndex( + null, // $context, + null, // $index, + "enum.enum-namespace-existing-enum", // $id, + "enum.enum-namespace-existing-enum", // $filename, + "", // $parent, + "", // $sdesc, + "", // $ldesc, + "phpdoc:classref", // $element, + "", // $previous, + "", // $next, + 0, // $chunk +); + +$render = new TestRender(new Reader($outputHandler), $config, $format); +$render->run(); +?> +--EXPECT-- +Filename: enumidentifier_link_rendering.html +Content: +