Skip to content

Commit 094794e

Browse files
committed
Support rendering intersection types
As of PHP 8.1.0, intersection types are supported, so we already prepare PhD for rendering respective types. Since for now only pure union and intersection types are supported, we don't handle complex cases, although these are allowed by our DocBook DTD. Closes GH-47.
1 parent ff4a1c5 commit 094794e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

phpdotnet/phd/Package/PHP/XHTML.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,12 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
155155
"refsynopsisdiv" => null,
156156
);
157157

158-
/** @var int|null Number of already formatted types in the current union type */
158+
/** @var int|null Number of already formatted types in the current compound type */
159159
private $num_types = null;
160160

161+
/** @var string|null The character to separate the current compound type, i.e. "|" or "&" */
162+
private $type_separator = null;
163+
161164
protected $pihandlers = array(
162165
'dbhtml' => 'PI_DBHTMLHandler',
163166
'dbtimestamp' => 'PI_DBHTMLHandler',
@@ -315,14 +318,16 @@ public function format_type($open, $tag, $attrs, $props) {
315318
if ($open) {
316319
if (isset($attrs[Reader::XMLNS_DOCBOOK]["class"])) {
317320
$this->num_types = 0;
321+
$this->type_separator = $attrs[Reader::XMLNS_DOCBOOK]["class"] === "union" ? "|" : "&";
318322
} elseif (isset($this->num_types)) {
319-
if ($this->num_types > 0) $retval .= '|';
323+
if ($this->num_types > 0) $retval .= $this->type_separator;
320324
$this->num_types++;
321325
}
322326
$retval .= '<span class="type">';
323327
} else {
324328
if (isset($attrs[Reader::XMLNS_DOCBOOK]["class"])) {
325329
$this->num_types = null;
330+
$this->type_separator = null;
326331
}
327332
$retval .= '</span>';
328333
}
@@ -443,7 +448,7 @@ public function format_methodsynopsis($open, $name, $attrs, $props) {
443448
}
444449
$types[] = '<span class="type">' . $formatted_type . '</span>';
445450
}
446-
$type = implode('|', $types);
451+
$type = implode($this->type_separator, $types);
447452
if (count($types) > 1) {
448453
$type = '<span class="type">' . $type . '</span>';
449454
}

0 commit comments

Comments
 (0)