diff --git a/resources/config/php-domain.php b/resources/config/php-domain.php index d671375..d5fa2c0 100644 --- a/resources/config/php-domain.php +++ b/resources/config/php-domain.php @@ -22,6 +22,7 @@ use T3Docs\GuidesPhpDomain\TextRoles\ConstTextRole; use T3Docs\GuidesPhpDomain\TextRoles\EnumTextRole; use T3Docs\GuidesPhpDomain\TextRoles\ExceptionTextRole; +use T3Docs\GuidesPhpDomain\TextRoles\GlobalTextRole; use T3Docs\GuidesPhpDomain\TextRoles\MethodTextRole; use T3Docs\GuidesPhpDomain\TextRoles\PropertyTextRole; use T3Docs\GuidesPhpDomain\TextRoles\TraitTextRole; @@ -75,6 +76,8 @@ ->tag('phpdoc.guides.parser.rst.text_role', ['domain' => 'php']) ->set(ExceptionTextRole::class) ->tag('phpdoc.guides.parser.rst.text_role', ['domain' => 'php']) + ->set(GlobalTextRole::class) + ->tag('phpdoc.guides.parser.rst.text_role', ['domain' => 'php']) ->set(InterfaceTextRole::class) ->tag('phpdoc.guides.parser.rst.text_role', ['domain' => 'php']) ->set(MethodTextRole::class) diff --git a/src/Nodes/PhpGlobalNode.php b/src/Nodes/PhpGlobalNode.php index 35a14f5..7bf5339 100644 --- a/src/Nodes/PhpGlobalNode.php +++ b/src/Nodes/PhpGlobalNode.php @@ -5,6 +5,7 @@ namespace T3Docs\GuidesPhpDomain\Nodes; use phpDocumentor\Guides\Nodes\CompoundNode; +use phpDocumentor\Guides\Nodes\LinkTargetNode; use phpDocumentor\Guides\Nodes\Node; /** @@ -12,8 +13,9 @@ * * @extends CompoundNode */ -final class PhpGlobalNode extends CompoundNode +final class PhpGlobalNode extends CompoundNode implements LinkTargetNode { + private const TYPE = 'global'; /** * @param list $value */ @@ -34,4 +36,14 @@ public function getId(): string { return $this->id; } + + public function getLinkType(): string + { + return 'php:' . self::TYPE; + } + + public function getLinkText(): string + { + return $this->getName(); + } } diff --git a/src/TextRoles/GlobalTextRole.php b/src/TextRoles/GlobalTextRole.php new file mode 100644 index 0000000..d5fcf71 --- /dev/null +++ b/src/TextRoles/GlobalTextRole.php @@ -0,0 +1,50 @@ +createNodeWithInterlink($matches[2], $matches[1], $referenceName); + } + return $this->createNodeWithInterlink($referenceTarget, '', $referenceName); + } + + private function createNodeWithInterlink(string $referenceTarget, string $interlinkDomain, string|null $referenceName): ReferenceNode + { + $id = $this->anchorNormalizer->reduceAnchor($referenceTarget); + + return new ReferenceNode($id, $referenceName ?? $referenceTarget, $interlinkDomain, 'php:' . $this->getName()); + } + + public function getName(): string + { + return self::TYPE; + } + + /** + * @return list + */ + public function getAliases(): array + { + return []; + } +} diff --git a/tests/integration/global-link/expected/index.html b/tests/integration/global-link/expected/index.html new file mode 100644 index 0000000..5f19ce7 --- /dev/null +++ b/tests/integration/global-link/expected/index.html @@ -0,0 +1,20 @@ + +
+

PHP Global Variable

+
+
+ global + $GLOBALS['TCA'] + ΒΆ
+
+ +

Contains the TYPO3 Configuration Array

+ +
+
+ +

See also $GLOBALS['TCA'].

+ +
+ diff --git a/tests/integration/global-link/input/index.rst b/tests/integration/global-link/input/index.rst new file mode 100644 index 0000000..81882de --- /dev/null +++ b/tests/integration/global-link/input/index.rst @@ -0,0 +1,9 @@ +=================== +PHP Global Variable +=================== + +.. php:global:: $GLOBALS['TCA'] + + Contains the TYPO3 Configuration Array + +See also :php:global:`$GLOBALS['TCA']`.