refactoring

This commit is contained in:
Roland Gruber 2024-11-20 07:35:18 +01:00
parent 68095d3c40
commit 371e25f501

View file

@ -353,7 +353,7 @@ class ServerProfilePersistenceManager {
* Saves a server profile. * Saves a server profile.
* *
* @param LAMConfig $profile profile * @param LAMConfig $profile profile
* @param $name profile name * @param string $name profile name
* @throws LAMException error saving profile * @throws LAMException error saving profile
*/ */
public function saveProfile(LAMConfig $profile, $name): void { public function saveProfile(LAMConfig $profile, $name): void {
@ -563,7 +563,6 @@ class ServerProfilePersistenceStrategyFiles implements ServerProfilePersistenceS
*/ */
public function loadProfile(string $name): LAMConfig { public function loadProfile(string $name): LAMConfig {
$config = new LAMConfig(); $config = new LAMConfig();
$reflectionConfig = new ReflectionObject($config);
$confFilePath = $this->getPath($name); $confFilePath = $this->getPath($name);
if (!is_file($confFilePath)) { if (!is_file($confFilePath)) {
throw new LAMException(_('Unable to read file.')); throw new LAMException(_('Unable to read file.'));
@ -572,6 +571,7 @@ class ServerProfilePersistenceStrategyFiles implements ServerProfilePersistenceS
if (!$file) { if (!$file) {
throw new LAMException(_('Unable to read file.')); throw new LAMException(_('Unable to read file.'));
} }
$data = [];
$moduleSettings = []; $moduleSettings = [];
$typeSettings = []; $typeSettings = [];
$toolSettings = []; $toolSettings = [];
@ -589,14 +589,7 @@ class ServerProfilePersistenceStrategyFiles implements ServerProfilePersistenceS
$startIndex = strlen($keyword) + 2; $startIndex = strlen($keyword) + 2;
$value = (sizeof($parts) > 1) ? substr($line, $startIndex) : ''; $value = (sizeof($parts) > 1) ? substr($line, $startIndex) : '';
if (!in_array($keyword, ['modules', 'types', 'tools', 'jobs'])) { if (!in_array($keyword, ['modules', 'types', 'tools', 'jobs'])) {
try { $data[$keyword] = $value;
$property = $reflectionConfig->getProperty($keyword);
$property->setAccessible(true);
$property->setValue($config, $value);
}
catch (ReflectionException) {
// ignore
}
} }
else { else {
$subKeyword = $parts[1]; $subKeyword = $parts[1];
@ -624,10 +617,11 @@ class ServerProfilePersistenceStrategyFiles implements ServerProfilePersistenceS
} }
} }
fclose($file); fclose($file);
$config->set_moduleSettings($moduleSettings); $data['moduleSettings'] = $moduleSettings;
$config->set_typeSettings($typeSettings); $data['typeSettings'] = $typeSettings;
$config->setToolSettings($toolSettings); $data['toolSettings'] = $toolSettings;
$config->setJobSettings($jobSettings); $data['jobSettings'] = $jobSettings;
$config->importData($data);
$config->removeInvalidTypes(); $config->removeInvalidTypes();
$config->removeInvalidModules(); $config->removeInvalidModules();
return $config; return $config;