diff --git a/guides.xml b/guides.xml
index ea60d296d..ea6297c43 100644
--- a/guides.xml
+++ b/guides.xml
@@ -1,9 +1,18 @@
+ xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"
+ input="docs"
+ output="output"
+ input-format="rst"
+ show-progress="true"
+ theme="bootstrap"
+ fail-on-log="false"
+ log-path="php://stder"
+>
- bootstrap
+ html
+ intersphinx
diff --git a/packages/guides-cli/resources/schema/guides.xsd b/packages/guides-cli/resources/schema/guides.xsd
index e8029e8e9..e588f5ead 100644
--- a/packages/guides-cli/resources/schema/guides.xsd
+++ b/packages/guides-cli/resources/schema/guides.xsd
@@ -12,8 +12,15 @@
+
+
+
+
+
+
+
diff --git a/packages/guides-cli/src/Command/Run.php b/packages/guides-cli/src/Command/Run.php
index aaaa8d530..df6b5e2a6 100644
--- a/packages/guides-cli/src/Command/Run.php
+++ b/packages/guides-cli/src/Command/Run.php
@@ -18,6 +18,7 @@
use phpDocumentor\Guides\Handlers\RenderCommand;
use phpDocumentor\Guides\Intersphinx\InventoryRepository;
use phpDocumentor\Guides\Nodes\ProjectNode;
+use phpDocumentor\Guides\Settings\ProjectSettings;
use phpDocumentor\Guides\Settings\SettingsManager;
use phpDocumentor\Guides\Twig\Theme\ThemeManager;
use RuntimeException;
@@ -55,13 +56,11 @@ public function __construct(
'input',
InputArgument::OPTIONAL,
'Directory to read for files',
- 'docs',
);
$this->addArgument(
'output',
InputArgument::OPTIONAL,
'Directory to read for files',
- 'output',
);
$this->addOption(
@@ -69,21 +68,18 @@ public function __construct(
null,
InputOption::VALUE_REQUIRED,
'Format of the input can be RST, or Markdown',
- 'rst',
);
$this->addOption(
'output-format',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
- 'Format of the input can be html',
- ['html'],
+ 'Format of the input can be html and or intersphinx',
);
$this->addOption(
'log-path',
null,
InputOption::VALUE_REQUIRED,
'Write log to this path',
- 'php://stder',
);
$this->addOption(
'fail-on-log',
@@ -104,30 +100,62 @@ public function __construct(
null,
InputOption::VALUE_NEGATABLE,
'Whether to show a progress bar',
- true,
);
}
+ private function getSettingsOverridenWithInput(InputInterface $input): ProjectSettings
+ {
+ $settings = $this->settingsManager->getProjectSettings();
+ if ($input->getArgument('input')) {
+ $settings->setInput((string) $input->getArgument('input'));
+ }
+
+ if ($input->getArgument('output')) {
+ $settings->setOutput((string) $input->getArgument('output'));
+ }
+
+ if ($input->getOption('log-path')) {
+ $settings->setLogPath((string) $input->getOption('log-path'));
+ }
+
+ if ($input->getOption('fail-on-log')) {
+ $settings->setFailOnError(true);
+ }
+
+ if ($input->getOption('input-format')) {
+ $settings->setInputFormat((string) $input->getOption('input-format'));
+ }
+
+ if (count($input->getOption('output-format')) > 0) {
+ $settings->setOutputFormats($input->getOption('output-format'));
+ }
+
+ if ($input->getOption('theme')) {
+ $settings->setTheme((string) $input->getOption('theme'));
+ }
+
+ return $settings;
+ }
+
protected function execute(InputInterface $input, OutputInterface $output): int
{
- $inputDir = $this->getAbsolutePath((string) ($input->getArgument('input') ?? ''));
+ $settings = $this->getSettingsOverridenWithInput($input);
+ $inputDir = $this->getAbsolutePath($settings->getInput());
if (!is_dir($inputDir)) {
throw new RuntimeException(sprintf('Input directory "%s" was not found! ' . "\n" .
'Run "vendor/bin/guides -h" for information on how to configure this command.', $inputDir));
}
- $settings = $this->settingsManager->getProjectSettings();
-
$projectNode = new ProjectNode(
$settings->getTitle() === '' ? null : $settings->getTitle(),
$settings->getVersion() === '' ? null : $settings->getVersion(),
);
$this->inventoryRepository->initialize($settings->getInventories());
- $outputDir = $this->getAbsolutePath((string) ($input->getArgument('output') ?? ''));
- $sourceFileSystem = new Filesystem(new Local($input->getArgument('input')));
+ $outputDir = $this->getAbsolutePath($settings->getOutput());
+ $sourceFileSystem = new Filesystem(new Local($settings->getInput()));
$sourceFileSystem->addPlugin(new Finder());
- $logPath = $input->getOption('log-path') ?? 'php://stder';
+ $logPath = $settings->getLogPath();
if ($logPath === 'php://stder') {
$this->logger->pushHandler(new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, Logger::WARNING));
} else {
@@ -135,9 +163,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->logger->pushHandler(new StreamHandler($logPath . '/error.log', Logger::ERROR));
}
- $failOnLog = $input->getOption('fail-on-log') ?? false;
-
- if ($failOnLog) {
+ if ($settings->isFailOnError()) {
$spyProcessor = new SpyProcessor();
$this->logger->pushProcessor($spyProcessor);
}
@@ -146,15 +172,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
new ParseDirectoryCommand(
$sourceFileSystem,
'',
- $input->getOption('input-format'),
+ $settings->getInputFormat(),
$projectNode,
),
);
- $theme = $input->getOption('theme');
- if ($theme) {
- $settings->setTheme($theme);
- }
+
$this->themeManager->useTheme($settings->getTheme());
@@ -162,12 +185,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$destinationFileSystem = new Filesystem(new Local($outputDir));
- $outputFormats = $input->getOption('output-format');
+ $outputFormats = $settings->getOutputFormats();
foreach ($outputFormats as $format) {
$progressBar = null;
- if ($output instanceof ConsoleOutputInterface && $input->getOption('progress')) {
+ if ($output instanceof ConsoleOutputInterface && $settings->isShowProgressBar()) {
$progressBar = new ProgressBar($output->section());
}
@@ -195,7 +218,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'Successfully placed ' . (is_countable($documents) ? count($documents) : 0) . ' rendered ' . $formatsText . ' files into ' . $outputDir,
);
- if ($failOnLog && $spyProcessor->hasBeenCalled()) {
+ if ($settings->isFailOnError() && $spyProcessor->hasBeenCalled()) {
return Command::FAILURE;
}
diff --git a/packages/guides/src/DependencyInjection/GuidesExtension.php b/packages/guides/src/DependencyInjection/GuidesExtension.php
index 5d5d1d816..5c1bf546d 100644
--- a/packages/guides/src/DependencyInjection/GuidesExtension.php
+++ b/packages/guides/src/DependencyInjection/GuidesExtension.php
@@ -52,6 +52,16 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->scalarNode('theme')->end()
+ ->scalarNode('input')->end()
+ ->scalarNode('output')->end()
+ ->scalarNode('input_format')->end()
+ ->arrayNode('output_format')
+ ->defaultValue([])
+ ->scalarPrototype()->end()
+ ->end()
+ ->scalarNode('log_path')->end()
+ ->scalarNode('fail_on_log')->end()
+ ->scalarNode('show_progress')->end()
->arrayNode('base_template_paths')
->defaultValue([])
->scalarPrototype()->end()
@@ -91,28 +101,50 @@ public function load(array $configs, ContainerBuilder $container): void
$loader->load('command_bus.php');
$loader->load('guides.php');
- $projectSettings = [];
+ $projectSettings = new ProjectSettings();
if (isset($config['project'])) {
if (isset($config['project']['version'])) {
- $config['project']['version'] = (string) $config['project']['version'];
+ $projectSettings->setVersion((string) $config['project']['version']);
}
- $projectSettings = $config['project'];
+ $projectSettings->setTitle((string) $config['project']['title']);
}
if (isset($config['inventories'])) {
- $projectSettings['inventories'] = $config['inventories']['inventory'];
+ $projectSettings->setInventories($config['inventories']['inventory']);
}
if (isset($config['theme'])) {
- $projectSettings['theme'] = (string) $config['theme'];
+ $projectSettings->setTheme((string) $config['theme']);
+ }
+
+ if (isset($config['input'])) {
+ $projectSettings->setInput((string) $config['input']);
+ }
+
+ if (isset($config['output'])) {
+ $projectSettings->setOutput((string) $config['output']);
}
- if ($projectSettings) {
- $container->getDefinition(SettingsManager::class)
- ->addMethodCall('setProjectSettings', [new ProjectSettings($projectSettings)]);
+ if (isset($config['input_format'])) {
+ $projectSettings->setInputFormat((string) $config['input_format']);
}
+ if (isset($config['output_format']) && is_array($config['output_format'])) {
+ $projectSettings->setOutputFormats($config['output_format']);
+ }
+
+ if (isset($config['show_progress'])) {
+ $projectSettings->setShowProgressBar((bool) $config['show_progress']);
+ }
+
+ if (isset($config['fail_on_log'])) {
+ $projectSettings->setFailOnError((bool) $config['show_progress']);
+ }
+
+ $container->getDefinition(SettingsManager::class)
+ ->addMethodCall('setProjectSettings', [$projectSettings]);
+
$config['base_template_paths'][] = dirname(__DIR__, 2) . '/resources/template/html';
$container->setParameter('phpdoc.guides.base_template_paths', $config['base_template_paths']);
diff --git a/packages/guides/src/Settings/ProjectSettings.php b/packages/guides/src/Settings/ProjectSettings.php
index a40a8ab7a..38b496757 100644
--- a/packages/guides/src/Settings/ProjectSettings.php
+++ b/packages/guides/src/Settings/ProjectSettings.php
@@ -4,25 +4,21 @@
namespace phpDocumentor\Guides\Settings;
-use function is_array;
-use function is_string;
-
class ProjectSettings
{
/** @var array */
- private array $inventories;
- private string $title;
- private string $version;
- private string $theme;
-
- /** @param array> $settingsArray */
- public function __construct(array $settingsArray)
- {
- $this->title = isset($settingsArray['title']) && is_string($settingsArray['title']) ? $settingsArray['title'] : '';
- $this->version = isset($settingsArray['version']) && is_string($settingsArray['version']) ? $settingsArray['version'] : '';
- $this->inventories = isset($settingsArray['inventories']) && is_array($settingsArray['inventories']) ? $settingsArray['inventories'] : [];
- $this->theme = isset($settingsArray['theme']) && is_string($settingsArray['theme']) ? $settingsArray['theme'] : 'default';
- }
+ private array $inventories = [];
+ private string $title = '';
+ private string $version = '';
+ private string $theme = 'default';
+ private string $input = 'docs';
+ private string $output = 'output';
+ private string $inputFormat = 'rst';
+ /** @var string[] */
+ private array $outputFormats = ['html'];
+ private string $logPath = 'php://stder';
+ private bool $failOnError = false;
+ private bool $showProgressBar = true;
public function getTitle(): string
{
@@ -65,4 +61,76 @@ public function setTheme(string $theme): void
{
$this->theme = $theme;
}
+
+ public function getInput(): string
+ {
+ return $this->input;
+ }
+
+ public function setInput(string $input): void
+ {
+ $this->input = $input;
+ }
+
+ public function getOutput(): string
+ {
+ return $this->output;
+ }
+
+ public function setOutput(string $output): void
+ {
+ $this->output = $output;
+ }
+
+ public function getInputFormat(): string
+ {
+ return $this->inputFormat;
+ }
+
+ public function setInputFormat(string $inputFormat): void
+ {
+ $this->inputFormat = $inputFormat;
+ }
+
+ public function getLogPath(): string
+ {
+ return $this->logPath;
+ }
+
+ public function setLogPath(string $logPath): void
+ {
+ $this->logPath = $logPath;
+ }
+
+ public function isFailOnError(): bool
+ {
+ return $this->failOnError;
+ }
+
+ public function setFailOnError(bool $failOnError): void
+ {
+ $this->failOnError = $failOnError;
+ }
+
+ public function isShowProgressBar(): bool
+ {
+ return $this->showProgressBar;
+ }
+
+ public function setShowProgressBar(bool $showProgressBar): void
+ {
+ $this->showProgressBar = $showProgressBar;
+ }
+
+ /** @return string[] */
+ public function getOutputFormats(): array
+ {
+ return $this->outputFormats;
+ }
+
+ /** @param string[] $outputFormats */
+ public function setOutputFormats(array $outputFormats): void
+ {
+ $this->outputFormats = $outputFormats;
+ }
}
diff --git a/packages/guides/src/Settings/SettingsManager.php b/packages/guides/src/Settings/SettingsManager.php
index 79d6b49d7..49ab48468 100644
--- a/packages/guides/src/Settings/SettingsManager.php
+++ b/packages/guides/src/Settings/SettingsManager.php
@@ -10,7 +10,7 @@ class SettingsManager
public function __construct(ProjectSettings|null $projectSettings = null)
{
- $this->projectSettings = $projectSettings ?? new ProjectSettings([]);
+ $this->projectSettings = $projectSettings ?? new ProjectSettings();
}
public function getProjectSettings(): ProjectSettings