-
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 case and backed enums
- Loading branch information
Showing
16 changed files
with
345 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<dl class="php case"> | ||
<dt class="sig sig-object php" id="{{ node.id }}"> | ||
<em class="property"><span class="pre">case</span></em> | ||
{{ renderNode(node.memberName) }} : {% if node.backedValue -%}<span class="pre">{{ node.backedValue }}</span> {% endif -%} | ||
</dt> | ||
<dd>{{ renderNode(node.value) }}</dd> | ||
</dl> |
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,57 @@ | ||
<?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 Psr\Log\LoggerInterface; | ||
use T3Docs\GuidesPhpDomain\Nodes\MemberNameNode; | ||
use T3Docs\GuidesPhpDomain\Nodes\PhpCaseNode; | ||
use T3Docs\GuidesPhpDomain\Nodes\PhpConstNode; | ||
use T3Docs\GuidesPhpDomain\PhpDomain\ModifierService; | ||
|
||
final class CaseDirective extends SubDirective | ||
{ | ||
public function __construct( | ||
Rule $startingRule, | ||
GenericLinkProvider $genericLinkProvider, | ||
private readonly AnchorReducer $anchorReducer, | ||
) { | ||
parent::__construct($startingRule); | ||
$genericLinkProvider->addGenericLink($this->getName(), $this->getName()); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'php:case'; | ||
} | ||
|
||
protected function processSub( | ||
BlockContext $blockContext, | ||
CollectionNode $collectionNode, | ||
Directive $directive, | ||
): Node|null { | ||
$name = new MemberNameNode(trim($directive->getData())); | ||
$id = $this->anchorReducer->reduceAnchor($name->toString()); | ||
|
||
$value = null; | ||
if ($directive->hasOption('value')) { | ||
$value = $directive->getOption('value')->toString(); | ||
} | ||
|
||
return new PhpCaseNode( | ||
$id, | ||
$name, | ||
$collectionNode->getChildren(), | ||
$value, | ||
); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace T3Docs\GuidesPhpDomain\Nodes; | ||
|
||
use phpDocumentor\Guides\Nodes\Node; | ||
|
||
final class PhpCaseNode extends PhpMemberNode | ||
{ | ||
private const TYPE = 'const'; | ||
|
||
/** | ||
* @param Node[] $value | ||
*/ | ||
public function __construct( | ||
string $id, | ||
private readonly MemberNameNode $memberName, | ||
array $value = [], | ||
private readonly string|null $backedValue = null, | ||
) { | ||
parent::__construct($id, self::TYPE, $memberName->toString(), $value); | ||
} | ||
|
||
public function getMemberName(): MemberNameNode | ||
{ | ||
return $this->memberName; | ||
} | ||
|
||
public function getBackedValue(): ?string | ||
{ | ||
return $this->backedValue; | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
tests/integration/enum-backed-with-cases/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,33 @@ | ||
<!-- content start --> | ||
<div class="section" id="php-enum-with-const"> | ||
<h1>PHP Enum with Const</h1> | ||
|
||
<dl class="php enum"> | ||
<dt class="sig sig-object php" | ||
id="redsuit"> | ||
<em class="property"><span class="pre">enum</span> </em> | ||
<span class="sig-name descname"><span class="pre">RedSuit</span></span> | ||
<span class="pre"> : string</span> </dt> | ||
<dd> | ||
<p>In playing cards, a suit is one of the categories into which the | ||
cards of a deck are divided.</p><dl class="php case"> | ||
<dt class="sig sig-object php" id="hearts"> | ||
<em class="property"><span class="pre">case</span></em> | ||
<span class="sig-name descname"><span class="pre">Hearts</span></span> | ||
: <span class="pre">'H'</span> </dt> | ||
<dd><p>Hearts is one of the four suits in playing cards.</p></dd> | ||
</dl> | ||
<dl class="php case"> | ||
<dt class="sig sig-object php" id="diamonds"> | ||
<em class="property"><span class="pre">case</span></em> | ||
<span class="sig-name descname"><span class="pre">Diamonds</span></span> | ||
: <span class="pre">'D'</span> </dt> | ||
<dd><p>Diamonds is one of the four suits in playing cards.</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,19 @@ | ||
=================== | ||
PHP Enum with Const | ||
=================== | ||
|
||
.. php:enum:: RedSuit | ||
:type: string | ||
|
||
In playing cards, a suit is one of the categories into which the | ||
cards of a deck are divided. | ||
|
||
.. php:case:: Hearts | ||
:value: 'H' | ||
|
||
Hearts is one of the four suits in playing cards. | ||
|
||
.. php:case:: Diamonds | ||
:value: 'D' | ||
|
||
Diamonds is one of the four suits in playing cards. |
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,48 @@ | ||
<!-- content start --> | ||
<div class="section" id="php-enum-with-const"> | ||
<h1>PHP Enum with Const</h1> | ||
|
||
<dl class="php enum"> | ||
<dt class="sig sig-object php" | ||
id="suit"> | ||
<em class="property"><span class="pre">enum</span> </em> | ||
<span class="sig-name descname"><span class="pre">Suit</span></span> | ||
|
||
</dt> | ||
<dd> | ||
<p>In playing cards, a suit is one of the categories into which the | ||
cards of a deck are divided.</p><dl class="php case"> | ||
<dt class="sig sig-object php" id="hearts"> | ||
<em class="property"><span class="pre">case</span></em> | ||
<span class="sig-name descname"><span class="pre">Hearts</span></span> | ||
: </dt> | ||
<dd><p>Hearts is one of the four suits in playing cards.</p></dd> | ||
</dl> | ||
<dl class="php case"> | ||
<dt class="sig sig-object php" id="diamonds"> | ||
<em class="property"><span class="pre">case</span></em> | ||
<span class="sig-name descname"><span class="pre">Diamonds</span></span> | ||
: </dt> | ||
<dd><p>Diamonds is one of the four suits in playing cards.</p></dd> | ||
</dl> | ||
<dl class="php case"> | ||
<dt class="sig sig-object php" id="clubs"> | ||
<em class="property"><span class="pre">case</span></em> | ||
<span class="sig-name descname"><span class="pre">Clubs</span></span> | ||
: </dt> | ||
<dd><p>Clubs is one of the four suits in playing cards.</p></dd> | ||
</dl> | ||
<dl class="php case"> | ||
<dt class="sig sig-object php" id="spades"> | ||
<em class="property"><span class="pre">case</span></em> | ||
<span class="sig-name descname"><span class="pre">Spades</span></span> | ||
: </dt> | ||
<dd><p>Spades is one of the four suits in playing cards.</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,24 @@ | ||
=================== | ||
PHP Enum with Const | ||
=================== | ||
|
||
.. php:enum:: Suit | ||
In playing cards, a suit is one of the categories into which the | ||
cards of a deck are divided. | ||
|
||
.. php:case:: Hearts | ||
Hearts is one of the four suits in playing cards. | ||
|
||
.. php:case:: Diamonds | ||
Diamonds is one of the four suits in playing cards. | ||
|
||
.. php:case:: Clubs | ||
Clubs is one of the four suits in playing cards. | ||
|
||
.. php:case:: Spades | ||
Spades is one of the four suits in playing cards. |
Oops, something went wrong.