From 371e25f5010d750ab76f54b76772d20280b15e1d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 20 Nov 2024 07:35:18 +0100 Subject: [PATCH] refactoring --- lam/lib/config.inc | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lam/lib/config.inc b/lam/lib/config.inc index e1c289d76..6cc21ac21 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -353,7 +353,7 @@ class ServerProfilePersistenceManager { * Saves a server profile. * * @param LAMConfig $profile profile - * @param $name profile name + * @param string $name profile name * @throws LAMException error saving profile */ public function saveProfile(LAMConfig $profile, $name): void { @@ -563,7 +563,6 @@ class ServerProfilePersistenceStrategyFiles implements ServerProfilePersistenceS */ public function loadProfile(string $name): LAMConfig { $config = new LAMConfig(); - $reflectionConfig = new ReflectionObject($config); $confFilePath = $this->getPath($name); if (!is_file($confFilePath)) { throw new LAMException(_('Unable to read file.')); @@ -572,6 +571,7 @@ class ServerProfilePersistenceStrategyFiles implements ServerProfilePersistenceS if (!$file) { throw new LAMException(_('Unable to read file.')); } + $data = []; $moduleSettings = []; $typeSettings = []; $toolSettings = []; @@ -589,14 +589,7 @@ class ServerProfilePersistenceStrategyFiles implements ServerProfilePersistenceS $startIndex = strlen($keyword) + 2; $value = (sizeof($parts) > 1) ? substr($line, $startIndex) : ''; if (!in_array($keyword, ['modules', 'types', 'tools', 'jobs'])) { - try { - $property = $reflectionConfig->getProperty($keyword); - $property->setAccessible(true); - $property->setValue($config, $value); - } - catch (ReflectionException) { - // ignore - } + $data[$keyword] = $value; } else { $subKeyword = $parts[1]; @@ -624,10 +617,11 @@ class ServerProfilePersistenceStrategyFiles implements ServerProfilePersistenceS } } fclose($file); - $config->set_moduleSettings($moduleSettings); - $config->set_typeSettings($typeSettings); - $config->setToolSettings($toolSettings); - $config->setJobSettings($jobSettings); + $data['moduleSettings'] = $moduleSettings; + $data['typeSettings'] = $typeSettings; + $data['toolSettings'] = $toolSettings; + $data['jobSettings'] = $jobSettings; + $config->importData($data); $config->removeInvalidTypes(); $config->removeInvalidModules(); return $config;