Skip to content

Commit 9b0b3e4

Browse files
committed
[FEATURE] Provide Sphinx inventory version 2
for improved interoperability when interlinking from a Sphinx document to a guides document
1 parent dc17550 commit 9b0b3e4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/guides/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"require": {
2424
"php": "^8.1",
2525
"ext-json": "*",
26+
"ext-zlib": "*",
2627
"league/flysystem": "^1.1",
2728
"league/tactician": "^1.1",
2829
"league/uri": "^6.5 || ^7.0",

packages/guides/src/Renderer/InterlinkObjectsRenderer.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
use phpDocumentor\Guides\Renderer\UrlGenerator\UrlGeneratorInterface;
2020

2121
use function json_encode;
22+
use function sprintf;
23+
use function zlib_encode;
2224

2325
use const JSON_PRETTY_PRINT;
26+
use const ZLIB_ENCODING_DEFLATE;
2427

2528
final class InterlinkObjectsRenderer implements TypeRenderer
2629
{
@@ -84,5 +87,31 @@ public function render(RenderCommand $renderCommand): void
8487
'objects.inv.json',
8588
$json,
8689
);
90+
91+
$header = sprintf(
92+
<<<'EOF'
93+
# Sphinx inventory version 2
94+
# Project: %s
95+
# Version: %s
96+
# The remainder of this file is compressed using zlib.
97+
98+
EOF
99+
,
100+
$renderCommand->getProjectNode()->getTitle(),
101+
$renderCommand->getProjectNode()->getVersion(),
102+
);
103+
$body = '';
104+
105+
foreach ($inventory as $role => $entry) {
106+
foreach ($entry as $key => $value) {
107+
$body .= sprintf("%s %s %s %s %s\n", $key, $role, -1, $value[2], $value[3]);
108+
}
109+
}
110+
111+
$encodedBody = zlib_encode($body, ZLIB_ENCODING_DEFLATE);
112+
$renderCommand->getDestination()->put(
113+
'objects.inv',
114+
$header . $encodedBody,
115+
);
87116
}
88117
}

0 commit comments

Comments
 (0)