From cba8f7b8e050e65544fe5a85cd312045c17de27a Mon Sep 17 00:00:00 2001 From: "lina.wolf" Date: Sat, 9 Dec 2023 07:05:04 +0000 Subject: [PATCH] [FEATURE] PHP domain object struct See https://wiki.php.net/rfc/structs --- resources/config/php-domain.php | 2 + src/Directives/Php/StructDirective.php | 57 +++++++++++++++++++ src/Nodes/PhpStructNode.php | 26 +++++++++ .../struct-directive/expected/index.html | 48 ++++++++++++++++ .../struct-directive/input/index.rst | 19 +++++++ 5 files changed, 152 insertions(+) create mode 100644 src/Directives/Php/StructDirective.php create mode 100644 src/Nodes/PhpStructNode.php create mode 100644 tests/integration/struct-directive/expected/index.html create mode 100644 tests/integration/struct-directive/input/index.rst diff --git a/resources/config/php-domain.php b/resources/config/php-domain.php index 0f49f8e..7bef5f3 100644 --- a/resources/config/php-domain.php +++ b/resources/config/php-domain.php @@ -13,6 +13,7 @@ use T3Docs\GuidesPhpDomain\Directives\Php\PropertyDirective; use T3Docs\GuidesPhpDomain\Directives\Php\StaticMethodDirective; use T3Docs\GuidesPhpDomain\Directives\Php\GlobalDirective; +use T3Docs\GuidesPhpDomain\Directives\Php\StructDirective; use T3Docs\GuidesPhpDomain\PhpDomain\ModifierService; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; @@ -45,6 +46,7 @@ ->set(NamespaceDirective::class) ->set(PropertyDirective::class) ->set(StaticMethodDirective::class) + ->set(StructDirective::class) ->set(FullyQualifiedNameService::class) ->set(MethodNameService::class) ->set(ModifierService::class) diff --git a/src/Directives/Php/StructDirective.php b/src/Directives/Php/StructDirective.php new file mode 100644 index 0000000..998c149 --- /dev/null +++ b/src/Directives/Php/StructDirective.php @@ -0,0 +1,57 @@ +addGenericLink($this->getName(), $this->getName()); + } + + public function getName(): string + { + return 'php:struct'; + } + + protected function processSub( + BlockContext $blockContext, + CollectionNode $collectionNode, + Directive $directive, + ): Node|null { + $name = trim($directive->getData()); + $fqn = $this->fullyQualifiedNameService->getFullyQualifiedName($name, true); + $id = $this->anchorReducer->reduceAnchor($fqn->toString()); + + return new PhpStructNode( + $id, + $fqn, + $collectionNode->getChildren(), + null, + [], + ); + } +} diff --git a/src/Nodes/PhpStructNode.php b/src/Nodes/PhpStructNode.php new file mode 100644 index 0000000..ce45367 --- /dev/null +++ b/src/Nodes/PhpStructNode.php @@ -0,0 +1,26 @@ + $value + * @param list $members + */ + public function __construct( + string $id, + FullyQualifiedNameNode $name, + array $value = [], + PhpNamespaceNode|null $namespace = null, + array $members = [], + ) { + parent::__construct($id, self::TYPE, $name, $value, $namespace, $members); + } +} diff --git a/tests/integration/struct-directive/expected/index.html b/tests/integration/struct-directive/expected/index.html new file mode 100644 index 0000000..aa8bc3d --- /dev/null +++ b/tests/integration/struct-directive/expected/index.html @@ -0,0 +1,48 @@ + +
+

PHP static method

+ +
+
+ struct + \App\Accounting\ +Employee + +
+
+
+
+ string firstName + +
+
+
+
+
+ string lastName + +
+
+
+
+
+ int salary + +
+
+
+
+
+ bool fullTime + +
+
+
+ +
+
+ +
+ + diff --git a/tests/integration/struct-directive/input/index.rst b/tests/integration/struct-directive/input/index.rst new file mode 100644 index 0000000..e7ac5e1 --- /dev/null +++ b/tests/integration/struct-directive/input/index.rst @@ -0,0 +1,19 @@ +================= +PHP static method +================= + +.. php:namespace:: App\Accounting + +.. php:struct:: Employee + + .. php:property:: firstName + :type: string + + .. php:property:: lastName + :type: string + + .. php:property:: salary + :type: int + + .. php:property:: fullTime + :type: bool