@@ -187,6 +187,32 @@ function save_file($filename, $content) { /* {{{ */
187
187
}
188
188
/* }}} */
189
189
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
+
190
216
function get_type_by_string ($ str ) { /* {{{ */
191
217
if (is_numeric ($ str )) {
192
218
if ($ str && intval ($ str ) == $ str ) {
@@ -507,7 +533,7 @@ function gen_class_markup(ReflectionClass $class, $content) { /* {{{ */
507
533
foreach ($ constants as $ constant => $ value ) {
508
534
$ markup .= str_repeat (' ' , $ ident ) ."<fieldsynopsis> " . PHP_EOL ;
509
535
$ 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
511
537
$ markup .= str_repeat (' ' , $ ident + 1 ) .'<varname linkend=" ' . $ id .'.constants. ' . format_id ($ constant ) .'"> ' . $ class ->getName () .':: ' . $ constant ."</varname> " . PHP_EOL ;
512
538
$ markup .= str_repeat (' ' , $ ident + 1 ) .'<initializer> ' . $ value ."</initializer> " . PHP_EOL ;
513
539
$ markup .= str_repeat (' ' , $ ident ) ."</fieldsynopsis> " . PHP_EOL ;
@@ -707,7 +733,7 @@ function gen_extension_markup(ReflectionExtension $obj, $content, $xml_file) { /
707
733
$ markup .= str_repeat (' ' , $ ident + 2 ) .'<varlistentry xml:id="constant. ' . format_id ($ name ) .'"> ' . PHP_EOL ;
708
734
$ markup .= str_repeat (' ' , $ ident + 3 ) ."<term> " . PHP_EOL ;
709
735
$ 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 ;
711
737
$ markup .= str_repeat (' ' , $ ident + 3 ) ."</term> " . PHP_EOL ;
712
738
$ markup .= str_repeat (' ' , $ ident + 3 ) ."<listitem> " . PHP_EOL ;
713
739
$ markup .= str_repeat (' ' , $ ident + 4 ) ."<simpara> " . PHP_EOL ;
0 commit comments