diff --git a/resources/config/php-domain.php b/resources/config/php-domain.php index 095706e..5157958 100644 --- a/resources/config/php-domain.php +++ b/resources/config/php-domain.php @@ -7,6 +7,7 @@ use phpDocumentor\Guides\RestructuredText\Parser\Productions\DirectiveContentRule; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; +use T3Docs\GuidesPhpDomain\Directives\Php\ClassDirective; use T3Docs\GuidesPhpDomain\Directives\Php\ConstDirective; use T3Docs\GuidesPhpDomain\Directives\Php\GlobalDirective; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; @@ -29,6 +30,7 @@ ->bind('$startingRule', service(DirectiveContentRule::class)) ->instanceof(BaseDirective::class) ->tag('phpdoc.guides.directive') + ->set(ClassDirective::class) ->set(ConstDirective::class) ->set(EnumDirective::class) ->set(GlobalDirective::class) diff --git a/src/Directives/Php/ClassDirective.php b/src/Directives/Php/ClassDirective.php new file mode 100644 index 0000000..16d9eca --- /dev/null +++ b/src/Directives/Php/ClassDirective.php @@ -0,0 +1,55 @@ +addGenericLink($this->getName(), $this->getName()); + } + + public function getName(): string + { + return 'php:class'; + } + + 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 PhpClassNode( + $id, + $fqn, + $collectionNode->getChildren(), + null, + [], + [], + ); + } +} diff --git a/src/Nodes/PhpClassNode.php b/src/Nodes/PhpClassNode.php new file mode 100644 index 0000000..af5ab6a --- /dev/null +++ b/src/Nodes/PhpClassNode.php @@ -0,0 +1,27 @@ + $members + * @param list $modifiers + * @param list $value + */ + public function __construct( + string $id, + FullyQualifiedNameNode $name, + array $value = [], + PhpNamespaceNode|null $namespace = null, + array $members = [], + array $modifiers = [], + ) { + parent::__construct($id, self::TYPE, $name, $value, $namespace, $members, $modifiers); + } +} diff --git a/tests/integration/class-namespace-directive/expected/index.html b/tests/integration/class-namespace-directive/expected/index.html new file mode 100644 index 0000000..1c76d28 --- /dev/null +++ b/tests/integration/class-namespace-directive/expected/index.html @@ -0,0 +1,46 @@ + +
+

PHP Class with current namespace from directive

+ +
+
+ class + \TYPO3\CMS\Core\ +TestClass + +
+
+

Lorem Ipsum Dolor!

+
+
+ +
+
+ class + \TYPO3\CMS\Core\ +AnotherClass + +
+
+

Lorem Ipsum Dolor Another!

+
+
+ +
+
+ class + \MyVendor\Some\Namespace\ +AnotherClass + +
+
+

Lorem Ipsum Dolor Yet Another!

+
+
+ +
+ + diff --git a/tests/integration/class-namespace-directive/input/index.rst b/tests/integration/class-namespace-directive/input/index.rst new file mode 100644 index 0000000..9bcc2b6 --- /dev/null +++ b/tests/integration/class-namespace-directive/input/index.rst @@ -0,0 +1,17 @@ +=============================================== +PHP Class with current namespace from directive +=============================================== + +.. php:namespace:: TYPO3\CMS\Core + +.. php:class:: TestClass + + Lorem Ipsum Dolor! + +.. php:class:: AnotherClass + + Lorem Ipsum Dolor Another! + +.. php:class:: MyVendor\Some\Namespace\AnotherClass + + Lorem Ipsum Dolor Yet Another! diff --git a/tests/integration/class-with-method/expected/index.html b/tests/integration/class-with-method/expected/index.html new file mode 100644 index 0000000..37a2832 --- /dev/null +++ b/tests/integration/class-with-method/expected/index.html @@ -0,0 +1,45 @@ + +
+

PHP Class with explicit namespace

+ +
+
+ class + \TYPO3\CMS\Core\ +Test + +
+
+

Lorem Ipsum Dolor!

+
+ +setDate +( +int $year, int $month, int $day) + +
+
+

Set the date.

+
+
+
+
+ +getDate +( +) +: int + +
+
+

Get the date.

+
+
+ +
+
+ +
+ + diff --git a/tests/integration/class-with-method/input/index.rst b/tests/integration/class-with-method/input/index.rst new file mode 100644 index 0000000..79cd2c0 --- /dev/null +++ b/tests/integration/class-with-method/input/index.rst @@ -0,0 +1,15 @@ +================================= +PHP Class with explicit namespace +================================= + +.. php:class:: TYPO3\CMS\Core\Test + + Lorem Ipsum Dolor! + + .. php:method:: setDate(int $year, int $month, int $day) + + Set the date. + + .. php:method:: getDate(): int + + Get the date. diff --git a/tests/integration/class-without-namespace/expected/index.html b/tests/integration/class-without-namespace/expected/index.html new file mode 100644 index 0000000..700cd25 --- /dev/null +++ b/tests/integration/class-without-namespace/expected/index.html @@ -0,0 +1,19 @@ + +
+

PHP Class

+ +
+
+ class + TestClass + +
+
+

Lorem Ipsum Dolor!

+
+
+ +
+ + diff --git a/tests/integration/class-without-namespace/input/index.rst b/tests/integration/class-without-namespace/input/index.rst new file mode 100644 index 0000000..bb9c098 --- /dev/null +++ b/tests/integration/class-without-namespace/input/index.rst @@ -0,0 +1,7 @@ +========= +PHP Class +========= + +.. php:class:: TestClass + + Lorem Ipsum Dolor!