-
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:staticmethod directive
- Loading branch information
Showing
12 changed files
with
168 additions
and
2 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
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 @@ | ||
<span class="sig-name modifier"><span class="pre">{{ node.type }}</span></span> |
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,51 @@ | ||
<?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\PhpMethodNode; | ||
use T3Docs\GuidesPhpDomain\Nodes\PhpModifierNode; | ||
use T3Docs\GuidesPhpDomain\PhpDomain\MethodNameService; | ||
|
||
final class StaticMethodDirective extends SubDirective | ||
{ | ||
public function __construct( | ||
Rule $startingRule, | ||
GenericLinkProvider $genericLinkProvider, | ||
private readonly MethodNameService $methodNameService, | ||
private readonly AnchorReducer $anchorReducer, | ||
) { | ||
parent::__construct($startingRule); | ||
$genericLinkProvider->addGenericLink($this->getName(), $this->getName()); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'php:staticmethod'; | ||
} | ||
|
||
protected function processSub( | ||
BlockContext $blockContext, | ||
CollectionNode $collectionNode, | ||
Directive $directive, | ||
): Node|null { | ||
$name = $this->methodNameService->getMethodName(trim($directive->getData())); | ||
$id = $this->anchorReducer->reduceAnchor($name->toString()); | ||
|
||
return new PhpMethodNode( | ||
$id, | ||
$name, | ||
$collectionNode->getChildren(), | ||
[new PhpModifierNode(PhpModifierNode::STATIC)] | ||
); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace T3Docs\GuidesPhpDomain\Nodes; | ||
|
||
use phpDocumentor\Guides\Nodes\AbstractNode; | ||
use phpDocumentor\Guides\Nodes\Node; | ||
|
||
/** | ||
* Stores data on PHP modifiers for classes, methods, attributes, etc | ||
* @extends AbstractNode<string> | ||
*/ | ||
final class PhpModifierNode extends AbstractNode | ||
{ | ||
public const STATIC = 'static'; | ||
public function __construct( | ||
private readonly string $type, | ||
) { | ||
$this->value = $type; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return $this->type; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/integration/class-with-staticmethod/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,32 @@ | ||
<!-- content start --> | ||
<div class="section" id="php-class-with-static-method"> | ||
<h1>PHP Class with static method</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="dosomething"><span class="sig-name modifier"><span class="pre">static</span></span> | ||
|
||
<span class="sig-name descname"><span class="pre">doSomething</span></span> | ||
<span class="sig-paren">(</span> | ||
<em class="sig-param"><span class="pre">string $whatever</span></em><span class="sig-paren">)</span> | ||
<em class="sig-returns"><span class="pre">: string</span></em> | ||
</dt> | ||
<dd> | ||
<p>Do something</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,11 @@ | ||
============================ | ||
PHP Class with static method | ||
============================ | ||
|
||
.. php:class:: TYPO3\CMS\Core\Test | ||
Lorem Ipsum Dolor! | ||
|
||
.. php:staticmethod:: doSomething(string $whatever): string | ||
Do something |
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,20 @@ | ||
<!-- content start --> | ||
<div class="section" id="php-static-method"> | ||
<h1>PHP static method</h1> | ||
|
||
<dl class="php method"> | ||
<dt class="sig sig-object php" id="dosomething"><span class="sig-name modifier"><span class="pre">static</span></span> | ||
|
||
<span class="sig-name descname"><span class="pre">doSomething</span></span> | ||
<span class="sig-paren">(</span> | ||
<em class="sig-param"><span class="pre">string $whatever</span></em><span class="sig-paren">)</span> | ||
<em class="sig-returns"><span class="pre">: string</span></em> | ||
</dt> | ||
<dd> | ||
<p>Do something</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 static method | ||
================= | ||
|
||
.. php:staticmethod:: doSomething(string $whatever): string | ||
Do something |