Skip to content

Commit 481cc03

Browse files
authored
Merge pull request #586 from phpDocumentor/feature/paths
[FEATURE] Configure inventories via guides.xml
2 parents 1b367ad + 04c24fd commit 481cc03

File tree

11 files changed

+66
-77
lines changed

11 files changed

+66
-77
lines changed

docs/configuration.rst

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,11 @@ Configuration
66

77
This library can be configured in two ways:
88

9-
1. ``guides.xml`` in the current directory. This file configures the Guides
10-
library (which extensions to load) and can configure default values for
11-
the project specific settings.
12-
2. ``settings.php`` in the source files directory. This file can contain
13-
project/manual specific settings.
14-
15-
In most cases, you should do everything in the ``guides.xml`` file.
16-
Documentations that compile the docs for a collection of projects might
17-
want to use both config options. For instance, the ``guides.xml`` can
18-
configure the documentation theme, whereas the ``settings.php`` configures
19-
the title and version of each specific project.
9+
1. ``guides.xml`` in the current directory. This file configures the Guides
10+
library (which extensions to load) and can configure default values for
11+
the project specific settings.
12+
2. ``guides.xml`` in the parent of the vendor directory. Options are
13+
overridden by the first location
2014

2115
Global configuration
2216
====================
@@ -52,24 +46,3 @@ you want to use the Bootstrap HTML theme, use this configuration:
5246
</guides>
5347
5448
See the ``guides.xsd`` file for all available config options.
55-
56-
Per-manual configuration
57-
========================
58-
59-
If you need different settings for different manuals you are building,
60-
you can do so by creating a ``settings.php`` file in the input directory
61-
of the manual you are building (that is the directory you would specify
62-
as a first argument to the CLI).
63-
64-
That file needs to return an `array`, and typically looks as
65-
follows:
66-
67-
.. code-block:: php
68-
69-
<?php
70-
71-
return [
72-
'title' => 'My Project',
73-
'version' => '3.1.4',
74-
'inventories' => ['t3coreapi' => 'https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/'],
75-
];

packages/guides-cli/resources/schema/guides.xsd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,15 @@
4040

4141
<xsd:attribute name="extends" type="xsd:string"/>
4242
</xsd:complexType>
43+
44+
<xsd:complexType name="inventories">
45+
<xsd:sequence>
46+
<xsd:element name="inventory" type="inventory" minOccurs="1" maxOccurs="unbounded"/>
47+
</xsd:sequence>
48+
</xsd:complexType>
49+
50+
<xsd:complexType name="inventory">
51+
<xsd:attribute name="name" type="xsd:string" use="required"/>
52+
<xsd:attribute name="path" type="xsd:string" use="required"/>
53+
</xsd:complexType>
4354
</xsd:schema>

packages/guides-cli/src/Command/Run.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use phpDocumentor\Guides\Handlers\RenderCommand;
1919
use phpDocumentor\Guides\Intersphinx\InventoryRepository;
2020
use phpDocumentor\Guides\Nodes\ProjectNode;
21-
use phpDocumentor\Guides\Settings\ProjectSettings;
2221
use phpDocumentor\Guides\Settings\SettingsManager;
2322
use phpDocumentor\Guides\Twig\Theme\ThemeManager;
2423
use RuntimeException;
@@ -34,10 +33,8 @@
3433
use function count;
3534
use function getcwd;
3635
use function implode;
37-
use function is_array;
3836
use function is_countable;
3937
use function is_dir;
40-
use function is_file;
4138
use function realpath;
4239
use function sprintf;
4340
use function str_starts_with;
@@ -120,17 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
120117
'Run "vendor/bin/guides -h" for information on how to configure this command.', $inputDir));
121118
}
122119

123-
if (is_file($inputDir . '/settings.php')) {
124-
$settingsArray = require $inputDir . '/settings.php';
125-
if (!is_array($settingsArray)) {
126-
throw new RuntimeException('settings.php must return an array!');
127-
}
128-
129-
$settings = new ProjectSettings($settingsArray);
130-
$this->settingsManager->setProjectSettings($settings);
131-
} else {
132-
$settings = $this->settingsManager->getProjectSettings();
133-
}
120+
$settings = $this->settingsManager->getProjectSettings();
134121

135122
$projectNode = new ProjectNode(
136123
$settings->getTitle() === '' ? null : $settings->getTitle(),

packages/guides/src/DependencyInjection/GuidesExtension.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ public function getConfigTreeBuilder(): TreeBuilder
3939
->scalarNode('version')->end()
4040
->end()
4141
->end()
42+
->arrayNode('inventories')
43+
->children()
44+
->arrayNode('inventory')
45+
->arrayPrototype()
46+
->children()
47+
->scalarNode('id')->end()
48+
->scalarNode('url')->end()
49+
->end()
50+
->end()
51+
->end()
52+
->end()
53+
->end()
4254
->scalarNode('html_theme')->end()
4355
->arrayNode('base_template_paths')
4456
->defaultValue([])
@@ -79,13 +91,22 @@ public function load(array $configs, ContainerBuilder $container): void
7991
$loader->load('command_bus.php');
8092
$loader->load('guides.php');
8193

94+
$projectSettings = [];
8295
if (isset($config['project'])) {
8396
if (isset($config['project']['version'])) {
8497
$config['project']['version'] = (string) $config['project']['version'];
8598
}
8699

100+
$projectSettings = $config['project'];
101+
}
102+
103+
if (isset($config['inventories'])) {
104+
$projectSettings['inventories'] = $config['inventories']['inventory'];
105+
}
106+
107+
if ($projectSettings) {
87108
$container->getDefinition(SettingsManager::class)
88-
->addMethodCall('setProjectSettings', [new ProjectSettings($config['project'])]);
109+
->addMethodCall('setProjectSettings', [new ProjectSettings($projectSettings)]);
89110
}
90111

91112
if (isset($config['html_theme'])) {

packages/guides/src/Intersphinx/InventoryRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public function __construct(private readonly InventoryLoader $inventoryLoader)
1818
{
1919
}
2020

21-
/** @param array<string, string> $inventoryConfigs */
21+
/** @param array<int, array<string, string>> $inventoryConfigs */
2222
public function initialize(array $inventoryConfigs): void
2323
{
2424
$this->inventories = [];
25-
foreach ($inventoryConfigs as $key => $url) {
26-
$this->inventories[$key] = new Inventory($url);
25+
foreach ($inventoryConfigs as $inventory) {
26+
$this->inventories[$inventory['id']] = new Inventory($inventory['url']);
2727
}
2828
}
2929

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides>
3+
<project title="My Project" version="main (development)" />
4+
<inventories>
5+
<inventory id="t3coreapi" url="https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/" />
6+
<inventory id="someapi" url="https://docs.typo3.org/m/typo3/reference-someapi/main/en-us/" />
7+
</inventories>
8+
</guides>

tests/Integration/tests/intersphinx-link/input/settings.php

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides>
3+
<project title="My Project" version="main (development)" />
4+
<inventories>
5+
<inventory id="t3coreapi" url="https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/" />
6+
<inventory id="t3home" url="https://docs.typo3.org/" />
7+
</inventories>
8+
</guides>

tests/Integration/tests/intersphinx-numeric/input/settings.php

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<guides>
3+
<project title="My Project" version="3.1.4" />
4+
<inventories>
5+
<inventory id="t3coreapi" url="https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/" />
6+
<inventory id="t3home" url="https://docs.typo3.org/" />
7+
</inventories>
8+
</guides>

0 commit comments

Comments
 (0)