[DOC-CVS] [phd] master: Fix rendering of class method names inside packagesynopsis (#251)
[email protected] (Máté Kocsis via GitHub) Wed, 29 Apr 2026 08:03:33 +0000
| Newsgroups | php.doc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Máté Kocsis (kocsismate) Committer: GitHub (web-flow) Pusher: kocsismate Date: 2026-04-29T10:03:30+02:00 Commit: https://github.com/php/phd/commit/7dfd4f49a4b505faed5e718931324dd6fc2a789b Raw diff: https://github.com/php/phd/commit/7dfd4f49a4b505faed5e718931324dd6fc2a789b.diff Fix rendering of class method names inside packagesynopsis (#251) Co-authored-by: Gina Peter Banyard <[email protected]> Changed paths: M phpdotnet/phd/Package/Generic/XHTML.php M phpdotnet/phd/Package/PHP/XHTML.php M tests/package/php/data/packagesynopsis_rendering.xml M tests/package/php/packagesynopsis_rendering_001.phpt Diff: diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index e5cdaed5..b5ab2b90 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -467,6 +467,11 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { 'constant' => 'format_suppressed_text', ), /** Those are used to retrieve the class/interface name to be able to remove it from method names */ + 'package' => [ + /* DEFAULT */ false, + 'packagesynopsis' => 'format_packagesynopsis_package_text' + ], + /** Those are used to retrieve the class/interface name to be able to remove it from method names */ 'classname' => [ /* DEFAULT */ false, 'ooclass' => [ @@ -538,7 +543,10 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { protected $cchunk = array(); /* Default Chunk variables */ private $dchunk = array( - "packagesynopsis" => false, + "packagesynopsis" => [ + "open" => false, + "namespace" => '', + ], "classsynopsis" => [ "close" => false, "classname" => false, @@ -1257,7 +1265,7 @@ public function format_classsynopsis($open, $name, $attrs, $props) { /** Legacy presentation does not use the class attribute */ $this->cchunk["classsynopsis"]['legacy'] = !isset($attrs[Reader::XMLNS_DOCBOOK]["class"]); - $inPackageSynopsis = $this->cchunk["packagesynopsis"] ?? false; + $inPackageSynopsis = $this->cchunk["packagesynopsis"]["open"] ?? false; if ($this->cchunk["classsynopsis"]['legacy']) { if ($open) { @@ -1324,18 +1332,22 @@ public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag } list($class, $method) = explode($explode, $value); - if ($class !== $this->cchunk["classsynopsis"]["classname"]) { + $thisFqcn = $this->getFqcn(); + + if ($class !== $thisFqcn) { return $value; } + return $method; } public function format_packagesynopsis($open, $name, $attrs, $props) { + $this->cchunk["packagesynopsis"] = $this->dchunk["packagesynopsis"]; if ($open) { - $this->cchunk["packagesynopsis"] = true; + $this->cchunk["packagesynopsis"]["open"] = true; return '<div class="classsynopsis"><div class="classsynopsisinfo">'; } - $this->cchunk["packagesynopsis"] = false; + $this->cchunk["packagesynopsis"]["open"] = false; return '</div>'; } @@ -1346,8 +1358,16 @@ public function format_packagesynopsis_package($open, $name, $attrs, $props) { return '</strong>;</div>'; } + public function format_packagesynopsis_package_text($value, $tag) { + if (!$this->cchunk["packagesynopsis"]["namespace"]) { + $this->cchunk["packagesynopsis"]["namespace"] = $value; + } + + return $this->TEXT($value); + } + public function format_enumsynopsis($open, $name, $attrs, $props) { - $inPackageSynopsis = $this->cchunk["packagesynopsis"] ?? false; + $inPackageSynopsis = $this->cchunk["packagesynopsis"]["open"] ?? false; if ($open) { if ($inPackageSynopsis) { return '<div class="classsynopsisinfo">'; @@ -2683,4 +2703,14 @@ public function onNewPage(): void { $this->perPageExampleCounter = 0; } + + protected function getFqcn() { + $fqcn = ""; + + if ($this->cchunk["packagesynopsis"]["namespace"]) { + $fqcn = $this->cchunk["packagesynopsis"]["namespace"] . "\\"; + } + + return $fqcn . $this->cchunk["classsynopsis"]["classname"]; + } } diff --git a/phpdotnet/phd/Package/PHP/XHTML.php b/phpdotnet/phd/Package/PHP/XHTML.php index fce9f6f7..a50b1b23 100644 --- a/phpdotnet/phd/Package/PHP/XHTML.php +++ b/phpdotnet/phd/Package/PHP/XHTML.php @@ -807,7 +807,7 @@ public function format_acronym_text($value, $tag) { public function format_classsynopsis_fieldsynopsis_varname_text($value, $tag) { if ($this->cchunk["classsynopsis"]["classname"]) { if (strpos($value, "::") === false && strpos($value, "->") === false) { - $value = $this->cchunk["classsynopsis"]["classname"] . "->" . $value; + $value = $this->getFqcn() . "->" . $value; } } @@ -817,7 +817,7 @@ public function format_classsynopsis_fieldsynopsis_varname_text($value, $tag) { public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag) { if ($this->cchunk["classsynopsis"]["classname"]) { if (strpos($value, "::") === false && strpos($value, "->") === false) { - $value = $this->cchunk["classsynopsis"]["classname"] . "::" . $value; + $value = $this->getFqcn() . "::" . $value; } } diff --git a/tests/package/php/data/packagesynopsis_rendering.xml b/tests/package/php/data/packagesynopsis_rendering.xml index 1cd3013a..e0e37a82 100644 --- a/tests/package/php/data/packagesynopsis_rendering.xml +++ b/tests/package/php/data/packagesynopsis_rendering.xml @@ -15,6 +15,17 @@ <modifier>implements</modifier> <interfacename>Stringable</interfacename> </oointerface> + + <fieldsynopsis> + <modifier>public</modifier> + <type>int</type> + <varname linkend="bcmath-number.props.scale">scale</varname> + </fieldsynopsis> + + <methodsynopsis xmlns="http://docbook.org/ns/docbook" role="BcMath\\Number"> + <modifier>public</modifier> <type>BcMath\Number</type><methodname>BcMath\Number::floor</methodname> + <void/> + </methodsynopsis> </classsynopsis> </packagesynopsis> </section> diff --git a/tests/package/php/packagesynopsis_rendering_001.phpt b/tests/package/php/packagesynopsis_rendering_001.phpt index ba011850..6e8ba6b5 100644 --- a/tests/package/php/packagesynopsis_rendering_001.phpt +++ b/tests/package/php/packagesynopsis_rendering_001.phpt @@ -34,6 +34,16 @@ Content: <span class="modifier">implements</span> <strong class="interfacename">Stringable</strong> {</div> + + <div class="fieldsynopsis"> + <span class="modifier">public</span> + <span class="type"><a href="language.types.integer.html" class="type int">int</a></span> + <var class="varname"><a href=".html#bcmath-number.props.scale">$<var class="varname">scale</var></a></var>;</div> + + + <div class="methodsynopsis dc-description"> + <span class="modifier">public</span> <span class="methodname"><strong>floor</strong></span>(): <span class="type">BcMath\Number</span></div> + } </div> </div>