diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 499fcea..00d9a0b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -2,7 +2,7 @@ parameters: ignoreErrors: - message: "#^Function phpDocumentor\\\\Guides\\\\DependencyInjection\\\\template not found\\.$#" - count: 7 + count: 8 path: src/DependencyInjection/GuidesPhpDomainExtension.php - diff --git a/resources/config/php-domain.php b/resources/config/php-domain.php index 75e6cea..095706e 100644 --- a/resources/config/php-domain.php +++ b/resources/config/php-domain.php @@ -8,6 +8,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use T3Docs\GuidesPhpDomain\Directives\Php\ConstDirective; +use T3Docs\GuidesPhpDomain\Directives\Php\GlobalDirective; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; use T3Docs\GuidesPhpDomain\Directives\Php\EnumDirective; @@ -30,6 +31,7 @@ ->tag('phpdoc.guides.directive') ->set(ConstDirective::class) ->set(EnumDirective::class) + ->set(GlobalDirective::class) ->set(InterfaceDirective::class) ->set(MethodDirective::class) ->set(NamespaceDirective::class) diff --git a/resources/template/html/body/directive/php/global.html.twig b/resources/template/html/body/directive/php/global.html.twig new file mode 100644 index 0000000..274a194 --- /dev/null +++ b/resources/template/html/body/directive/php/global.html.twig @@ -0,0 +1,10 @@ +
+
+ global + {{ node.name }} +
+
+ {{ renderNode(node.value) }} +
+
diff --git a/src/DependencyInjection/GuidesPhpDomainExtension.php b/src/DependencyInjection/GuidesPhpDomainExtension.php index a02aaea..91e4d30 100644 --- a/src/DependencyInjection/GuidesPhpDomainExtension.php +++ b/src/DependencyInjection/GuidesPhpDomainExtension.php @@ -14,6 +14,7 @@ use T3Docs\GuidesPhpDomain\Nodes\MethodNameNode; use T3Docs\GuidesPhpDomain\Nodes\PhpComponentNode; use T3Docs\GuidesPhpDomain\Nodes\PhpConstNode; +use T3Docs\GuidesPhpDomain\Nodes\PhpGlobalNode; use T3Docs\GuidesPhpDomain\Nodes\PhpMethodNode; use T3Docs\GuidesPhpDomain\Nodes\PhpNamespaceNode; @@ -42,6 +43,7 @@ public function prepend(ContainerBuilder $container): void 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(PhpGlobalNode::class, 'body/directive/php/global.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'), diff --git a/src/Directives/Php/GlobalDirective.php b/src/Directives/Php/GlobalDirective.php new file mode 100644 index 0000000..f24aced --- /dev/null +++ b/src/Directives/Php/GlobalDirective.php @@ -0,0 +1,47 @@ +addGenericLink($this->getName(), $this->getName()); + } + + public function getName(): string + { + return 'php:global'; + } + + protected function processSub( + BlockContext $blockContext, + CollectionNode $collectionNode, + Directive $directive, + ): Node|null { + $name = trim($directive->getData()); + $id = $this->anchorReducer->reduceAnchor($name); + + return new PhpGlobalNode( + $id, + $name, + $collectionNode->getChildren(), + ); + } +} diff --git a/src/Nodes/PhpGlobalNode.php b/src/Nodes/PhpGlobalNode.php new file mode 100644 index 0000000..35a14f5 --- /dev/null +++ b/src/Nodes/PhpGlobalNode.php @@ -0,0 +1,37 @@ + + */ +final class PhpGlobalNode extends CompoundNode +{ + /** + * @param list $value + */ + public function __construct( + private readonly string $id, + private readonly string $name, + array $value = [], + ) { + parent::__construct($value); + } + + public function getName(): string + { + return $this->name; + } + + public function getId(): string + { + return $this->id; + } +} diff --git a/tests/integration/global-variable/expected/index.html b/tests/integration/global-variable/expected/index.html new file mode 100644 index 0000000..e34b058 --- /dev/null +++ b/tests/integration/global-variable/expected/index.html @@ -0,0 +1,18 @@ + +
+

PHP Global Variable

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

Contains the TYPO3 Configuration Array

+
+
+ +
+ + diff --git a/tests/integration/global-variable/input/index.rst b/tests/integration/global-variable/input/index.rst new file mode 100644 index 0000000..29b8634 --- /dev/null +++ b/tests/integration/global-variable/input/index.rst @@ -0,0 +1,7 @@ +=================== +PHP Global Variable +=================== + +.. php:global:: $GLOBALS['TCA'] + + Contains the TYPO3 Configuration Array