Skip to content

Commit 9c996f2

Browse files
authored
Generate int/float/null instead of integer/double/NULL in docgen.php
Co-authored-by: Christoph M. Becker <[email protected]> Co-authored-by: Peter Cowburn <[email protected]> Closes GH-45.
1 parent 6a1a15b commit 9c996f2

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

scripts/docgen/docgen.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,32 @@ function save_file($filename, $content) { /* {{{ */
187187
}
188188
/* }}} */
189189

190+
/** Returns an xml type tag or an entity to use in the generated xml for a PHP constant */
191+
function get_xml_type_tag_or_entity($value, bool $allow_entity) { /* {{{ */
192+
// Entities from entities/global.ent are recommended for freeform text.
193+
if (is_int($value)) {
194+
return $allow_entity ? '&integer;' : '<type>int</type>';
195+
} elseif (is_float($value)) {
196+
return $allow_entity ? '&float;' : '<type>float</type>';
197+
} elseif (is_null($value)) {
198+
return '<type>null</type>';
199+
} elseif (is_bool($value)) {
200+
return $allow_entity ? '&boolean;' : '<type>bool</type>';
201+
}
202+
if ($allow_entity) {
203+
if (is_array($value)) {
204+
return '&array;';
205+
} elseif (is_object($value)) {
206+
return '&object;';
207+
} elseif (is_resource($value)) {
208+
return '&resource;';
209+
}
210+
}
211+
// Use <type>$type</type> for other types
212+
return '<type>' . gettype($value) . '</type>';
213+
}
214+
/* }}} */
215+
190216
function get_type_by_string($str) { /* {{{ */
191217
if (is_numeric($str)) {
192218
if ($str && intval($str) == $str) {
@@ -507,7 +533,7 @@ function gen_class_markup(ReflectionClass $class, $content) { /* {{{ */
507533
foreach ($constants as $constant => $value) {
508534
$markup .= str_repeat(' ', $ident) ."<fieldsynopsis>". PHP_EOL;
509535
$markup .= str_repeat(' ', $ident + 1) ."<modifier>const</modifier>". PHP_EOL;
510-
$markup .= str_repeat(' ', $ident + 1) .'<type>'. gettype($value) ."</type>". PHP_EOL;
536+
$markup .= str_repeat(' ', $ident + 1) .get_xml_type_tag_or_entity($value, false). PHP_EOL; // For the class synopsis we use explicit <type> elements
511537
$markup .= str_repeat(' ', $ident + 1) .'<varname linkend="'. $id .'.constants.'. format_id($constant) .'">'. $class->getName() .'::'. $constant ."</varname>". PHP_EOL;
512538
$markup .= str_repeat(' ', $ident + 1) .'<initializer>'. $value ."</initializer>". PHP_EOL;
513539
$markup .= str_repeat(' ', $ident) ."</fieldsynopsis>". PHP_EOL;
@@ -707,7 +733,7 @@ function gen_extension_markup(ReflectionExtension $obj, $content, $xml_file) { /
707733
$markup .= str_repeat(' ', $ident + 2) .'<varlistentry xml:id="constant.'. format_id($name) .'">'. PHP_EOL;
708734
$markup .= str_repeat(' ', $ident + 3) ."<term>". PHP_EOL;
709735
$markup .= str_repeat(' ', $ident + 4) ."<constant>". $name ."</constant>". PHP_EOL;
710-
$markup .= str_repeat(' ', $ident + 4) ."(<type>". gettype($value) ."</type>)". PHP_EOL;
736+
$markup .= str_repeat(' ', $ident + 4) ."(". get_xml_type_tag_or_entity($value, true) .")". PHP_EOL;
711737
$markup .= str_repeat(' ', $ident + 3) ."</term>". PHP_EOL;
712738
$markup .= str_repeat(' ', $ident + 3) ."<listitem>". PHP_EOL;
713739
$markup .= str_repeat(' ', $ident + 4) ."<simpara>". PHP_EOL;

0 commit comments

Comments
 (0)