acl->check(self::SCOPE)) { throw new Forbidden(); } if ($this->acl->getLevel(self::SCOPE, Acl\Table::ACTION_READ) !== Acl\Table::LEVEL_YES) { throw new Forbidden(); } return (object) ( $this->config->get('currencyRates') ?? [] ); } /** * @throws BadRequest * @throws Forbidden * @throws Error */ public function set(stdClass $rates): stdClass { if (!$this->acl->check(self::SCOPE)) { throw new Forbidden(); } if ($this->acl->getLevel(self::SCOPE, Acl\Table::ACTION_EDIT) !== Acl\Table::LEVEL_YES) { throw new Forbidden(); } $config = $this->config; $currencyList = $config->get('currencyList') ?? []; foreach (get_object_vars($rates) as $key => $value) { if (!is_string($key) || !in_array($key, $currencyList)) { unset($rates->$key); continue; } if (!is_numeric($value) || is_string($value)) { throw new BadRequest(); } if ($value < 0) { throw new BadRequest(); } } foreach ($currencyList as $currency) { if ($currency == $config->get('baseCurrency')) { continue; } if (!isset($rates->$currency)) { $rates->$currency = $config->get('currencyRates.' . $currency) ?? 1.0; } } $this->configWriter->set('currencyRates', $rates); $this->configWriter->save(); $this->dataManager->rebuildDatabase([]); return (object) ( $config->get('currencyRates') ?? [] ); } }