-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Introduce php:class directive (#11)
* [FEATURE] Introduce php:class directive visibility and other modifiers and the textrole come in a followup * Update tests/integration/class-with-method/input/index.rst Co-authored-by: Chris Müller <2566282+brotkrueml@users.noreply.github.com> --------- Co-authored-by: Chris Müller <2566282+brotkrueml@users.noreply.github.com>
- Loading branch information
1 parent
e951aff
commit cc00776
Showing
9 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace T3Docs\GuidesPhpDomain\Directives\Php; | ||
|
||
use phpDocumentor\Guides\Nodes\CollectionNode; | ||
use phpDocumentor\Guides\Nodes\Node; | ||
use phpDocumentor\Guides\ReferenceResolvers\AnchorReducer; | ||
use phpDocumentor\Guides\RestructuredText\Directives\SubDirective; | ||
use phpDocumentor\Guides\RestructuredText\Parser\BlockContext; | ||
use phpDocumentor\Guides\RestructuredText\Parser\Directive; | ||
use phpDocumentor\Guides\RestructuredText\Parser\Productions\Rule; | ||
use phpDocumentor\Guides\RestructuredText\TextRoles\GenericLinkProvider; | ||
use T3Docs\GuidesPhpDomain\Nodes\PhpClassNode; | ||
use T3Docs\GuidesPhpDomain\Nodes\PhpInterfaceNode; | ||
use T3Docs\GuidesPhpDomain\PhpDomain\FullyQualifiedNameService; | ||
|
||
final class ClassDirective extends SubDirective | ||
{ | ||
public function __construct( | ||
Rule $startingRule, | ||
GenericLinkProvider $genericLinkProvider, | ||
private readonly FullyQualifiedNameService $fullyQualifiedNameService, | ||
private readonly AnchorReducer $anchorReducer, | ||
) { | ||
parent::__construct($startingRule); | ||
$genericLinkProvider->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, | ||
[], | ||
[], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace T3Docs\GuidesPhpDomain\Nodes; | ||
|
||
use phpDocumentor\Guides\Nodes\Node; | ||
|
||
final class PhpClassNode extends PhpComponentNode | ||
{ | ||
private const TYPE = 'class'; | ||
/** | ||
* @param list<PhpMemberNode> $members | ||
* @param list<string> $modifiers | ||
* @param list<Node> $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); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/integration/class-namespace-directive/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!-- 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> | ||
|
||
</dt> | ||
<dd> | ||
<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> | ||
|
||
</dt> | ||
<dd> | ||
<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> | ||
|
||
</dt> | ||
<dd> | ||
<p>Lorem Ipsum Dolor Yet Another!</p> | ||
</dd> | ||
</dl> | ||
|
||
</div> | ||
|
||
<!-- content end --> |
17 changes: 17 additions & 0 deletions
17
tests/integration/class-namespace-directive/input/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!-- content start --> | ||
<div class="section" id="php-class-with-explicit-namespace"> | ||
<h1>PHP Class with explicit namespace</h1> | ||
|
||
<dl class="php class"> | ||
<dt class="sig sig-object php" | ||
id="typo3-cms-core-test"> | ||
<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> | ||
|
||
</dt> | ||
<dd> | ||
<p>Lorem Ipsum Dolor!</p><dl class="php method"> | ||
<dt class="sig sig-object php" id="setdate"> | ||
|
||
<span class="sig-name descname"><span class="pre">setDate</span></span> | ||
<span class="sig-paren">(</span> | ||
<em class="sig-param"><span class="pre">int $year</span></em>, <em class="sig-param"><span class="pre">int $month</span></em>, <em class="sig-param"><span class="pre">int $day</span></em><span class="sig-paren">)</span> | ||
|
||
</dt> | ||
<dd> | ||
<p>Set the date.</p> | ||
</dd> | ||
</dl> | ||
<dl class="php method"> | ||
<dt class="sig sig-object php" id="getdate"> | ||
|
||
<span class="sig-name descname"><span class="pre">getDate</span></span> | ||
<span class="sig-paren">(</span> | ||
<span class="sig-paren">)</span> | ||
<em class="sig-returns"><span class="pre">: int</span></em> | ||
|
||
</dt> | ||
<dd> | ||
<p>Get the date.</p> | ||
</dd> | ||
</dl> | ||
|
||
</dd> | ||
</dl> | ||
|
||
</div> | ||
|
||
<!-- content end --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
19 changes: 19 additions & 0 deletions
19
tests/integration/class-without-namespace/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- content start --> | ||
<div class="section" id="php-class"> | ||
<h1>PHP Class</h1> | ||
|
||
<dl class="php class"> | ||
<dt class="sig sig-object php" | ||
id="testclass"> | ||
<em class="property"><span class="pre">class</span> </em> | ||
<span class="sig-name descname"><span class="pre">TestClass</span></span> | ||
|
||
</dt> | ||
<dd> | ||
<p>Lorem Ipsum Dolor!</p> | ||
</dd> | ||
</dl> | ||
|
||
</div> | ||
|
||
<!-- content end --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
========= | ||
PHP Class | ||
========= | ||
|
||
.. php:class:: TestClass | ||
Lorem Ipsum Dolor! |