From 072b3358ce72937a26af57d37e004a4d9439a5a4 Mon Sep 17 00:00:00 2001 From: haszi Date: Sun, 16 Jun 2024 18:18:56 +0200 Subject: [PATCH 1/2] Add property and constant attribute rendering --- phpdotnet/phd/Package/Generic/XHTML.php | 14 +++ .../generic/attribute_formatting_003.phpt | 88 +++++++++++++++++++ .../generic/data/attribute_formatting_003.xml | 38 ++++++++ 3 files changed, 140 insertions(+) create mode 100644 tests/package/generic/attribute_formatting_003.phpt create mode 100644 tests/package/generic/data/attribute_formatting_003.xml diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 954d4438..38a2490a 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -1218,12 +1218,26 @@ public function format_emphasis($open, $name, $attrs) public function format_fieldsynopsis($open, $name, $attrs) { $this->cchunk["fieldsynopsis"] = $this->dchunk["fieldsynopsis"]; if ($open) { + if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) { + $this->pushRole($attrs[Reader::XMLNS_DOCBOOK]["role"]); + } return '
'; } + if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) { + $this->popRole(); + } return ";
\n"; } public function format_fieldsynopsis_modifier_text($value, $tag) { + if ($this->getRole() === "attribute") { + $attribute = trim(strtolower($value), "#[]\\"); + $href = Format::getFilename("class.$attribute"); + if ($href) { + return '' .$value. ' '; + } + return false; + } $this->cchunk["fieldsynopsis"]["modifier"] = trim($value); return $this->TEXT($value); } diff --git a/tests/package/generic/attribute_formatting_003.phpt b/tests/package/generic/attribute_formatting_003.phpt new file mode 100644 index 00000000..20ca2d61 --- /dev/null +++ b/tests/package/generic/attribute_formatting_003.phpt @@ -0,0 +1,88 @@ +--TEST-- +Attribute formatting 003 - Class properties/constants +--FILE-- +setXml_file($xml_file); + +$format = new TestGenericChunkedXHTML; + +$format->SQLiteIndex( + null, // $context, + null, // $index, + "class.knownattribute", // $id, + "file.knownattribute.is.in", // $filename, + "", // $parent, + "", // $sdesc, + "", // $ldesc, + "", // $element, + "", // $previous, + "", // $next, + 0, // $chunk +); +$format->SQLiteIndex( + null, // $context, + null, // $index, + "class.anotherknownattribute", // $id, + "file.anotherknownattribute.is.in", // $filename, + "", // $parent, + "", // $sdesc, + "", // $ldesc, + "", // $element, + "", // $previous, + "", // $next, + 0, // $chunk +); + +$render = new TestRender(new Reader, $config, $format); + +$render->run(); +?> +--EXPECT-- +Filename: attribute-formatting-003.html +Content: +
+
+

1. Property/Constant with unknown attributes

+
+ + class ClassName + {
+
/* Properties/Constants */
+
+ #[\UnknownAttribute]
+ #[\AnotherUnknownAttribute]
+ public + readonly + string + $CONSTANT_NAME;
+ + }
+
+ +
+

2. Property/Constant with known attributes

+
+ + class ClassName + {
+
/* Properties/Constants */
+
+ #[\KnownAttribute]
+ #[\AnotherKnownAttribute]
+ public + readonly + string + $propertyName;
+ + }
+
+ +
diff --git a/tests/package/generic/data/attribute_formatting_003.xml b/tests/package/generic/data/attribute_formatting_003.xml new file mode 100644 index 00000000..3905c5c8 --- /dev/null +++ b/tests/package/generic/data/attribute_formatting_003.xml @@ -0,0 +1,38 @@ + +
+ 1. Property/Constant with unknown attributes + + + ClassName + + Properties/Constants + + #[\UnknownAttribute] + #[\AnotherUnknownAttribute] + public + readonly + string + CONSTANT_NAME + + +
+ +
+ 2. Property/Constant with known attributes + + + ClassName + + Properties/Constants + + #[\KnownAttribute] + #[\AnotherKnownAttribute] + public + readonly + string + propertyName + + +
+ +
From 1732575dab94bd187b0bae54f7f68622751944a6 Mon Sep 17 00:00:00 2001 From: haszi Date: Sun, 16 Jun 2024 18:30:22 +0200 Subject: [PATCH 2/2] Fix whitespace --- tests/package/generic/attribute_formatting_003.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/package/generic/attribute_formatting_003.phpt b/tests/package/generic/attribute_formatting_003.phpt index 20ca2d61..a042c8a4 100644 --- a/tests/package/generic/attribute_formatting_003.phpt +++ b/tests/package/generic/attribute_formatting_003.phpt @@ -52,7 +52,7 @@ Content:

1. Property/Constant with unknown attributes

- + class ClassName {
/* Properties/Constants */
@@ -70,7 +70,7 @@ Content:

2. Property/Constant with known attributes

- + class ClassName {
/* Properties/Constants */