diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 01c33a1..499fcea 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2,7 +2,7 @@ parameters: ignoreErrors: - message: "#^Function phpDocumentor\\\\Guides\\\\DependencyInjection\\\\template not found\\.$#" - count: 5 + count: 7 path: src/DependencyInjection/GuidesPhpDomainExtension.php - diff --git a/resources/config/php-domain.php b/resources/config/php-domain.php index 53cb2bc..75e6cea 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\ConstDirective; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; use T3Docs\GuidesPhpDomain\Directives\Php\EnumDirective; @@ -27,6 +28,7 @@ ->bind('$startingRule', service(DirectiveContentRule::class)) ->instanceof(BaseDirective::class) ->tag('phpdoc.guides.directive') + ->set(ConstDirective::class) ->set(EnumDirective::class) ->set(InterfaceDirective::class) ->set(MethodDirective::class) diff --git a/resources/template/html/body/directive/php/const.html.twig b/resources/template/html/body/directive/php/const.html.twig new file mode 100644 index 0000000..95e482e --- /dev/null +++ b/resources/template/html/body/directive/php/const.html.twig @@ -0,0 +1,7 @@ +
+
+ constant + {{ renderNode(node.memberName) }} +
+
{{ renderNode(node.value) }}
+
diff --git a/resources/template/html/body/directive/php/memberName.html.twig b/resources/template/html/body/directive/php/memberName.html.twig new file mode 100644 index 0000000..d667905 --- /dev/null +++ b/resources/template/html/body/directive/php/memberName.html.twig @@ -0,0 +1 @@ +{{ node.name }} diff --git a/src/DependencyInjection/GuidesPhpDomainExtension.php b/src/DependencyInjection/GuidesPhpDomainExtension.php index 426d381..a02aaea 100644 --- a/src/DependencyInjection/GuidesPhpDomainExtension.php +++ b/src/DependencyInjection/GuidesPhpDomainExtension.php @@ -10,8 +10,10 @@ use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use T3Docs\GuidesPhpDomain\Nodes\FullyQualifiedNameNode; +use T3Docs\GuidesPhpDomain\Nodes\MemberNameNode; use T3Docs\GuidesPhpDomain\Nodes\MethodNameNode; use T3Docs\GuidesPhpDomain\Nodes\PhpComponentNode; +use T3Docs\GuidesPhpDomain\Nodes\PhpConstNode; use T3Docs\GuidesPhpDomain\Nodes\PhpMethodNode; use T3Docs\GuidesPhpDomain\Nodes\PhpNamespaceNode; @@ -39,8 +41,10 @@ public function prepend(ContainerBuilder $container): void 'templates' => [ template(FullyQualifiedNameNode::class, 'body/directive/php/fullyQualifiedName.html.twig'), template(PhpComponentNode::class, 'body/directive/php/component.html.twig'), + template(PhpConstNode::class, 'body/directive/php/const.html.twig'), template(PhpNamespaceNode::class, 'body/directive/php/namespace.html.twig'), template(PhpMethodNode::class, 'body/directive/php/method.html.twig'), + template(MemberNameNode::class, 'body/directive/php/memberName.html.twig'), template(MethodNameNode::class, 'body/directive/php/methodName.html.twig'), ], ], diff --git a/src/Directives/Php/ConstDirective.php b/src/Directives/Php/ConstDirective.php new file mode 100644 index 0000000..2b4d25d --- /dev/null +++ b/src/Directives/Php/ConstDirective.php @@ -0,0 +1,48 @@ +addGenericLink($this->getName(), $this->getName()); + } + + public function getName(): string + { + return 'php:const'; + } + + protected function processSub( + BlockContext $blockContext, + CollectionNode $collectionNode, + Directive $directive, + ): Node|null { + $name = new MemberNameNode(trim($directive->getData())); + $id = $this->anchorReducer->reduceAnchor($name->toString()); + + return new PhpConstNode( + $id, + $name, + $collectionNode->getChildren(), + ); + } +} diff --git a/src/Nodes/MemberNameNode.php b/src/Nodes/MemberNameNode.php new file mode 100644 index 0000000..833e3fb --- /dev/null +++ b/src/Nodes/MemberNameNode.php @@ -0,0 +1,28 @@ + + */ +class MemberNameNode extends AbstractNode +{ + public function __construct( + private readonly string $name, + ) { + $this->value = $name; + } + + public function getName(): string + { + return $this->name; + } + + public function toString(): string + { + return $this->name; + } +} diff --git a/src/Nodes/PhpConstNode.php b/src/Nodes/PhpConstNode.php new file mode 100644 index 0000000..169f117 --- /dev/null +++ b/src/Nodes/PhpConstNode.php @@ -0,0 +1,28 @@ +toString(), $value); + } + + public function getMemberName(): MemberNameNode + { + return $this->memberName; + } +} diff --git a/tests/integration/enum-with-constant/expected/index.html b/tests/integration/enum-with-constant/expected/index.html new file mode 100644 index 0000000..57de1a7 --- /dev/null +++ b/tests/integration/enum-with-constant/expected/index.html @@ -0,0 +1,28 @@ + +
+

PHP Enum with Const

+ +
+
+ enum + \MyVendor\MyExtension\ +SomeEnum + +
+
+

some stuff

+
+ constant + PI + +
+

represents the ratio of a circle's circumference to its diameter

+
+ +
+
+ +
+ + diff --git a/tests/integration/enum-with-constant/input/index.rst b/tests/integration/enum-with-constant/input/index.rst new file mode 100644 index 0000000..e614815 --- /dev/null +++ b/tests/integration/enum-with-constant/input/index.rst @@ -0,0 +1,13 @@ +=================== +PHP Enum with Const +=================== + +.. php:enum:: MyVendor\MyExtension\SomeEnum + + some stuff + + + .. php:const:: PI + + represents the ratio of a circle's circumference to its diameter + diff --git a/tests/integration/interface-with-const/expected/index.html b/tests/integration/interface-with-const/expected/index.html new file mode 100644 index 0000000..e6452ec --- /dev/null +++ b/tests/integration/interface-with-const/expected/index.html @@ -0,0 +1,28 @@ + +
+

PHP Interface with const

+ +
+
+ interface + \TYPO3\CMS\Core\ +TestInterface + +
+
+

Lorem Ipsum Dolor!

+
+ constant + ATOM + +
+

The ATOM

+
+ +
+
+ +
+ + diff --git a/tests/integration/interface-with-const/input/index.rst b/tests/integration/interface-with-const/input/index.rst new file mode 100644 index 0000000..8dea266 --- /dev/null +++ b/tests/integration/interface-with-const/input/index.rst @@ -0,0 +1,11 @@ +======================== +PHP Interface with const +======================== + +.. php:interface:: TYPO3\CMS\Core\TestInterface + + Lorem Ipsum Dolor! + + .. php:const:: ATOM + + The ATOM