Skip to content

Commit

Permalink
=[FEATURE] php domain object struct
Browse files Browse the repository at this point in the history
  • Loading branch information
linawolf committed Dec 9, 2023
1 parent b9a2399 commit b3fc69d
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions resources/config/php-domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use T3Docs\GuidesPhpDomain\Directives\Php\ConstDirective;
use T3Docs\GuidesPhpDomain\Directives\Php\StaticMethodDirective;
use T3Docs\GuidesPhpDomain\Directives\Php\GlobalDirective;
use T3Docs\GuidesPhpDomain\Directives\Php\StructDirective;
use T3Docs\GuidesPhpDomain\PhpDomain\ModifierService;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

Expand Down Expand Up @@ -40,6 +41,7 @@
->set(MethodDirective::class)
->set(NamespaceDirective::class)
->set(StaticMethodDirective::class)
->set(StructDirective::class)
->set(FullyQualifiedNameService::class)
->set(MethodNameService::class)
->set(ModifierService::class)
Expand Down
56 changes: 56 additions & 0 deletions src/Directives/Php/StructDirective.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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\PhpClassNode;
use T3Docs\GuidesPhpDomain\Nodes\PhpInterfaceNode;
use T3Docs\GuidesPhpDomain\Nodes\PhpModifierNode;
use T3Docs\GuidesPhpDomain\Nodes\PhpStructNode;
use T3Docs\GuidesPhpDomain\PhpDomain\FullyQualifiedNameService;
use T3Docs\GuidesPhpDomain\PhpDomain\ModifierService;

final class StructDirective 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:struct';
}

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 PhpStructNode(
$id,
$fqn,
$collectionNode->getChildren(),
null,
[],
);
}
}
25 changes: 25 additions & 0 deletions src/Nodes/PhpStructNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace T3Docs\GuidesPhpDomain\Nodes;

use phpDocumentor\Guides\Nodes\Node;

final class PhpStructNode extends PhpComponentNode
{
private const TYPE = 'struct';
/**
* @param Node $members
* @param Node $value
*/
public function __construct(
string $id,
FullyQualifiedNameNode $name,
array $value = [],
PhpNamespaceNode|null $namespace = null,
array $members = [],
) {
parent::__construct($id, self::TYPE, $name, $value, $namespace, $members);
}
}
20 changes: 20 additions & 0 deletions tests/integration/struct-directive/expected/index.html
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 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
app.WARNING: Directive `.. php:staticmethod::` is deprecated use directive `.. php:method::` with option `:static:` instead. {"rst-file":"index.rst"} []
5 changes: 5 additions & 0 deletions tests/integration/struct-directive/input/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=================
PHP static method
=================

.. php:struct:: Employee

0 comments on commit b3fc69d

Please sign in to comment.