Skip to content

Commit 06b57f0

Browse files
authored
Merge pull request #592 from phpDocumentor/bugfix/html-theme
[BUGFIX] Make setting theme in guides.xml work
2 parents 3117161 + 0b569ee commit 06b57f0

File tree

39 files changed

+81
-170
lines changed

39 files changed

+81
-170
lines changed

guides.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd">
55
<project title="phpDocumentor Guides"/>
6+
<theme>bootstrap</theme>
67

78
<extension class="phpDocumentor\Guides\Bootstrap"/>
89
</guides>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<xsd:element name="extension" type="extension" minOccurs="0" maxOccurs="unbounded"/>
1515
</xsd:choice>
1616

17-
<xsd:attribute name="html-theme" type="xsd:string"/>
17+
<xsd:attribute name="theme" type="xsd:string"/>
1818
</xsd:complexType>
1919

2020
<xsd:complexType name="extension">

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public function __construct(
9797
null,
9898
InputOption::VALUE_REQUIRED,
9999
'The theme used for rendering.',
100-
'default',
101100
);
102101

103102
$this->addOption(
@@ -154,9 +153,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
154153

155154
$theme = $input->getOption('theme');
156155
if ($theme) {
157-
$this->themeManager->useTheme($theme);
156+
$settings->setTheme($theme);
158157
}
159158

159+
$this->themeManager->useTheme($settings->getTheme());
160+
160161
$documents = $this->commandBus->handle(new CompileDocumentsCommand($documents, new CompilerContext($projectNode)));
161162

162163
$destinationFileSystem = new Filesystem(new Local($outputDir));

packages/guides/src/DependencyInjection/GuidesExtension.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getConfigTreeBuilder(): TreeBuilder
5151
->end()
5252
->end()
5353
->end()
54-
->scalarNode('html_theme')->end()
54+
->scalarNode('theme')->end()
5555
->arrayNode('base_template_paths')
5656
->defaultValue([])
5757
->scalarPrototype()->end()
@@ -104,16 +104,15 @@ public function load(array $configs, ContainerBuilder $container): void
104104
$projectSettings['inventories'] = $config['inventories']['inventory'];
105105
}
106106

107+
if (isset($config['theme'])) {
108+
$projectSettings['theme'] = (string) $config['theme'];
109+
}
110+
107111
if ($projectSettings) {
108112
$container->getDefinition(SettingsManager::class)
109113
->addMethodCall('setProjectSettings', [new ProjectSettings($projectSettings)]);
110114
}
111115

112-
if (isset($config['html_theme'])) {
113-
$container->getDefinition(ThemeManager::class)
114-
->addMethodCall('useTheme', [$config['html_theme']]);
115-
}
116-
117116
$config['base_template_paths'][] = dirname(__DIR__, 2) . '/resources/template/html';
118117
$container->setParameter('phpdoc.guides.base_template_paths', $config['base_template_paths']);
119118

packages/guides/src/Settings/ProjectSettings.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010
class ProjectSettings
1111
{
1212
/** @var array<string, string> */
13-
private readonly array $inventories;
14-
private readonly string $title;
15-
private readonly string $version;
13+
private array $inventories;
14+
private string $title;
15+
private string $version;
16+
private string $theme;
1617

1718
/** @param array<string, string|array<string, string>> $settingsArray */
1819
public function __construct(array $settingsArray)
1920
{
2021
$this->title = isset($settingsArray['title']) && is_string($settingsArray['title']) ? $settingsArray['title'] : '';
2122
$this->version = isset($settingsArray['version']) && is_string($settingsArray['version']) ? $settingsArray['version'] : '';
2223
$this->inventories = isset($settingsArray['inventories']) && is_array($settingsArray['inventories']) ? $settingsArray['inventories'] : [];
24+
$this->theme = isset($settingsArray['theme']) && is_string($settingsArray['theme']) ? $settingsArray['theme'] : 'default';
2325
}
2426

2527
public function getTitle(): string
@@ -37,4 +39,30 @@ public function getInventories(): array
3739
{
3840
return $this->inventories;
3941
}
42+
43+
public function getTheme(): string
44+
{
45+
return $this->theme;
46+
}
47+
48+
/** @param array<string, string> $inventories*/
49+
public function setInventories(array $inventories): void
50+
{
51+
$this->inventories = $inventories;
52+
}
53+
54+
public function setTitle(string $title): void
55+
{
56+
$this->title = $title;
57+
}
58+
59+
public function setVersion(string $version): void
60+
{
61+
$this->version = $version;
62+
}
63+
64+
public function setTheme(string $theme): void
65+
{
66+
$this->theme = $theme;
67+
}
4068
}

tests/Integration/IntegrationBootstrapTest.php

Lines changed: 0 additions & 158 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 xmlns="https://www.phpdoc.org/guides"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd">
5+
<theme>bootstrap</theme>
6+
7+
<extension class="phpDocumentor\Guides\Bootstrap"/>
8+
</guides>
File renamed without changes.

0 commit comments

Comments
 (0)