entries(get_transient(self::CACHE_TRANSIENT))[$target] ?? null; if (! is_array($entry) || ! is_int($entry['until'] ?? null) || ! (is_string($entry['body'] ?? null) || ($entry['body'] ?? null) === null)) { return null; } return ['body' => $entry['body'], 'until' => $entry['until']]; } public function saveCached(string $target, ?string $body, int $until): void { $entries = $this->entries(get_transient(self::CACHE_TRANSIENT)); // ans Ende stellen: trim() behält die zuletzt geschriebenen unset($entries[$target]); $entries[$target] = ['body' => $body, 'until' => $until]; set_transient(self::CACHE_TRANSIENT, self::trim($entries), SecurityTxtSource::CACHE_SECONDS); } public function forgetCached(): void { delete_transient(self::CACHE_TRANSIENT); } public function lastGood(string $target): ?string { $body = $this->entries(get_option(self::LAST_GOOD_OPTION, null))[$target] ?? null; return is_string($body) ? $body : null; } public function saveLastGood(string $target, ?string $body): void { $entries = $this->entries(get_option(self::LAST_GOOD_OPTION, null)); if ($body === null && ! array_key_exists($target, $entries)) { return; } unset($entries[$target]); if ($body !== null) { $entries[$target] = $body; } if ($entries === []) { delete_option(self::LAST_GOOD_OPTION); return; } update_option(self::LAST_GOOD_OPTION, self::trim($entries), false); } /** * @return array */ private function entries(mixed $raw): array { return is_array($raw) ? $raw : []; } /** * Die zuletzt geschriebenen Ziele behalten. * * @param array $entries * @return array */ private static function trim(array $entries): array { return array_slice($entries, -self::MAX_TARGETS, null, true); } }