Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Make globals linkable #43

Merged
merged 2 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions resources/config/php-domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion src/Nodes/PhpGlobalNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
namespace T3Docs\GuidesPhpDomain\Nodes;

use phpDocumentor\Guides\Nodes\CompoundNode;
use phpDocumentor\Guides\Nodes\LinkTargetNode;
use phpDocumentor\Guides\Nodes\Node;

/**
* Stores data on global PHP variables
*
* @extends CompoundNode<Node>
*/
final class PhpGlobalNode extends CompoundNode
final class PhpGlobalNode extends CompoundNode implements LinkTargetNode
{
private const TYPE = 'global';
/**
* @param list<Node> $value
*/
Expand All @@ -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();
}
}
50 changes: 50 additions & 0 deletions src/TextRoles/GlobalTextRole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace T3Docs\GuidesPhpDomain\TextRoles;

use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
use phpDocumentor\Guides\ReferenceResolvers\AnchorNormalizer;
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContext;
use Psr\Log\LoggerInterface;

final class GlobalTextRole extends PhpComponentTextRole
{
private const TYPE = 'global';

public function __construct(
LoggerInterface $logger,
private readonly AnchorNormalizer $anchorNormalizer,
) {
parent::__construct($logger, $anchorNormalizer);
}

protected function createNode(DocumentParserContext $documentParserContext, string $referenceTarget, string|null $referenceName, string $role): ReferenceNode
{
if (preg_match(self::INTERLINK_NAME_REGEX, $referenceTarget, $matches)) {
return $this->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<string>
*/
public function getAliases(): array
{
return [];
}
}
14 changes: 5 additions & 9 deletions tests/integration/class-abstract/expected/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<!-- content start -->
<div class="section" id="abstract-class">
<h1>abstract class</h1>

<dl class="php class">
<dt class="sig sig-object php"
id="typo3-cms-core-abstracttest">
<span class="sig-name modifier"><span class="pre">abstract</span></span>
<em class="property"><span class="pre">class</span> </em>
<span class="sig-name modifier"><span class="pre">abstract</span></span> <em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">AbstractTest</span></span>
<a class="headerlink" href="#typo3-cms-core-abstracttest" title="Permalink to this definition">¶</a>
</dt>
<span class="sig-name descname"><span class="pre">AbstractTest</span></span><a class="headerlink" href="#typo3-cms-core-abstracttest" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>Lorem Ipsum Dolor!</p>

<p>Lorem Ipsum Dolor!</p>

</dd>
</dl>

</div>

<!-- content end -->
15 changes: 5 additions & 10 deletions tests/integration/class-final-abstract/expected/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<!-- content start -->
<div class="section" id="abstract-final-class-causes-warning">
<h1>abstract final class causes warning</h1>

<dl class="php class">
<dt class="sig sig-object php"
id="typo3-cms-core-test">
<span class="sig-name modifier"><span class="pre">abstract</span></span>
<span class="sig-name modifier"><span class="pre">final</span></span>
<em class="property"><span class="pre">class</span> </em>
<span class="sig-name modifier"><span class="pre">abstract</span></span> <span class="sig-name modifier"><span class="pre">final</span></span> <em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">Test</span></span>
<a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition">¶</a>
</dt>
<span class="sig-name descname"><span class="pre">Test</span></span><a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>Lorem Ipsum Dolor!</p>

<p>Lorem Ipsum Dolor!</p>

</dd>
</dl>

</div>

<!-- content end -->
14 changes: 5 additions & 9 deletions tests/integration/class-final/expected/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<!-- content start -->
<div class="section" id="final-class">
<h1>final class</h1>

<dl class="php class">
<dt class="sig sig-object php"
id="typo3-cms-core-test">
<span class="sig-name modifier"><span class="pre">final</span></span>
<em class="property"><span class="pre">class</span> </em>
<span class="sig-name modifier"><span class="pre">final</span></span> <em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">Test</span></span>
<a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition">¶</a>
</dt>
<span class="sig-name descname"><span class="pre">Test</span></span><a class="headerlink" href="#typo3-cms-core-test" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>Lorem Ipsum Dolor!</p>

<p>Lorem Ipsum Dolor!</p>

</dd>
</dl>

</div>

<!-- content end -->
29 changes: 12 additions & 17 deletions tests/integration/class-namespace-directive/expected/index.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
<!-- content start -->
<div class="section" id="php-class-with-current-namespace-from-directive">
<h1>PHP Class with current namespace from directive</h1>

<dl class="php class">
<dt class="sig sig-object php"
id="typo3-cms-core-testclass">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">TestClass</span></span>
<a class="headerlink" href="#typo3-cms-core-testclass" title="Permalink to this definition">¶</a>
</dt>
<span class="sig-name descname"><span class="pre">TestClass</span></span><a class="headerlink" href="#typo3-cms-core-testclass" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>Lorem Ipsum Dolor!</p>

<p>Lorem Ipsum Dolor!</p>

</dd>
</dl>

<dl class="php class">
<dt class="sig sig-object php"
id="typo3-cms-core-anotherclass">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\TYPO3\CMS\Core\</span></span>
<span class="sig-name descname"><span class="pre">AnotherClass</span></span>
<a class="headerlink" href="#typo3-cms-core-anotherclass" title="Permalink to this definition">¶</a>
</dt>
<span class="sig-name descname"><span class="pre">AnotherClass</span></span><a class="headerlink" href="#typo3-cms-core-anotherclass" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>Lorem Ipsum Dolor Another!</p>

<p>Lorem Ipsum Dolor Another!</p>

</dd>
</dl>

<dl class="php class">
<dt class="sig sig-object php"
id="myvendor-some-namespace-anotherclass">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\MyVendor\Some\Namespace\</span></span>
<span class="sig-name descname"><span class="pre">AnotherClass</span></span>
<a class="headerlink" href="#myvendor-some-namespace-anotherclass" title="Permalink to this definition">¶</a>
</dt>
<span class="sig-name descname"><span class="pre">AnotherClass</span></span><a class="headerlink" href="#myvendor-some-namespace-anotherclass" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>Lorem Ipsum Dolor Yet Another!</p>

<p>Lorem Ipsum Dolor Yet Another!</p>

</dd>
</dl>

</div>

<!-- content end -->
Original file line number Diff line number Diff line change
@@ -1,56 +1,44 @@
<!-- content start -->
<div class="section" id="php-class-with-constants">
<h1>PHP class with constants</h1>

<dl class="php class">
<dt class="sig sig-object php"
id="chucklefactory-funclass">
<em class="property"><span class="pre">class</span> </em>
<span class="sig-prename descclassname"><span class="pre">\ChuckleFactory\</span></span>
<span class="sig-name descname"><span class="pre">FunClass</span></span>
<a class="headerlink" href="#chucklefactory-funclass" title="Permalink to this definition">¶</a>
</dt>
<span class="sig-name descname"><span class="pre">FunClass</span></span><a class="headerlink" href="#chucklefactory-funclass" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>Where Fun Knows No Bounds!</p><dl class="php const">
<dt class="sig sig-object php" id="chucklefactory-funclass-joy-constant">
<span class="sig-name modifier"><span class="pre">public</span></span>
<span class="sig-name modifier"><span class="pre">private</span></span>
<em class="property"><span class="pre">const</span></em>
<span class="sig-name descname"><span class="pre">JOY_CONSTANT</span></span>

<a class="headerlink" href="#chucklefactory-funclass-joy-constant" title="Permalink to this definition">¶</a>
</dt>
<dd><p>The constant that encapsulates pure joy and laughter. Whenever you need
a pick-me-up, just access JOY_CONSTANT and let the chuckles begin.</p></dd>
</dl>
<p>Where Fun Knows No Bounds!</p>
<dl class="php const">
<dt class="sig sig-object php" id="chucklefactory-funclass-joy-constant">
<span class="sig-name modifier"><span class="pre">public</span></span> <span class="sig-name modifier"><span class="pre">private</span></span> <em class="property"><span class="pre">const</span></em>
<span class="sig-name descname"><span class="pre">JOY_CONSTANT</span></span>
<a class="headerlink" href="#chucklefactory-funclass-joy-constant" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>The constant that encapsulates pure joy and laughter. Whenever you need
a pick-me-up, just access JOY_CONSTANT and let the chuckles begin.</p>
</dd>
</dl><dl class="php const">
<dt class="sig sig-object php" id="chucklefactory-funclass-giggle-factor">
<span class="sig-name modifier"><span class="pre">public</span></span>
<span class="sig-name modifier"><span class="pre">protected</span></span>
<em class="property"><span class="pre">const</span></em>
<span class="sig-name modifier"><span class="pre">public</span></span> <span class="sig-name modifier"><span class="pre">protected</span></span> <em class="property"><span class="pre">const</span></em>
<span class="sig-name descname"><span class="pre">GIGGLE_FACTOR</span></span>

<a class="headerlink" href="#chucklefactory-funclass-giggle-factor" title="Permalink to this definition">¶</a>
</dt>
<dd><p>A dynamic constant that measures the giggle intensity in the ChuckleFactory.
It&#039;s known to spontaneously increase during code reviews and coffee breaks.</p></dd>
</dl>
<dl class="php const">
<a class="headerlink" href="#chucklefactory-funclass-giggle-factor" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>A dynamic constant that measures the giggle intensity in the ChuckleFactory.
It&#039;s known to spontaneously increase during code reviews and coffee breaks.</p>
</dd>
</dl><dl class="php const">
<dt class="sig sig-object php" id="chucklefactory-funclass-whimsical-wonder">
<span class="sig-name modifier"><span class="pre">protected</span></span>
<span class="sig-name modifier"><span class="pre">private</span></span>
<em class="property"><span class="pre">const</span></em>
<span class="sig-name modifier"><span class="pre">protected</span></span> <span class="sig-name modifier"><span class="pre">private</span></span> <em class="property"><span class="pre">const</span></em>
<span class="sig-name descname"><span class="pre">WHIMSICAL_WONDER</span></span>

<a class="headerlink" href="#chucklefactory-funclass-whimsical-wonder" title="Permalink to this definition">¶</a>
</dt>
<dd><p>Unleash the power of whimsy! This constant is your key to unlocking the
whimsical wonders hidden within the FunClass. Expect surprises and delight!</p></dd>
<a class="headerlink" href="#chucklefactory-funclass-whimsical-wonder" title="Permalink to this definition">¶</a> </dt>
<dd>
<p>Unleash the power of whimsy! This constant is your key to unlocking the
whimsical wonders hidden within the FunClass. Expect surprises and delight!</p>
</dd>
</dl>

</dd>
</dl>

</div>

<!-- content end -->
Loading
Loading