From b3fc69df58130c7ed3c24c28bae79b5c34043117 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 --- resources/config/php-domain.php | 2 + src/Directives/Php/StructDirective.php | 56 +++++++++++++++++++ src/Nodes/PhpStructNode.php | 25 +++++++++ .../struct-directive/expected/index.html | 20 +++++++ .../expected/logs/warning.log | 1 + .../struct-directive/input/index.rst | 5 ++ 6 files changed, 109 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/expected/logs/warning.log 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 67f340a..d0479b0 100644 --- a/resources/config/php-domain.php +++ b/resources/config/php-domain.php @@ -11,6 +11,7 @@ use T3Docs\GuidesPhpDomain\Directives\Php\ConstDirective; 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; @@ -40,6 +41,7 @@ ->set(MethodDirective::class) ->set(NamespaceDirective::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..de65800 --- /dev/null +++ b/src/Directives/Php/StructDirective.php @@ -0,0 +1,56 @@ +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..d980401 --- /dev/null +++ b/src/Nodes/PhpStructNode.php @@ -0,0 +1,25 @@ + +
+

PHP static method

+ +
+
static + +doSomething +( +string $whatever) +: string +
+
+

Do something

+
+
+ +
+ + diff --git a/tests/integration/struct-directive/expected/logs/warning.log b/tests/integration/struct-directive/expected/logs/warning.log new file mode 100644 index 0000000..8761005 --- /dev/null +++ b/tests/integration/struct-directive/expected/logs/warning.log @@ -0,0 +1 @@ +app.WARNING: Directive `.. php:staticmethod::` is deprecated use directive `.. php:method::` with option `:static:` instead. {"rst-file":"index.rst"} [] diff --git a/tests/integration/struct-directive/input/index.rst b/tests/integration/struct-directive/input/index.rst new file mode 100644 index 0000000..086821d --- /dev/null +++ b/tests/integration/struct-directive/input/index.rst @@ -0,0 +1,5 @@ +================= +PHP static method +================= + +.. php:struct:: Employee