Skip to content

Commit 5acd7f5

Browse files
authored
Merge branch 'main' into feature/external-menu
2 parents c29676e + 21fa962 commit 5acd7f5

File tree

12 files changed

+115
-32
lines changed

12 files changed

+115
-32
lines changed

docs/contributions/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ Contributions
77
Clone the mono repository
88
=========================
99

10+
This project uses a :doc:`mono repository </contributions/monorepository-layout>`,
11+
meaning a single git repository regroups several different Composer packages,
12+
built from several git repositories split from this repository.
13+
Contributions need to be made against that mono repository.
14+
15+
To clone the repository, run the following command::
16+
17+
git clone [email protected]:phpDocumentor/guides.git
18+
1019
Run the tests
1120
=============
1221

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. include:: /include.rst.txt
2+
3+
===============
4+
Mono repository
5+
===============
6+
7+
This project uses a mono repository approach. This means that all the
8+
development happens in a single repository, later split into multiple
9+
repositories for distribution.
10+
11+
Consequences:
12+
13+
- The mono repository is not installable as a Composer package, and its
14+
``composer.json`` file is not even valid because there is no package
15+
name. Its purpose is to help installing development dependencies, and
16+
dependencies of each component.
17+
- The ``require`` section of the root ``composer.json`` file should only
18+
contain the list of the components.
19+
- The ``autoload-dev`` section of the root ``composer.json`` file should
20+
make all the components's test support code available.
21+
- The ``require-dev`` section of the root ``composer.json`` file of
22+
components should only be used to mention optional dependencies, and
23+
not actual development dependencies.
24+
- Issues and pull requests should be opened in the mono repository, and
25+
not in the component repositories.
26+
27+
The components are located under the ``packages`` directory.

packages/guides-graphs/src/Graphs/Renderer/PlantumlRenderer.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace phpDocumentor\Guides\Graphs\Renderer;
1515

1616
use Psr\Log\LoggerInterface;
17+
use Symfony\Component\Process\Exception\RuntimeException;
1718
use Symfony\Component\Process\Process;
1819

1920
use function file_get_contents;
@@ -44,12 +45,17 @@ public function render(string $diagram): string|null
4445

4546
$pumlFileLocation = tempnam(sys_get_temp_dir() . '/phpdocumentor', 'pu_');
4647
file_put_contents($pumlFileLocation, $output);
48+
try {
49+
$process = new Process([$this->plantUmlBinaryPath, '-tsvg', $pumlFileLocation], __DIR__, null, null, 600.0);
50+
$process->run();
4751

48-
$process = new Process([$this->plantUmlBinaryPath, '-tsvg', $pumlFileLocation], __DIR__, null, null, 600.0);
49-
$process->run();
52+
if (!$process->isSuccessful()) {
53+
$this->logger->error('Generating the class diagram failed', ['error' => $process->getErrorOutput()]);
5054

51-
if (!$process->isSuccessful()) {
52-
$this->logger->error('Generating the class diagram failed', ['error' => $process->getErrorOutput()]);
55+
return null;
56+
}
57+
} catch (RuntimeException $e) {
58+
$this->logger->error('Generating the class diagram failed', ['error' => $e->getMessage()]);
5359

5460
return null;
5561
}

packages/guides-restructured-text/resources/config/guides-restructured-text.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
use phpDocumentor\Guides\RestructuredText\MarkupLanguageParser;
5757
use phpDocumentor\Guides\RestructuredText\Parser\DocumentParserContextFactory;
5858
use phpDocumentor\Guides\RestructuredText\Parser\InlineParser;
59+
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\DefaultInterlinkParser;
60+
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;
5961
use phpDocumentor\Guides\RestructuredText\Parser\Productions\AnnotationRule;
6062
use phpDocumentor\Guides\RestructuredText\Parser\Productions\BlockQuoteRule;
6163
use phpDocumentor\Guides\RestructuredText\Parser\Productions\CommentRule;
@@ -232,6 +234,8 @@
232234
->set('phpdoc.guides.parser.rst.body_elements', RuleContainer::class)
233235
->set('phpdoc.guides.parser.rst.structural_elements', RuleContainer::class)
234236

237+
->set(InterlinkParser::class, DefaultInterlinkParser::class)
238+
235239
->set(AnnotationRule::class)
236240
->tag('phpdoc.guides.parser.rst.body_element', ['priority' => AnnotationRule::PRIORITY])
237241
->set(LinkRule::class)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Guides\RestructuredText\Parser\Interlink;
6+
7+
use function preg_match;
8+
9+
final class DefaultInterlinkParser implements InterlinkParser
10+
{
11+
/** @see https://regex101.com/r/htMn5p/1 */
12+
private const INTERLINK_REGEX = '/^([a-zA-Z0-9-_]+):(.*$)/';
13+
14+
public function extractInterlink(string $fullReference): InterlinkData
15+
{
16+
if (!preg_match(self::INTERLINK_REGEX, $fullReference, $matches)) {
17+
return new InterlinkData($fullReference, '');
18+
}
19+
20+
return new InterlinkData($matches[2], $matches[1] ?? '');
21+
}
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Guides\RestructuredText\Parser\Interlink;
6+
7+
class InterlinkData
8+
{
9+
public function __construct(
10+
public readonly string $reference,
11+
public readonly string $interlink,
12+
) {
13+
}
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace phpDocumentor\Guides\RestructuredText\Parser\Interlink;
6+
7+
interface InterlinkParser
8+
{
9+
public function extractInterlink(string $fullReference): InterlinkData;
10+
}

packages/guides-restructured-text/src/RestructuredText/TextRoles/AbstractReferenceTextRole.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ abstract class AbstractReferenceTextRole implements TextRole
1313
{
1414
use EmbeddedUriParser;
1515

16-
/** @see https://regex101.com/r/htMn5p/1 */
17-
public const INTERLINK_REGEX = '/^([a-zA-Z0-9-_]+):(.*$)/';
18-
1916
public function processNode(
2017
DocumentParserContext $documentParserContext,
2118
string $role,

packages/guides-restructured-text/src/RestructuredText/TextRoles/DocReferenceTextRole.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66

77
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
88
use phpDocumentor\Guides\Nodes\Inline\DocReferenceNode;
9-
10-
use function preg_match;
9+
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;
1110

1211
class DocReferenceTextRole extends AbstractReferenceTextRole
1312
{
1413
final public const NAME = 'doc';
1514

15+
public function __construct(
16+
private readonly InterlinkParser $interlinkParser,
17+
) {
18+
}
19+
1620
public function getName(): string
1721
{
1822
return self::NAME;
@@ -27,15 +31,8 @@ public function getAliases(): array
2731
/** @return DocReferenceNode */
2832
protected function createNode(string $referenceTarget, string|null $referenceName, string $role): AbstractLinkInlineNode
2933
{
30-
$pattern = AbstractReferenceTextRole::INTERLINK_REGEX;
31-
if (preg_match($pattern, $referenceTarget, $matches)) {
32-
$interlinkDomain = $matches[1];
33-
$path = $matches[2];
34-
} else {
35-
$interlinkDomain = '';
36-
$path = $referenceTarget;
37-
}
38-
39-
return new DocReferenceNode($path, $referenceName ?? '', $interlinkDomain);
34+
$interlinkData = $this->interlinkParser->extractInterlink($referenceTarget);
35+
36+
return new DocReferenceNode($interlinkData->reference, $referenceName ?? '', $interlinkData->interlink);
4037
}
4138
}

packages/guides-restructured-text/src/RestructuredText/TextRoles/GenericReferenceTextRole.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
use phpDocumentor\Guides\Nodes\Inline\AbstractLinkInlineNode;
88
use phpDocumentor\Guides\Nodes\Inline\ReferenceNode;
99
use phpDocumentor\Guides\ReferenceResolvers\AnchorReducer;
10+
use phpDocumentor\Guides\RestructuredText\Parser\Interlink\InterlinkParser;
1011

1112
use function array_keys;
12-
use function preg_match;
1313

1414
class GenericReferenceTextRole extends AbstractReferenceTextRole
1515
{
1616
public function __construct(
1717
private readonly GenericLinkProvider $genericLinkProvider,
1818
private readonly AnchorReducer $anchorReducer,
19+
private readonly InterlinkParser $interlinkParser,
1920
) {
2021
}
2122

@@ -34,15 +35,9 @@ public function getAliases(): array
3435
protected function createNode(string $referenceTarget, string|null $referenceName, string $role): AbstractLinkInlineNode
3536
{
3637
$linkType = $this->genericLinkProvider->getLinkType($role);
37-
$pattern = '/^([a-zA-Z0-9]+):(.*$)/';
38-
if (preg_match(AbstractReferenceTextRole::INTERLINK_REGEX, $referenceTarget, $matches)) {
39-
$interlinkDomain = $matches[1];
40-
$id = $this->anchorReducer->reduceAnchor($matches[2]);
41-
} else {
42-
$interlinkDomain = '';
43-
$id = $this->anchorReducer->reduceAnchor($referenceTarget);
44-
}
45-
46-
return new ReferenceNode($id, $referenceName ?? '', $interlinkDomain, $linkType);
38+
$interlinkData = $this->interlinkParser->extractInterlink($referenceTarget);
39+
$reference = $this->anchorReducer->reduceAnchor($interlinkData->reference);
40+
41+
return new ReferenceNode($reference, $referenceName ?? '', $interlinkData->interlink, $linkType);
4742
}
4843
}

0 commit comments

Comments
 (0)