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

[FEATURE] php domain object struct #22

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions resources/config/php-domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use T3Docs\GuidesPhpDomain\Directives\Php\PropertyDirective;
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 @@ -45,6 +46,7 @@
->set(NamespaceDirective::class)
->set(PropertyDirective::class)
->set(StaticMethodDirective::class)
->set(StructDirective::class)
->set(FullyQualifiedNameService::class)
->set(MethodNameService::class)
->set(ModifierService::class)
Expand Down
57 changes: 57 additions & 0 deletions src/Directives/Php/StructDirective.php
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\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,
[],
);
}
}
26 changes: 26 additions & 0 deletions src/Nodes/PhpStructNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace T3Docs\GuidesPhpDomain\Nodes;

use phpDocumentor\Guides\Nodes\Node;

final class PhpStructNode extends PhpComponentNode
{
private const TYPE = 'struct';

/**
* @param list<Node> $value
* @param list<PhpMemberNode> $members
*/
public function __construct(
string $id,
FullyQualifiedNameNode $name,
array $value = [],
PhpNamespaceNode|null $namespace = null,
array $members = [],
) {
parent::__construct($id, self::TYPE, $name, $value, $namespace, $members);
}
}
48 changes: 48 additions & 0 deletions tests/integration/struct-directive/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!-- content start -->
<div class="section" id="php-static-method">
<h1>PHP static method</h1>

<dl class="php struct">
<dt class="sig sig-object php"
id="app-accounting-employee">
<em class="property"><span class="pre">struct</span> </em>
<span class="sig-prename descclassname"><span class="pre">\App\Accounting\</span></span>
<span class="sig-name descname"><span class="pre">Employee</span></span>

</dt>
<dd>
<dl class="php property">
<dt class="sig sig-object php" id="firstname">
<span class="pre">string</span> <span class="sig-name descname"><span class="pre">firstName</span></span>

</dt>
<dd></dd>
</dl>
<dl class="php property">
<dt class="sig sig-object php" id="lastname">
<span class="pre">string</span> <span class="sig-name descname"><span class="pre">lastName</span></span>

</dt>
<dd></dd>
</dl>
<dl class="php property">
<dt class="sig sig-object php" id="salary">
<span class="pre">int</span> <span class="sig-name descname"><span class="pre">salary</span></span>

</dt>
<dd></dd>
</dl>
<dl class="php property">
<dt class="sig sig-object php" id="fulltime">
<span class="pre">bool</span> <span class="sig-name descname"><span class="pre">fullTime</span></span>

</dt>
<dd></dd>
</dl>

</dd>
</dl>

</div>

<!-- content end -->
19 changes: 19 additions & 0 deletions tests/integration/struct-directive/input/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=================
PHP static method
=================

.. php:namespace:: App\Accounting

.. php:struct:: Employee

.. php:property:: firstName
:type: string

.. php:property:: lastName
:type: string

.. php:property:: salary
:type: int

.. php:property:: fullTime
:type: bool