mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add configuration option to select storage driver
Introduces a new `use_driver` configuration option to specify the desired storage driver (`local_storage` or `openstack`). Ensures proper validation to handle multiple drivers and throws appropriate errors when configurations are inconsistent or missing. Refactors related logic to improve clarity and maintainability.
This commit is contained in:
parent
812e4047d0
commit
73bcfb82b7
@ -41,11 +41,22 @@ class StorageConfigurationCompilerPass implements CompilerPassInterface
|
||||
->getParameterBag()
|
||||
->resolveValue($container->getParameter('chill_doc_store'));
|
||||
|
||||
if (array_key_exists('openstack', $config) && array_key_exists('local_storage', $config)) {
|
||||
throw new InvalidConfigurationException('chill_doc_store: you can either configure a local storage (key local_storage) or openstack storage (key openstack). Choose between them.');
|
||||
if (array_key_exists('local_storage', $config) && !array_key_exists('openstack', $config)) {
|
||||
$driver = 'local_storage';
|
||||
$this->checkUseDriverConfiguration($config['use_driver'] ?? null, $driver);
|
||||
} elseif (!array_key_exists('local_storage', $config) && array_key_exists('openstack', $config)) {
|
||||
$driver = 'openstack';
|
||||
$this->checkUseDriverConfiguration($config['use_driver'] ?? null, $driver);
|
||||
} elseif (array_key_exists('openstack', $config) && array_key_exists('local_storage', $config)) {
|
||||
$driver = $config['use_driver'] ?? null;
|
||||
if (null === $driver) {
|
||||
throw new InvalidConfigurationException('There are multiple drivers configured for chill_doc_store, set the one you want to use with the variable use_driver');
|
||||
}
|
||||
} else {
|
||||
throw new InvalidConfigurationException('No driver defined for storing document. Define one in chill_doc_store configuration');
|
||||
}
|
||||
|
||||
if (array_key_exists('local_storage', $config)) {
|
||||
if ('local_storage' === $driver) {
|
||||
foreach (self::SERVICES_OPENSTACK as $service) {
|
||||
$container->removeDefinition($service);
|
||||
}
|
||||
@ -61,4 +72,15 @@ class StorageConfigurationCompilerPass implements CompilerPassInterface
|
||||
$container->setAlias(TempUrlGeneratorInterface::class, TempUrlOpenstackGenerator::class);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkUseDriverConfiguration(?string $useDriver, string $driver): void
|
||||
{
|
||||
if (null === $useDriver) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($useDriver !== $driver) {
|
||||
throw new InvalidConfigurationException(sprintf('The "use_driver" configuration require a driver (%s) which is not configured. Configure this driver in order to use it.', $useDriver));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,10 @@ class Configuration implements ConfigurationInterface
|
||||
|
||||
/* @phpstan-ignore-next-line As there are inconsistencies in return types, but the code works... */
|
||||
$rootNode->children()
|
||||
->enumNode('use_driver')
|
||||
->values(['local_storage', 'openstack'])
|
||||
->info('Driver to use. Default to the single one if multiple driver are defined. Configuration will raise an error if there are multiple drivers defined, and if this key is not set')
|
||||
->end()
|
||||
->arrayNode('local_storage')
|
||||
->info('where the stored object should be stored')
|
||||
->children()
|
||||
|
Loading…
x
Reference in New Issue
Block a user