walletApiUrl) && trim($this->walletApiUrl) !== ''; } public function hasSsoSecret(): bool { return is_string($this->ssoJwtSecret) && $this->ssoJwtSecret !== ''; } /** * 可安全写入 Cache 的数组形态(避免 readonly 对象序列化产生 __PHP_Incomplete_Class)。 * * @return array */ public function toCacheArray(): array { return [ 'site_code' => $this->siteCode, 'enabled' => $this->enabled, 'wallet_api_url' => $this->walletApiUrl, 'wallet_debit_path' => $this->walletDebitPath, 'wallet_credit_path' => $this->walletCreditPath, 'wallet_balance_path' => $this->walletBalancePath, 'sso_jwt_secret' => $this->ssoJwtSecret, 'wallet_api_key' => $this->walletApiKey, 'wallet_timeout_seconds' => $this->walletTimeoutSeconds, 'source' => $this->source, ]; } /** * @param array $data */ public static function fromCacheArray(array $data): self { return new self( siteCode: (string) ($data['site_code'] ?? ''), enabled: (bool) ($data['enabled'] ?? false), walletApiUrl: isset($data['wallet_api_url']) && is_string($data['wallet_api_url']) && $data['wallet_api_url'] !== '' ? $data['wallet_api_url'] : null, walletDebitPath: (string) ($data['wallet_debit_path'] ?? '/wallet/debit-for-lottery'), walletCreditPath: (string) ($data['wallet_credit_path'] ?? '/wallet/credit-from-lottery'), walletBalancePath: (string) ($data['wallet_balance_path'] ?? '/wallet/balance'), ssoJwtSecret: isset($data['sso_jwt_secret']) && is_string($data['sso_jwt_secret']) && $data['sso_jwt_secret'] !== '' ? $data['sso_jwt_secret'] : null, walletApiKey: isset($data['wallet_api_key']) && is_string($data['wallet_api_key']) && $data['wallet_api_key'] !== '' ? $data['wallet_api_key'] : null, walletTimeoutSeconds: max(1, (int) ($data['wallet_timeout_seconds'] ?? 10)), source: (string) ($data['source'] ?? self::SOURCE_DATABASE), ); } }