Skip to content

Commit

Permalink
fix(configuration): Move deprecation logic before handling defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Huber committed Aug 19, 2022
1 parent 5be2b86 commit 19193e8
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/Configuration/ConfigurationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,22 +737,11 @@ private function validateHostConfig($config_name, Node $data)
$data['needs'] = $gathered_methods;
$used_methods = $this->methods->getSubset($data['needs']);

foreach ($used_methods as $method) {
$data = $this->applyDefaults(
$data,
$method->getDefaultConfig($this, $data),
$this->disallowDeepMergeForKeys
);
}

// Overall validation.

$validation_errors = new ValidationErrorBag();
$validation = new ValidationService($data, $validation_errors, 'host-config: `' . $config_name . '`');
$validation->isArray('needs', 'Please specify the needed methods as an array');
$validation->isOneOf('type', HostType::getAll());

// Validate data against used methods.
// Apply defaults and handle deprecations

foreach ($used_methods as $method) {
if (!empty($deprecation_mapping = $method->getDeprecationMapping())) {
Expand All @@ -766,6 +755,20 @@ private function validateHostConfig($config_name, Node $data)
}
}
}
$data = $this->applyDefaults(
$data,
$method->getDefaultConfig($this, $data),
$this->disallowDeepMergeForKeys
);
}


$validation->isArray('needs', 'Please specify the needed methods as an array');
$validation->isOneOf('type', HostType::getAll());

// Validate data against used methods.

foreach ($used_methods as $method) {
$method->validateConfig($data, $validation_errors);
}

Expand Down Expand Up @@ -1148,11 +1151,12 @@ public function getData(): Node
private function mapDeprecatedConfig(Node $data, array $mapping)
{
foreach ($mapping as $deprecated => $key) {
if ($data->has($deprecated)) {
$data->setProperty($key, $data[$deprecated]);

if (!is_null($deprecated_value = $data->getProperty($deprecated))) {
$existing_value = $data->find($key);
if (is_null($existing_value)) {
$data->setProperty($key, $deprecated_value);
}
}
}
}

}

0 comments on commit 19193e8

Please sign in to comment.