>|null */ private static ?array $memo = null; private static bool $loaded = false; /** * همهٔ کلیدهای سوپرادمین (حتی value خالی). null = سوپرادمین در دسترس نبود. * * @return array>|null */ public function catalogMap(): ?array { return $this->load(); } /** * فقط کلیدهایی که سوپرادمین مقدار غیرخالی دارد — برای ConfigService. * * @return array>|null */ public function map(): ?array { $full = $this->load(); if ($full === null) { return null; } $withValue = []; foreach ($full as $key => $row) { $value = is_array($row) ? ($row['value'] ?? null) : null; if ($value === null || $value === '') { continue; } $withValue[$key] = $row; } return $withValue; } /** * @return array>|null */ private function load(): ?array { if (self::$loaded) { return self::$memo; } self::$loaded = true; $items = app(SuperAdminProgramSettingsClient::class)->fetchItems(); if ($items !== null) { $this->rememberLastGood($items); } else { $items = $this->lastGoodItems(); } if ($items === null) { self::$memo = null; return null; } $map = []; foreach ($items as $row) { if (! is_array($row)) { continue; } $key = trim((string) ($row['key'] ?? '')); if ($key === '' || ! self::isSuperAdminOwned($key)) { continue; } $map[$key] = $row; } self::$memo = $map; return $map; } /** @param array> $items */ private function rememberLastGood(array $items): void { try { Cache::put( self::LAST_GOOD_CACHE_KEY, $items, now()->addMinutes(self::LAST_GOOD_CACHE_MINUTES) ); } catch (\Throwable $e) { // کش در دسترس نیست — همان رفتار قبلی } } /** * @return array>|null */ private function lastGoodItems(): ?array { try { $cached = Cache::get(self::LAST_GOOD_CACHE_KEY); } catch (\Throwable $e) { return null; } return is_array($cached) && $cached !== [] ? $cached : null; } /** * @return array> */ public function items(): array { $map = $this->map(); if ($map === null || $map === []) { return []; } return array_values($map); } /** * @return array|null */ public function row(string $key): ?array { $map = $this->map(); if ($map === null) { return null; } $key = trim($key); if ($key === '' || ! array_key_exists($key, $map)) { return null; } return $map[$key]; } public static function isRuntime(string $key): bool { return in_array($key, self::RUNTIME_KEYS, true); } public static function isLocalOwned(string $key): bool { return in_array($key, self::LOCAL_OWNED_KEYS, true); } public static function isSuperAdminOwned(string $key): bool { return in_array(trim($key), self::SUPERADMIN_OWNED_KEYS, true); } }