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

Align the output of docgen.php to gen_stub.php #86

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions scripts/docgen/class.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@

<!-- {{{ Synopsis -->
<classsynopsis>
<ooclass><classname>{CLASS_NAME}</classname></ooclass>
<ooclass>
<classname>{CLASS_NAME}</classname>
</ooclass>

<!-- {{{ Class synopsis -->
<classsynopsisinfo>
<ooclass>
<classname>{CLASS_NAME}</classname>
</ooclass>
{EXTENDS}
{IMPLEMENTS}
</classsynopsisinfo>
<!-- }}} -->

{CONSTANTS_LIST}
{PROPERTIES_LIST}
{METHOD_XINCLUDE}
Expand Down
45 changes: 24 additions & 21 deletions scripts/docgen/docgen.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,15 @@ function add_warning($err_msg) { /* {{{ */
}
/* }}} */

function create_markup_to_modifiers(ReflectionMethod $method) { /* {{{ */
$modifiers = Reflection::getModifierNames($method->getModifiers());
$markup = '';
function create_markup_to_modifiers(int $modifierFlags): array { /* {{{ */
$modifiers = Reflection::getModifierNames($modifierFlags);
$result = [];

if ($modifiers) {
foreach ($modifiers as $modifier) {
$markup .= '<modifier>'. $modifier .'</modifier> ';
}
}
foreach ($modifiers as $modifier) {
$result[] = '<modifier>'. $modifier .'</modifier>';
}

return $markup;
return $result;
}
/* }}} */

Expand Down Expand Up @@ -395,7 +393,7 @@ function gen_method_markup(ReflectionMethod $method, $content) { /* {{{ */
$content = preg_replace('/\{METHOD_NAME\}/', $method->name, $content);

/* {MODIFIERS} */
$content = preg_replace('/\{MODIFIERS\}/', create_markup_to_modifiers($method), $content, 1);
$content = preg_replace('/\{MODIFIERS\}/', implode(" ", create_markup_to_modifiers($method->getModifiers())), $content, 1);

/* {RETURN_TYPE} */
if (!$method->isConstructor()) {
Expand Down Expand Up @@ -476,6 +474,7 @@ function gen_mapping_markup(ReflectionMethod $method, ReflectionFunction $functi

function gen_class_markup(ReflectionClass $class, $content) { /* {{{ */
$id = format_id($class->getName());
$escapedName = addslashes($class->getName());

/* {CLASS_NAME} */
$content = preg_replace('/\{CLASS_NAME\}/', $class->getName(), $content);
Expand Down Expand Up @@ -573,7 +572,7 @@ function gen_class_markup(ReflectionClass $class, $content) { /* {{{ */


/* {PROPERTIES_LIST} */
if ($properties = $class->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED)) {
if ($properties = $class->getProperties()) {
$ident = get_ident_size('PROPERTIES_LIST', $content);
$inherited = array();

Expand All @@ -587,17 +586,21 @@ function gen_class_markup(ReflectionClass $class, $content) { /* {{{ */
continue;
}

/* Get the modifier */
preg_match('/(\w+) \$/', (string) $property, $match);

$markup .= str_repeat(' ', $ident) ."<fieldsynopsis>". PHP_EOL;
$markup .= str_repeat(' ', $ident + 1) .'<modifier>'. $match[1] ."</modifier>". PHP_EOL;
$markup .= str_repeat(' ', $ident + 1) .'<varname linkend="'. $id .'.props.'. format_id($property->getName()) .'">'. $property->getName() ."</varname>". PHP_EOL;
$markup .= str_repeat(' ', $ident) ."</fieldsynopsis>". PHP_EOL;
$markup .= str_repeat(' ', $ident + 1) .
implode(
str_repeat(' ', $ident + 1) . PHP_EOL,
create_markup_to_modifiers($property->getModifiers())
) . PHP_EOL;
if (PHP_VERSION_ID >= 74000 && $property->hasType()) {
$markup .= str_repeat(' ', $ident + 1) . get_type_as_xml_string($property->getType()). PHP_EOL;
}
$markup .= str_repeat(' ', $ident + 1) . '<varname linkend="'. $id .'.props.'. format_id($property->getName()) .'">'. $property->getName() ."</varname>". PHP_EOL;
$markup .= str_repeat(' ', $ident) . "</fieldsynopsis>". PHP_EOL;
}

if ($markup) {
$markup = "<classsynopsisinfo role=\"comment\">&Properties;</classsynopsisinfo>". PHP_EOL . $markup;
$markup = PHP_EOL . str_repeat(' ', $ident) . "<classsynopsisinfo role=\"comment\">&Properties;</classsynopsisinfo>". PHP_EOL . $markup;
}

if ($inherited) {
Expand All @@ -606,7 +609,7 @@ function gen_class_markup(ReflectionClass $class, $content) { /* {{{ */
}
$markup .= '<classsynopsisinfo role="comment">&InheritedProperties;</classsynopsisinfo>'. PHP_EOL;
foreach ($inherited as $declaring_class) {
$markup .= str_repeat(' ', $ident) ."<xi:include xpointer=\"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('" . strtolower($declaring_class) . ".synopsis')/descendant::db:fieldsynopsis)\"><xi:fallback/></xi:include>". PHP_EOL;
$markup .= str_repeat(' ', $ident) ."<xi:include xpointer=\"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('" . strtolower($declaring_class) . ".synopsis')/descendant::db:fieldsynopsis)\">" . PHP_EOL . str_repeat(' ', $ident + 1) . "<xi:fallback/>" . PHP_EOL . str_repeat(' ', $ident) . "</xi:include>". PHP_EOL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use "\n" instead of PHP_EOL? As the output on Windows will be different from Nix

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking about changing this, but at last I decided not to touch so many instances of PHP_EOL (150+). However, this could de addressed in a separate PR if Christoph also agrees.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right makes sense to leave it as is then

}
}

Expand Down Expand Up @@ -651,15 +654,15 @@ function gen_class_markup(ReflectionClass $class, $content) { /* {{{ */
$ident = get_ident_size('METHOD_XINCLUDE', $content);
$content = preg_replace('/\{METHOD_XINCLUDE\}/',
PHP_EOL . str_repeat(' ', $ident) . "<classsynopsisinfo role=\"comment\">&Methods;</classsynopsisinfo>". PHP_EOL.
str_repeat(' ', $ident) ."<xi:include xpointer=\"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.". $id ."')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])\"><xi:fallback/></xi:include>",
str_repeat(' ', $ident) ."<xi:include xpointer=\"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.". $id ."')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='" . $escapedName . "'])\">" . PHP_EOL . str_repeat(' ', $ident + 1) . "<xi:fallback/>" . PHP_EOL . str_repeat(' ', $ident) . "</xi:include>",
$content, 1);

/* {INHERITED_XINCLUDE} */
if ($parent) {
$ident = get_ident_size('INHERITED_XINCLUDE', $content);
$content = preg_replace('/\{INHERITED_XINCLUDE\}/',
PHP_EOL . str_repeat(' ', $ident) ."<classsynopsisinfo role=\"comment\">&InheritedMethods;</classsynopsisinfo>". PHP_EOL.
str_repeat(' ', $ident) ."<xi:include xpointer=\"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.". format_id($parent->getName()) ."')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[not(@role='procedural')])\"><xi:fallback/></xi:include>". PHP_EOL,
str_repeat(' ', $ident) ."<xi:include xpointer=\"xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.". format_id($parent->getName()) ."')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role='" . $escapedName . "'])\">" . PHP_EOL . str_repeat(' ', $ident + 1) . "<xi:fallback/>" . PHP_EOL . str_repeat(' ', $ident) . "</xi:include>". PHP_EOL,
$content, 1);
} else {
$content = preg_replace('/^\s*\{INHERITED_XINCLUDE\}.*?\n/m', '', $content, 1);
Expand Down