From 472dd3c144d10053f58ef3a114237f30e0baa45b Mon Sep 17 00:00:00 2001 From: haszi Date: Sun, 9 Jun 2024 22:24:40 +0200 Subject: [PATCH] Add non-parameter attribute rendering Enable rendering of attributes for classes, exceptions, interfaces, methods and functions. --- phpdotnet/phd/Package/Generic/XHTML.php | 26 ++- .../generic/attribute_formatting_001.phpt | 4 +- .../generic/attribute_formatting_002.phpt | 170 ++++++++++++++++++ .../generic/data/attribute_formatting_001.xml | 4 +- .../generic/data/attribute_formatting_002.xml | 140 +++++++++++++++ 5 files changed, 339 insertions(+), 5 deletions(-) create mode 100644 tests/package/generic/attribute_formatting_002.phpt create mode 100644 tests/package/generic/data/attribute_formatting_002.xml diff --git a/phpdotnet/phd/Package/Generic/XHTML.php b/phpdotnet/phd/Package/Generic/XHTML.php index 6a7dc8e6..7e6e837a 100644 --- a/phpdotnet/phd/Package/Generic/XHTML.php +++ b/phpdotnet/phd/Package/Generic/XHTML.php @@ -145,7 +145,10 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { 'methodsynopsis' => 'format_methodsynopsis', 'methodname' => 'format_methodname', 'member' => 'format_member', - 'modifier' => 'format_modifier', + 'modifier' => array( + /* DEFAULT */ 'format_modifier', + 'methodparam' => 'format_methodparam_modifier', + ), 'note' => 'format_note', 'orgname' => 'span', 'othercredit' => 'format_div', @@ -395,6 +398,10 @@ abstract class Package_Generic_XHTML extends Format_Abstract_XHTML { 'fieldsynopsis' => 'format_fieldsynopsis_modifier_text', 'methodparam' => 'format_modifier_text', 'methodsynopsis' => 'format_modifier_text', + 'constructorsynopsis' => 'format_modifier_text', + 'ooclass' => 'format_modifier_text', + 'ooexception' => 'format_modifier_text', + 'oointerface' => 'format_modifier_text', ), /** Those are used to retrieve the class/interface name to be able to remove it from method names */ 'classname' => [ @@ -1220,6 +1227,23 @@ public function format_fieldsynopsis_modifier_text($value, $tag) { } public function format_modifier($open, $name, $attrs, $props) { + if ($open) { + if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) { + $this->pushRole($attrs[Reader::XMLNS_DOCBOOK]["role"]); + return ''; + } + return ''; + } + if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) { + if ($attrs[Reader::XMLNS_DOCBOOK]["role"] === "attribute") { + return '
'; + } + $this->popRole(); + } + return '
'; + } + + public function format_methodparam_modifier($open, $name, $attrs, $props) { if ($open) { if (isset($attrs[Reader::XMLNS_DOCBOOK]["role"])) { $this->pushRole($attrs[Reader::XMLNS_DOCBOOK]["role"]); diff --git a/tests/package/generic/attribute_formatting_001.phpt b/tests/package/generic/attribute_formatting_001.phpt index 6c060192..99afd149 100644 --- a/tests/package/generic/attribute_formatting_001.phpt +++ b/tests/package/generic/attribute_formatting_001.phpt @@ -48,13 +48,13 @@ Content:

3. Function parameter with unknown attribute

-
bool password_verify#[\UnknownAttribute](string $password, string $hash)
+
bool password_verify(#[\UnknownAttribute]string $password, string $hash)

4. Function parameter with known attribute

-
bool password_verify#[\KnownAttribute] (string $password, string $hash)
+
bool password_verify(#[\KnownAttribute] string $password, string $hash)
diff --git a/tests/package/generic/attribute_formatting_002.phpt b/tests/package/generic/attribute_formatting_002.phpt new file mode 100644 index 00000000..5a5c94dd --- /dev/null +++ b/tests/package/generic/attribute_formatting_002.phpt @@ -0,0 +1,170 @@ +--TEST-- +Attribute formatting 002 - Class and method attributes +--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, new Config, $format); + +$render->run(); +?> +--EXPECT-- +Filename: attribute-formatting-002.html +Content: +
+
+

1. Class with unknown attributes

+
+ + #[\UnknownAttribute]
+ #[\AnotherUnknownAttribute]
+ class DateTime + {
+ }
+
+ +
+

2. Class with known attributes

+
+ + #[\KnownAttribute]
+ #[\AnotherKnownAttribute]
+ class DateTime + {
+ }
+
+ +
+

3. Method with unknown attributes

+
+ #[\UnknownAttribute]
+ #[\AnotherUnknownAttribute]
+ public ClassName::methodName()
+ +
+ +
+

4. Method with known attributes

+
#[\KnownAttribute]
+ #[\AnotherKnownAttribute]
+ public ClassName::methodName()
+ +
+ +
+

5. Constructor with unknown attributes

+
#[\UnknownAttribute]
+ #[\AnotherUnknownAttribute]
+ public ClassName::__construct()
+ +
+ +
+

6. Constructor with known attributes

+
#[\KnownAttribute]
+ #[\AnotherKnownAttribute]
+ public ClassName::__construct()
+ +
+ +
+

7. Class, constructor and methods with unknown attributes

+
+ + #[\UnknownAttribute]
+ #[\AnotherUnknownAttribute]
+ class DateTime + {
+
+ #[\UnknownAttribute]
+ #[\AnotherUnknownAttribute]
+ public ClassName::__construct()
+ +
#[\UnknownAttribute]
+ #[\AnotherUnknownAttribute]
+ public ClassName::methodName1()
+ +
#[\UnknownAttribute]
+ #[\AnotherUnknownAttribute]
+ public ClassName::methodName2()
+ + }
+
+ +
+

8. Class, constructor and methods with known attributes

+
+ + #[\KnownAttribute]
+ #[\AnotherKnownAttribute]
+ class DateTime + {
+
+ #[\KnownAttribute]
+ #[\AnotherKnownAttribute]
+ public ClassName::__construct()
+ +
#[\KnownAttribute]
+ #[\AnotherKnownAttribute]
+ public ClassName::methodName1()
+ +
#[\KnownAttribute]
+ #[\AnotherKnownAttribute]
+ public ClassName::methodName2()
+ + }
+
+ +
+

9. Function with unknown attributes

+
+ #[\UnknownAttribute]
+ #[\AnotherUnknownAttribute]
+ void function_name)
+ +
+ +
+

10. Function with known attributes

+ + +
+ +
diff --git a/tests/package/generic/data/attribute_formatting_001.xml b/tests/package/generic/data/attribute_formatting_001.xml index af69ccb0..b965d6bd 100644 --- a/tests/package/generic/data/attribute_formatting_001.xml +++ b/tests/package/generic/data/attribute_formatting_001.xml @@ -19,7 +19,7 @@ 3. Function parameter with unknown attribute boolpassword_verify - #[\UnknownAttribute]stringpassword + #[\UnknownAttribute]stringpassword stringhash @@ -28,7 +28,7 @@ 4. Function parameter with known attribute boolpassword_verify - #[\KnownAttribute]stringpassword + #[\KnownAttribute]stringpassword stringhash diff --git a/tests/package/generic/data/attribute_formatting_002.xml b/tests/package/generic/data/attribute_formatting_002.xml new file mode 100644 index 00000000..18e666ba --- /dev/null +++ b/tests/package/generic/data/attribute_formatting_002.xml @@ -0,0 +1,140 @@ + +
+ 1. Class with unknown attributes + + + #[\UnknownAttribute] + #[\AnotherUnknownAttribute] + DateTime + + +
+ +
+ 2. Class with known attributes + + + #[\KnownAttribute] + #[\AnotherKnownAttribute] + DateTime + + +
+ +
+ 3. Method with unknown attributes + + #[\UnknownAttribute] + #[\AnotherUnknownAttribute] + public ClassName::methodName + + +
+ +
+ 4. Method with known attributes + + #[\KnownAttribute] + #[\AnotherKnownAttribute] + public ClassName::methodName + + +
+ +
+ 5. Constructor with unknown attributes + + #[\UnknownAttribute] + #[\AnotherUnknownAttribute] + public ClassName::__construct + + +
+ +
+ 6. Constructor with known attributes + + #[\KnownAttribute] + #[\AnotherKnownAttribute] + public ClassName::__construct + + +
+ +
+ 7. Class, constructor and methods with unknown attributes + + + #[\UnknownAttribute] + #[\AnotherUnknownAttribute] + DateTime + + + #[\UnknownAttribute] + #[\AnotherUnknownAttribute] + public ClassName::__construct + + + + #[\UnknownAttribute] + #[\AnotherUnknownAttribute] + public ClassName::methodName1 + + + + #[\UnknownAttribute] + #[\AnotherUnknownAttribute] + public ClassName::methodName2 + + + +
+ +
+ 8. Class, constructor and methods with known attributes + + + #[\KnownAttribute] + #[\AnotherKnownAttribute] + DateTime + + + #[\KnownAttribute] + #[\AnotherKnownAttribute] + public ClassName::__construct + + + + #[\KnownAttribute] + #[\AnotherKnownAttribute] + public ClassName::methodName1 + + + + #[\KnownAttribute] + #[\AnotherKnownAttribute] + public ClassName::methodName2 + + + +
+ +
+ 9. Function with unknown attributes + + #[\UnknownAttribute] + #[\AnotherUnknownAttribute] + voidfunction_name + +
+ +
+ 10. Function with known attributes + + #[\KnownAttribute] + #[\AnotherKnownAttribute] + voidfunction_name + +
+ +