Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly support union types #30

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpdotnet/phd/Package/Generic/XHTML.php
Expand Up @@ -427,7 +427,7 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML {
"modifier" => "public",
),
"methodsynopsis" => array(
"returntype" => false,
"returntypes" => [],
),
"co" => 0,
"callouts" => 0,
Expand Down
4 changes: 0 additions & 4 deletions phpdotnet/phd/Package/PHP/PDF.php
Expand Up @@ -288,10 +288,6 @@ public function format_type_text($type, $tagname) {
$href = "language.pseudo-types";
$fragment = "language.types.$t";
break;
case "array|object":
$href = "language.pseudo-types";
$fragment = "language.types.array-object";
break;
default:
/* Check if its a classname. */
$t = strtolower(str_replace(array("_", "::", "->"), array("-", "-", "-"), $t));
Expand Down
61 changes: 47 additions & 14 deletions phpdotnet/phd/Package/PHP/XHTML.php
Expand Up @@ -69,8 +69,12 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
),
),
'type' => array(
/* DEFAULT */ 'span',
/* DEFAULT */ 'format_type',
'methodsynopsis' => 'format_suppressed_tags',
'type' => array(
/* DEFAULT */ 'format_type',
'methodsynopsis' => 'format_suppressed_tags',
),
cmb69 marked this conversation as resolved.
Show resolved Hide resolved
),
'varname' => array(
/* DEFAULT */ 'format_suppressed_tags',
Expand Down Expand Up @@ -102,11 +106,15 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
),
'refname' => 'format_refname_text',
'type' => array(
/* DEFAULT */ 'format_type_text',
/* DEFAULT */ 'format_type_if_object_or_pseudo_text',
'classsynopsisinfo' => false,
'fieldsynopsis' => 'format_type_if_object_or_pseudo_text',
'methodparam' => 'format_type_if_object_or_pseudo_text',
'methodsynopsis' => 'format_type_methodsynopsis_text',
'type' => array(
/* DEFAULT */ 'format_type_if_object_or_pseudo_text',
'methodsynopsis' => 'format_type_methodsynopsis_text',
),
),
'titleabbrev' => array(
/* DEFAULT */ 'format_suppressed_text',
Expand All @@ -125,10 +133,11 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
private $versions = array();
private $acronyms = array();
protected $deprecated = array();

/* Current Chunk settings */
protected $cchunk = array();
/* Default Chunk settings */

/* Default Chunk settings */
protected $dchunk = array(
"phpdoc:classref" => null,
"args" => null,
Expand All @@ -145,6 +154,9 @@ abstract class Package_PHP_XHTML extends Package_Generic_XHTML {
"refsynopsisdiv" => null,
);

/** @var int|null Number of already formatted types in the current union type */
private $num_types = null;

protected $pihandlers = array(
'dbhtml' => 'PI_DBHTMLHandler',
'dbtimestamp' => 'PI_DBHTMLHandler',
Expand Down Expand Up @@ -297,6 +309,24 @@ public function autogenVersionInfo($refnames) {
$retval = '<p class="verinfo">(' .(htmlspecialchars($verinfo, ENT_QUOTES, "UTF-8")). ')</p>';
return $retval;
}
public function format_type($open, $tag, $attrs, $props) {
$retval = '';
if ($open) {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["class"])) {
$this->num_types = 0;
} elseif (isset($this->num_types)) {
if ($this->num_types > 0) $retval .= '|';
$this->num_types++;
}
$retval .= '<span class="type">';
} else {
if (isset($attrs[Reader::XMLNS_DOCBOOK]["class"])) {
$this->num_types = null;
}
$retval .= '</span>';
}
return $retval;
cmb69 marked this conversation as resolved.
Show resolved Hide resolved
}
public function format_refpurpose($open, $tag, $attrs, $props) {
if ($open) {
$retval = "";
Expand Down Expand Up @@ -402,13 +432,20 @@ public function format_methodsynopsis($open, $name, $attrs) {
}
$content .= " )";

if ($this->cchunk["methodsynopsis"]["returntype"]) {
$return_type = $this->cchunk["methodsynopsis"]["returntype"];
$formatted_type = self::format_type_if_object_or_pseudo_text($return_type, "type");
if ($formatted_type === false) {
$formatted_type = $return_type;
if ($this->cchunk["methodsynopsis"]["returntypes"]) {
$types = [];
foreach ($this->cchunk["methodsynopsis"]["returntypes"] as $return_type) {
$formatted_type = self::format_type_if_object_or_pseudo_text($return_type, "type");
if ($formatted_type === false) {
$formatted_type = $return_type;
}
$types[] = '<span class="type">' . $formatted_type . '</span>';
}
$type = implode('|', $types);
if (count($types) > 1) {
$type = '<span class="type">' . $type . '</span>';
}
$content .= ' : <span class="type">' . $formatted_type . '</span>';
$content .= ' : ' . $type;
}

$content .= "</div>\n";
Expand All @@ -418,7 +455,7 @@ public function format_methodsynopsis($open, $name, $attrs) {
}

public function format_type_methodsynopsis_text($type, $tagname) {
$this->cchunk["methodsynopsis"]["returntype"] = $type;
$this->cchunk["methodsynopsis"]["returntypes"][] = $type;
return "";
}

Expand Down Expand Up @@ -461,10 +498,6 @@ public function format_type_text($type, $tagname) {
$href = "language.pseudo-types";
$fragment = "language.types.$t";
break;
case "array|object":
$href = "language.pseudo-types";
$fragment = "language.types.array-object";
break;
default:
/* Check if its a classname. */
$href = Format::getFilename("class.$t");
Expand Down