Skip to content

Commit 7dfd4f4

Browse files
kocsismateGirgias
andauthored
Fix rendering of class method names inside packagesynopsis (#251)
Co-authored-by: Gina Peter Banyard <girgias@php.net>
1 parent e546e7b commit 7dfd4f4

4 files changed

Lines changed: 59 additions & 8 deletions

File tree

phpdotnet/phd/Package/Generic/XHTML.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML {
467467
'constant' => 'format_suppressed_text',
468468
),
469469
/** Those are used to retrieve the class/interface name to be able to remove it from method names */
470+
'package' => [
471+
/* DEFAULT */ false,
472+
'packagesynopsis' => 'format_packagesynopsis_package_text'
473+
],
474+
/** Those are used to retrieve the class/interface name to be able to remove it from method names */
470475
'classname' => [
471476
/* DEFAULT */ false,
472477
'ooclass' => [
@@ -538,7 +543,10 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML {
538543
protected $cchunk = array();
539544
/* Default Chunk variables */
540545
private $dchunk = array(
541-
"packagesynopsis" => false,
546+
"packagesynopsis" => [
547+
"open" => false,
548+
"namespace" => '',
549+
],
542550
"classsynopsis" => [
543551
"close" => false,
544552
"classname" => false,
@@ -1257,7 +1265,7 @@ public function format_classsynopsis($open, $name, $attrs, $props) {
12571265
/** Legacy presentation does not use the class attribute */
12581266
$this->cchunk["classsynopsis"]['legacy'] = !isset($attrs[Reader::XMLNS_DOCBOOK]["class"]);
12591267

1260-
$inPackageSynopsis = $this->cchunk["packagesynopsis"] ?? false;
1268+
$inPackageSynopsis = $this->cchunk["packagesynopsis"]["open"] ?? false;
12611269

12621270
if ($this->cchunk["classsynopsis"]['legacy']) {
12631271
if ($open) {
@@ -1324,18 +1332,22 @@ public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag
13241332
}
13251333

13261334
list($class, $method) = explode($explode, $value);
1327-
if ($class !== $this->cchunk["classsynopsis"]["classname"]) {
1335+
$thisFqcn = $this->getFqcn();
1336+
1337+
if ($class !== $thisFqcn) {
13281338
return $value;
13291339
}
1340+
13301341
return $method;
13311342
}
13321343

13331344
public function format_packagesynopsis($open, $name, $attrs, $props) {
1345+
$this->cchunk["packagesynopsis"] = $this->dchunk["packagesynopsis"];
13341346
if ($open) {
1335-
$this->cchunk["packagesynopsis"] = true;
1347+
$this->cchunk["packagesynopsis"]["open"] = true;
13361348
return '<div class="classsynopsis"><div class="classsynopsisinfo">';
13371349
}
1338-
$this->cchunk["packagesynopsis"] = false;
1350+
$this->cchunk["packagesynopsis"]["open"] = false;
13391351
return '</div>';
13401352
}
13411353

@@ -1346,8 +1358,16 @@ public function format_packagesynopsis_package($open, $name, $attrs, $props) {
13461358
return '</strong>;</div>';
13471359
}
13481360

1361+
public function format_packagesynopsis_package_text($value, $tag) {
1362+
if (!$this->cchunk["packagesynopsis"]["namespace"]) {
1363+
$this->cchunk["packagesynopsis"]["namespace"] = $value;
1364+
}
1365+
1366+
return $this->TEXT($value);
1367+
}
1368+
13491369
public function format_enumsynopsis($open, $name, $attrs, $props) {
1350-
$inPackageSynopsis = $this->cchunk["packagesynopsis"] ?? false;
1370+
$inPackageSynopsis = $this->cchunk["packagesynopsis"]["open"] ?? false;
13511371
if ($open) {
13521372
if ($inPackageSynopsis) {
13531373
return '<div class="classsynopsisinfo">';
@@ -2683,4 +2703,14 @@ public function onNewPage(): void
26832703
{
26842704
$this->perPageExampleCounter = 0;
26852705
}
2706+
2707+
protected function getFqcn() {
2708+
$fqcn = "";
2709+
2710+
if ($this->cchunk["packagesynopsis"]["namespace"]) {
2711+
$fqcn = $this->cchunk["packagesynopsis"]["namespace"] . "\\";
2712+
}
2713+
2714+
return $fqcn . $this->cchunk["classsynopsis"]["classname"];
2715+
}
26862716
}

phpdotnet/phd/Package/PHP/XHTML.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ public function format_acronym_text($value, $tag) {
807807
public function format_classsynopsis_fieldsynopsis_varname_text($value, $tag) {
808808
if ($this->cchunk["classsynopsis"]["classname"]) {
809809
if (strpos($value, "::") === false && strpos($value, "->") === false) {
810-
$value = $this->cchunk["classsynopsis"]["classname"] . "->" . $value;
810+
$value = $this->getFqcn() . "->" . $value;
811811
}
812812
}
813813

@@ -817,7 +817,7 @@ public function format_classsynopsis_fieldsynopsis_varname_text($value, $tag) {
817817
public function format_classsynopsis_methodsynopsis_methodname_text($value, $tag) {
818818
if ($this->cchunk["classsynopsis"]["classname"]) {
819819
if (strpos($value, "::") === false && strpos($value, "->") === false) {
820-
$value = $this->cchunk["classsynopsis"]["classname"] . "::" . $value;
820+
$value = $this->getFqcn() . "::" . $value;
821821
}
822822
}
823823

tests/package/php/data/packagesynopsis_rendering.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
<modifier>implements</modifier>
1616
<interfacename>Stringable</interfacename>
1717
</oointerface>
18+
19+
<fieldsynopsis>
20+
<modifier>public</modifier>
21+
<type>int</type>
22+
<varname linkend="bcmath-number.props.scale">scale</varname>
23+
</fieldsynopsis>
24+
25+
<methodsynopsis xmlns="http://docbook.org/ns/docbook" role="BcMath\\Number">
26+
<modifier>public</modifier> <type>BcMath\Number</type><methodname>BcMath\Number::floor</methodname>
27+
<void/>
28+
</methodsynopsis>
1829
</classsynopsis>
1930
</packagesynopsis>
2031
</section>

tests/package/php/packagesynopsis_rendering_001.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ Content:
3434

3535
<span class="modifier">implements</span>
3636
<strong class="interfacename">Stringable</strong> {</div>
37+
38+
<div class="fieldsynopsis">
39+
<span class="modifier">public</span>
40+
<span class="type"><a href="language.types.integer.html" class="type int">int</a></span>
41+
<var class="varname"><a href=".html#bcmath-number.props.scale">$<var class="varname">scale</var></a></var>;</div>
42+
43+
44+
<div class="methodsynopsis dc-description">
45+
<span class="modifier">public</span> <span class="methodname"><strong>floor</strong></span>(): <span class="type">BcMath\Number</span></div>
46+
3747
}
3848
</div>
3949
</div>

0 commit comments

Comments
 (0)