Skip to content
Merged
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"phpdocumentor/guides-markdown": "^1.0 || ^1.0@dev",
"phpdocumentor/guides-restructured-text": "^1.0 || ^1.0@dev",
"phpdocumentor/guides-theme-bootstrap": "^1.0 || ^1.0@dev",
"phpdocumentor/guides-theme-rst": "^1.0 || ^1.0@dev"
"phpdocumentor/guides-theme-rst": "^1.0 || ^1.0@dev",
"symfony/polyfill-php84": "^1.33"
},
"require-dev": {
"ext-dom": "*",
Expand Down
658 changes: 399 additions & 259 deletions composer.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions packages/guides-cli/src/DevServer/RerenderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
use phpDocumentor\Guides\Settings\ProjectSettings;
use Symfony\Component\Console\Output\OutputInterface;

use function array_find_key;
use function assert;
use function current;
use function sprintf;
use function substr;

final class RerenderListener
{
/** @param array<string, DocumentNode> $documents */
/** @param DocumentNode[] $documents */
public function __construct(
private readonly OutputInterface $output,
private readonly CommandBus $commandBus,
Expand Down Expand Up @@ -72,7 +74,16 @@ public function __invoke(FileModifiedEvent $event): void

/** @var array<string, DocumentNode> $documents */
$documents = $this->commandBus->handle(new CompileDocumentsCommand([$file => $document], new CompilerContext($this->projectNode)));
$this->documents[$file] = $documents[$file];
$key = array_find_key($this->documents, static fn (DocumentNode $entry) => $entry->getFilePath() === $document->getFilePath());
$document = current($documents);
assert($document instanceof DocumentNode);
if ($key === null) {
// If the document is new, we add it to the list with its file path as key
$this->documents[] = $document;
} else {
$this->documents[$key] = $document;
}

$destinationFileSystem = FlySystemAdapter::createForPath($this->settings->getOutput());

$documentIterator = DocumentListIterator::create(
Expand Down
2 changes: 1 addition & 1 deletion packages/guides-restructured-text/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"doctrine/lexer": "^3.0",
"phpdocumentor/guides": "^1.0 || ^2.0",
"webmozart/assert": "^1.11",
"league/csv": "^9.10.0"
"league/csv": "^9.27.0"
},
"extra": {
"branch-alias": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use function explode;
use function implode;
use function is_string;
use function method_exists;
use function strval;
use function trim;

Expand Down Expand Up @@ -79,18 +78,10 @@ public function processNode(
return new GenericNode('csv-table');
}

if (method_exists(Reader::class, 'from')) {
$csv = Reader::from($csvStream);
} else {
$csv = Reader::createFromStream($csvStream);
}
$csv = Reader::from($csvStream);
} else {
$lines = $blockContext->getDocumentIterator()->toArray();
if (method_exists(Reader::class, 'fromString')) {
$csv = Reader::fromString(implode("\n", $lines));
} else {
$csv = Reader::createFromString(implode("\n", $lines));
}
$csv = Reader::fromString(implode("\n", $lines));
}

if ($directive->getOption('header-rows')->getValue() !== null) {
Expand All @@ -99,11 +90,7 @@ public function processNode(

$header = null;
if ($directive->hasOption('header')) {
if (method_exists(Reader::class, 'fromString')) {
$headerCsv = Reader::fromString($directive->getOption('header')->toString());
} else {
$headerCsv = Reader::createFromString($directive->getOption('header')->toString());
}
$headerCsv = Reader::fromString($directive->getOption('header')->toString());

$header = new TableRow();
foreach ($headerCsv->first() as $column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ private function parseField(string $line): array
{
if (preg_match('/^:([^:]+):( (.*)|)$/mUsi', $line, $match) > 0) {
return [
$match[1] ?? '',
$match[2] ?? '',
$match[1],
$match[2],
];
}

Expand Down
1 change: 1 addition & 0 deletions packages/guides/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"symfony/clock": "^6.4.8",
"symfony/html-sanitizer": "^6.4.8",
"symfony/http-client": "^6.4.9",
"symfony/polyfill-php84": "^1.33.0",
"symfony/string": "^6.4.9",
"symfony/translation-contracts": "^3.5.1",
"twig/twig": "~2.15 || ^3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/guides/src/Compiler/Passes/GlobalMenuPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function run(array $documents, CompilerContextInterface $compilerContext)
}

if ($rootDocument === null) {
return [];
return $documents;
}

$menuNodes = [];
Expand Down
4 changes: 4 additions & 0 deletions packages/guides/src/Nodes/ProjectNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public function addLinkTarget(string $anchorName, InternalTarget $target): void
}

if (isset($this->internalLinkTargets[$linkType][$anchorName]) && $linkType !== 'std:title') {
if ($this->internalLinkTargets[$linkType][$anchorName]->getDocumentPath() === $target->getDocumentPath()) {
return;
}

throw new DuplicateLinkAnchorException(sprintf('Duplicate anchor "%s". There is already another anchor of that name in document "%s"', $anchorName, $this->internalLinkTargets[$linkType][$anchorName]->getDocumentPath()));
}

Expand Down
11 changes: 6 additions & 5 deletions packages/guides/tests/unit/Interlink/InventoryLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ final class InventoryLoaderTest extends TestCase
private JsonLoader&MockObject $jsonLoader;
private DefaultInventoryRepository $inventoryRepository;
private RenderContext&MockObject $renderContext;
/** @var array<string, mixed> */
private array $json;

protected function setUp(): void
{
Expand All @@ -65,9 +63,10 @@ public function loadObjectsJsonInv(string $filename): void
{
$jsonString = file_get_contents($filename);
assertIsString($jsonString);
$this->json = (array) json_decode($jsonString, true, 512, JSON_THROW_ON_ERROR);
/** @var array<array-key, mixed> $json */
$json = (array) json_decode($jsonString, true, 512, JSON_THROW_ON_ERROR);
$inventory = new Inventory('https://example.com/', new SluggerAnchorNormalizer());
$this->inventoryLoader->loadInventoryFromJson($inventory, $this->json);
$this->inventoryLoader->loadInventoryFromJson($inventory, $json);
$this->inventoryRepository->addInventory('somekey', $inventory);
$this->inventoryRepository->addInventory('some-key', $inventory);
}
Expand All @@ -82,7 +81,9 @@ public function testInventoryLoaderLoadsInventory(): void

public function testInventoryIsLoadedExactlyOnce(): void
{
$this->jsonLoader->expects(self::once())->method('loadJsonFromUrl')->willReturn($this->json);
$this->jsonLoader->expects(self::once())->method('loadJsonFromUrl')->willReturn(
['dummy' => 'data', 'items' => []],
);
$inventory = new Inventory('https://example.com/', new SluggerAnchorNormalizer());
$this->inventoryLoader->loadInventory($inventory);
$this->inventoryLoader->loadInventory($inventory);
Expand Down
Loading