Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration console command #54

Merged
merged 7 commits into from
Nov 20, 2023
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
2 changes: 1 addition & 1 deletion docs/shared_c.cache

Large diffs are not rendered by default.

1,384 changes: 1,384 additions & 0 deletions docs/tech/classes/ConfigurationCommand.md

Large diffs are not rendered by default.

127 changes: 127 additions & 0 deletions docs/tech/classes/ConfigurationKey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<!-- {% raw %} -->
<embed> <a href="/docs/README.md">BumbleDocGen</a> <b>/</b> <a href="/docs/tech/readme.md">Technical description of the project</a> <b>/</b> <a href="/docs/tech/map.md">Class map</a> <b>/</b> ConfigurationKey<hr> </embed>

<h1>
<a href="https://github.com/bumble-tech/bumble-doc-gen/blob/master/src/Core/Configuration/ConfigurationKey.php#L7">ConfigurationKey</a> class:
</h1>





```php
namespace BumbleDocGen\Core\Configuration;

final class ConfigurationKey
```









<h2>Methods:</h2>

<ol>
<li>
<a href="#mall">all</a>
</li>
</ol>


<h2>Constants:</h2>
<ul>
<li><a name="qadditional-console-commands"
href="#qadditional-console-commands">#</a>
<code>ADDITIONAL_CONSOLE_COMMANDS</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L23">source
code</a> </li>
<li><a name="qcache-dir"
href="#qcache-dir">#</a>
<code>CACHE_DIR</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L13">source
code</a> </li>
<li><a name="qcheck-file-in-git-before-creating-doc"
href="#qcheck-file-in-git-before-creating-doc">#</a>
<code>CHECK_FILE_IN_GIT_BEFORE_CREATING_DOC</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L17">source
code</a> </li>
<li><a name="qgit-client-path"
href="#qgit-client-path">#</a>
<code>GIT_CLIENT_PATH</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L15">source
code</a> </li>
<li><a name="qlanguage-handlers"
href="#qlanguage-handlers">#</a>
<code>LANGUAGE_HANDLERS</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L19">source
code</a> </li>
<li><a name="qoutput-dir"
href="#qoutput-dir">#</a>
<code>OUTPUT_DIR</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L11">source
code</a> </li>
<li><a name="qoutput-dir-base-url"
href="#qoutput-dir-base-url">#</a>
<code>OUTPUT_DIR_BASE_URL</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L12">source
code</a> </li>
<li><a name="qpage-link-processor"
href="#qpage-link-processor">#</a>
<code>PAGE_LINK_PROCESSOR</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L14">source
code</a> </li>
<li><a name="qplugins"
href="#qplugins">#</a>
<code>PLUGINS</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L20">source
code</a> </li>
<li><a name="qproject-root"
href="#qproject-root">#</a>
<code>PROJECT_ROOT</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L9">source
code</a> </li>
<li><a name="qsource-locators"
href="#qsource-locators">#</a>
<code>SOURCE_LOCATORS</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L18">source
code</a> </li>
<li><a name="qtemplates-dir"
href="#qtemplates-dir">#</a>
<code>TEMPLATES_DIR</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L10">source
code</a> </li>
<li><a name="qtwig-filters"
href="#qtwig-filters">#</a>
<code>TWIG_FILTERS</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L22">source
code</a> </li>
<li><a name="qtwig-functions"
href="#qtwig-functions">#</a>
<code>TWIG_FUNCTIONS</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L21">source
code</a> </li>
<li><a name="quse-shared-cache"
href="#quse-shared-cache">#</a>
<code>USE_SHARED_CACHE</code> <b>|</b> <a href="/src/Core/Configuration/ConfigurationKey.php#L16">source
code</a> </li>
</ul>





<h2>Method details:</h2>

<div class='method_description-block'>

<ul>
<li><a name="mall" href="#mall">#</a>
<b>all</b>
<b>|</b> <a href="https://github.com/bumble-tech/bumble-doc-gen/blob/master/src/Core/Configuration/ConfigurationKey.php#L25">source code</a></li>
</ul>

```php
public static function all(): array;
```



<b>Parameters:</b> not specified

<b>Return value:</b> <a href='https://www.php.net/manual/en/language.types.array.php'>array</a>


</div>
<hr>

<!-- {% endraw %} -->
4 changes: 3 additions & 1 deletion docs/tech/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Directory layout ( only documented files shown ):
│ │ ├──<b>Command</b>/
│ │ │ ├── <a href='/docs/tech/classes/AdditionalCommandCollection.md'>AdditionalCommandCollection.php</a>
│ │ │ ├── <a href='/docs/tech/classes/BaseCommand.md'>BaseCommand.php</a> <i> — <samp>Base class for all commands.</samp></i>
│ │ │ ├── <a href='/docs/tech/classes/ConfigurationCommand.md'>ConfigurationCommand.php</a> <i> — <samp>Base class for all commands.</samp></i>
│ │ │ └── <a href='/docs/tech/classes/GenerateCommand.md'>GenerateCommand.php</a> <i> — <samp>Base class for all commands.</samp></i>
│ │ ├──<b>ProgressBar</b>/
│ │ │ ├── <a href='/docs/tech/classes/ProgressBarFactory.md'>ProgressBarFactory.php</a>
Expand All @@ -47,6 +48,7 @@ Directory layout ( only documented files shown ):
│ │ │ │ ├── <a href='/docs/tech/classes/ValueToClassTransformer.md'>ValueToClassTransformer.php</a> <i> — <samp>Standard text-to-class transformer</samp></i>
│ │ │ │ └── <a href='/docs/tech/classes/ValueTransformerInterface.md'>ValueTransformerInterface.php</a> <i> — <samp>Interface defining classes that transform text configuration values into objects</samp></i>
│ │ │ ├── <a href='/docs/tech/classes/Configuration.md'>Configuration.php</a> <i> — <samp>Configuration project documentation</samp></i>
│ │ │ ├── <a href='/docs/tech/classes/ConfigurationKey.md'>ConfigurationKey.php</a>
│ │ │ └── <a href='/docs/tech/classes/ConfigurationParameterBag.md'>ConfigurationParameterBag.php</a> <i> — <samp>Wrapper for getting raw configuration file data</samp></i>
│ │ ├──<b>Logger</b>/
│ │ │ └──<b>Handler</b>/
Expand Down Expand Up @@ -257,4 +259,4 @@ Directory layout ( only documented files shown ):

<div id='page_committer_info'>
<hr>
<b>Last page committer:</b> fshcherbanich &lt;[email protected]&gt;<br><b>Last modified date:</b> Sat Sep 2 21:01:47 2023 +0300<br><b>Page content update date:</b> Mon Nov 06 2023<br>Made with <a href='https://github.com/bumble-tech/bumble-doc-gen/blob/master/docs/README.md'>Bumble Documentation Generator</a></div>
<b>Last page committer:</b> fshcherbanich &lt;[email protected]&gt;<br><b>Last modified date:</b> Sat Sep 2 21:01:47 2023 +0300<br><b>Page content update date:</b> Tue Nov 14 2023<br>Made with <a href='https://github.com/bumble-tech/bumble-doc-gen/blob/master/docs/README.md'>Bumble Documentation Generator</a></div>
2 changes: 2 additions & 0 deletions src/Console/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use BumbleDocGen\AI\Console\AddDocBlocksCommand;
use BumbleDocGen\AI\Console\GenerateReadMeTemplateCommand;
use BumbleDocGen\Console\Command\ConfigurationCommand;
use BumbleDocGen\Console\Command\GenerateCommand;
use BumbleDocGen\DocGeneratorFactory;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -34,6 +35,7 @@ public function __construct()
$this->add(new GenerateCommand());
$this->add(new GenerateReadMeTemplateCommand());
$this->add(new AddDocBlocksCommand());
$this->add(new ConfigurationCommand());
$this->setExtraCommands();
}

Expand Down
43 changes: 43 additions & 0 deletions src/Console/Command/ConfigurationCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace BumbleDocGen\Console\Command;

use BumbleDocGen\Core\Configuration\Exception\InvalidConfigurationParameterException;
use DI\DependencyException;
use DI\NotFoundException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

final class ConfigurationCommand extends BaseCommand
{
protected function configure(): void
{
$this
->setName('configuration')
->setDescription('Display list of configured plugins, programming language handlers, etc')
->addArgument('key', InputArgument::OPTIONAL, 'Configuration key to display')
;
}

/**
* @throws NotFoundException
* @throws DependencyException
* @throws InvalidConfigurationParameterException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$generator = $this->createDocGenInstance($input, $output);

$key = $input->getArgument('key');
if ($key === null) {
$generator->getConfigurationKeys();
} else {
$generator->getConfigurationKey($key);
}

return self::SUCCESS;
}
}
50 changes: 31 additions & 19 deletions src/Core/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getProjectRoot(): string
return $this->localObjectCache->getMethodCachedResult(__METHOD__, '');
} catch (ObjectNotFoundException) {
}
$projectRoot = $this->parameterBag->validateAndGetDirectoryPathValue('project_root', false);
$projectRoot = $this->parameterBag->validateAndGetDirectoryPathValue(ConfigurationKey::PROJECT_ROOT, false);
$this->localObjectCache->cacheMethodResult(__METHOD__, '', $projectRoot);
return $projectRoot;
}
Expand All @@ -70,7 +70,7 @@ public function getSourceLocators(): SourceLocatorsCollection
} catch (ObjectNotFoundException) {
}
$sourceLocators = $this->parameterBag->validateAndGetClassListValue(
'source_locators',
ConfigurationKey::SOURCE_LOCATORS,
SourceLocatorInterface::class
);
$cachedSourceLocatorsCollection = SourceLocatorsCollection::create(...$sourceLocators);
Expand All @@ -87,11 +87,14 @@ public function getTemplatesDir(): string
return $this->localObjectCache->getMethodCachedResult(__METHOD__, '');
} catch (ObjectNotFoundException) {
}
$templatesDir = $this->parameterBag->validateAndGetStringValue('templates_dir', false);
$templatesDir = $this->parameterBag->validateAndGetStringValue(ConfigurationKey::TEMPLATES_DIR, false);
$parentDir = dirname($templatesDir);
if (!$parentDir || !is_dir($parentDir)) {
throw new InvalidConfigurationParameterException(
misantron marked this conversation as resolved.
Show resolved Hide resolved
"`output_dir` cannot be created because parent directory `{$parentDir}` does not exist"
sprintf(
"`%s` cannot be created because parent directory `{$parentDir}` does not exist",
ConfigurationKey::TEMPLATES_DIR
)
);
}
if (!file_exists($templatesDir)) {
Expand All @@ -112,17 +115,23 @@ public function getOutputDir(): string
return $this->localObjectCache->getMethodCachedResult(__METHOD__, '');
} catch (ObjectNotFoundException) {
}
$outputDir = $this->parameterBag->validateAndGetStringValue('output_dir', false);
$outputDir = $this->parameterBag->validateAndGetStringValue(ConfigurationKey::OUTPUT_DIR, false);
$parentDir = dirname($outputDir);
if (!$parentDir || !is_dir($parentDir)) {
throw new InvalidConfigurationParameterException(
misantron marked this conversation as resolved.
Show resolved Hide resolved
"`output_dir` cannot be created because parent directory `{$parentDir}` does not exist"
sprintf(
"`%s` cannot be created because parent directory `{$parentDir}` does not exist",
ConfigurationKey::OUTPUT_DIR
)
);
}

if (!is_writable($parentDir)) {
throw new InvalidConfigurationParameterException(
"`output_dir` cannot be created because parent directory `{$parentDir}` is not writable"
sprintf(
"`%s` cannot be created because parent directory `{$parentDir}` is not writable",
ConfigurationKey::OUTPUT_DIR
)
);
}

Expand All @@ -144,7 +153,7 @@ public function getOutputDirBaseUrl(): string
return $this->localObjectCache->getMethodCachedResult(__METHOD__, '');
} catch (ObjectNotFoundException) {
}
$outputDirBaseUrl = $this->parameterBag->validateAndGetStringValue('output_dir_base_url', false);
$outputDirBaseUrl = $this->parameterBag->validateAndGetStringValue(ConfigurationKey::OUTPUT_DIR_BASE_URL, false);
$this->localObjectCache->cacheMethodResult(__METHOD__, '', $outputDirBaseUrl);
return $outputDirBaseUrl;
}
Expand All @@ -161,7 +170,7 @@ public function getLanguageHandlersCollection(): LanguageHandlersCollection
} catch (ObjectNotFoundException) {
}
$languageHandlers = $this->parameterBag->validateAndGetClassListValue(
'language_handlers',
ConfigurationKey::LANGUAGE_HANDLERS,
LanguageHandlerInterface::class,
false
);
Expand All @@ -182,7 +191,7 @@ public function getPlugins(): PluginsCollection
} catch (ObjectNotFoundException) {
}
$pluginsList = $this->parameterBag->validateAndGetClassListValue(
'plugins',
ConfigurationKey::PLUGINS,
PluginInterface::class
);
$cachedPlugins = PluginsCollection::create(...$pluginsList);
Expand All @@ -200,11 +209,14 @@ public function getCacheDir(): ?string
} catch (ObjectNotFoundException) {
}

$cacheDir = $this->parameterBag->validateAndGetStringValue('cache_dir');
$cacheDir = $this->parameterBag->validateAndGetStringValue(ConfigurationKey::CACHE_DIR);
$parentDir = dirname($cacheDir);
if (!is_dir($parentDir)) {
throw new InvalidConfigurationParameterException(
misantron marked this conversation as resolved.
Show resolved Hide resolved
"`cache_dir` cannot be created because parent directory `{$parentDir}` does not exist"
sprintf(
"`%s` cannot be created because parent directory `{$parentDir}` does not exist",
ConfigurationKey::CACHE_DIR
)
);
}
if (!file_exists($cacheDir)) {
Expand All @@ -229,7 +241,7 @@ public function getPageLinkProcessor(): PageLinkProcessorInterface
}
/** @var PageLinkProcessorInterface $pageLinkProcessor */
$pageLinkProcessor = $this->parameterBag->validateAndGetClassValue(
'page_link_processor',
ConfigurationKey::PAGE_LINK_PROCESSOR,
PageLinkProcessorInterface::class
);
$this->localObjectCache->cacheMethodResult(__METHOD__, '', $pageLinkProcessor);
Expand All @@ -245,7 +257,7 @@ public function getGitClientPath(): string
return $this->localObjectCache->getMethodCachedResult(__METHOD__, '');
} catch (ObjectNotFoundException) {
}
$gitClientPath = $this->parameterBag->validateAndGetStringValue('git_client_path', false);
$gitClientPath = $this->parameterBag->validateAndGetStringValue(ConfigurationKey::GIT_CLIENT_PATH, false);
$this->localObjectCache->cacheMethodResult(__METHOD__, '', $gitClientPath);
return $gitClientPath;
}
Expand All @@ -262,7 +274,7 @@ public function getTwigFunctions(): CustomFunctionsCollection
} catch (ObjectNotFoundException) {
}
$customFunctions = $this->parameterBag->validateAndGetClassListValue(
'twig_functions',
ConfigurationKey::TWIG_FUNCTIONS,
CustomFunctionInterface::class
);
$customFunctionsCollection = new CustomFunctionsCollection();
Expand All @@ -285,7 +297,7 @@ public function getTwigFilters(): CustomFiltersCollection
} catch (ObjectNotFoundException) {
}
$customFilters = $this->parameterBag->validateAndGetClassListValue(
'twig_filters',
ConfigurationKey::TWIG_FILTERS,
CustomFilterInterface::class
);
$customFiltersCollection = new CustomFiltersCollection();
Expand All @@ -305,7 +317,7 @@ public function useSharedCache(): bool
return $this->localObjectCache->getMethodCachedResult(__METHOD__, '');
} catch (ObjectNotFoundException) {
}
$useSharedCache = $this->parameterBag->validateAndGetBooleanValue('use_shared_cache');
$useSharedCache = $this->parameterBag->validateAndGetBooleanValue(ConfigurationKey::USE_SHARED_CACHE);
$this->localObjectCache->cacheMethodResult(__METHOD__, '', $useSharedCache);
return $useSharedCache;
}
Expand All @@ -319,7 +331,7 @@ public function isCheckFileInGitBeforeCreatingDocEnabled(): bool
return $this->localObjectCache->getMethodCachedResult(__METHOD__, '');
} catch (ObjectNotFoundException) {
}
$useSharedCache = $this->parameterBag->validateAndGetBooleanValue('check_file_in_git_before_creating_doc');
$useSharedCache = $this->parameterBag->validateAndGetBooleanValue(ConfigurationKey::CHECK_FILE_IN_GIT_BEFORE_CREATING_DOC);
$this->localObjectCache->cacheMethodResult(__METHOD__, '', $useSharedCache);
return $useSharedCache;
}
Expand Down Expand Up @@ -353,7 +365,7 @@ public function getAdditionalConsoleCommands(): AdditionalCommandCollection
} catch (ObjectNotFoundException) {
}
$customFilters = $this->parameterBag->validateAndGetClassListValue(
'additional_console_commands',
ConfigurationKey::ADDITIONAL_CONSOLE_COMMANDS,
Command::class
);
$additionalCommandCollection = AdditionalCommandCollection::create(...$customFilters);
Expand Down
Loading