settings->get(self::URL, '')); } /** * Nur die Adresse des Servers eingetragen? Dann gehört „/api/ex“ dazu. */ public static function normalizeUrl(string $url): string { $url = rtrim(trim($url), '/'); if ($url !== '' && in_array((string) parse_url($url, PHP_URL_PATH), ['', '/'], true)) { $url .= '/api/ex'; } return $url; } public function token(): string { return $this->decrypt(self::TOKEN); } public function secret(): string { return $this->decrypt(self::SECRET); } public function configured(): bool { return $this->url() !== '' && $this->token() !== '' && $this->secret() !== ''; } public function autoReserve(): ?bool { $value = $this->settings->get(self::AUTO_RESERVE); return $value === null ? null : (bool) $value; } public function intro(): ?string { return $this->settings->get(self::INTRO) ?: null; } /** * @param array{url: string, token?: ?string, secret?: ?string, auto_reserve: ?string, intro: ?string} $data leere Token/Secret = unverändert */ public function save(array $data): void { // Neue Adresse: Token und Secret neu eingeben – sonst gingen die gespeicherten an den neuen Server if (self::normalizeUrl($data['url']) !== $this->url() && $this->token() !== '' && (blank($data['token'] ?? null) || blank($data['secret'] ?? null))) { throw ValidationException::withMessages(['data.token' => 'Die Adresse wurde geändert – bitte Token und Signier-Secret erneut eingeben.']); } $this->settings->set(self::URL, self::normalizeUrl($data['url'])); foreach ([self::TOKEN => $data['token'] ?? null, self::SECRET => $data['secret'] ?? null] as $key => $value) { if (filled($value)) { $this->settings->set($key, Crypt::encryptString(trim($value))); } } $this->settings->set(self::AUTO_RESERVE, match ($data['auto_reserve'] ?? '') { 'yes' => true, 'no' => false, default => null, }); $this->settings->set(self::INTRO, $data['intro'] ?? null); } private function decrypt(string $key): string { $value = $this->settings->get($key); if (! is_string($value) || $value === '') { return ''; } try { return Crypt::decryptString($value); } catch (Throwable) { return ''; } } }