. */ namespace SP\Modules\Web\Controllers\Traits; use Exception; use SP\Domain\Common\Dtos\ActionResponse; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Core\Exceptions\SPException; use function SP\__u; use function SP\processException; /** * Trait ConfigTrait * * @package SP\Modules\Web\Controllers\Traits */ trait ConfigTrait { /** * Guardar la configuración * * @throws SPException */ protected function saveConfig( ConfigDataInterface $configData, ConfigFileService $config, callable $onSuccess = null ): ActionResponse { try { if ($configData->isDemoEnabled()) { return ActionResponse::warning(__u('Ey, this is a DEMO!!')); } $config->save($configData); if ($onSuccess !== null) { $onSuccess(); } return ActionResponse::ok(__u('Configuration updated')); } catch (Exception $e) { processException($e); return ActionResponse::error(__u('Error while saving the configuration')); } } }