|null The images array or null if unavailable */ public function getProductImages(string $productCode, ?string $hotelCode = null): ?array { $result = $this->getProductDetails($productCode, $hotelCode); if (true === isset($result['success']) && false === $result['success']) { return null; } return $result['hotel']['images'] ?? null; } /** * @return array|null */ public function getHotelImages(string $hotelCode): ?array { return $this->getHotelDetails($hotelCode)?->images; } public function getHotelDetails(string $hotelCode): ?CmsHotelData { $data = $this->fetchHotelDetails($hotelCode); if (isset($data['success']) && false === $data['success']) { return null; } return $this->mapHotelData($data); } /** * @return array{ * success?: bool, * message?: string, * name?: string, * address?: string, * description?: string, * features?: string, * room_types?: string, * additional_information?: string, * images?: array, * icons?: list, * region?: array{ * name: string, * latitude: float, * longitude: float, * webcam: string, * ski_area: string, * ski_area_extended: string, * description: string, * news: string, * length: int, * altitude: int, * lifts: int, * images: array, * region_maps: list, * }, * } */ private function fetchHotelDetails(string $hotelCode): array { return $this->cache->get( sprintf('cms_hotel_%s', $hotelCode), function (ItemInterface $item) use ($hotelCode): array { $item->expiresAfter(3600); try { $request = $this->httpClient->request('GET', 'api/hotel', [ 'query' => [ 'hotel' => $hotelCode, 'key' => $this->apiKey, ], ]); } catch (ExceptionInterface $e) { $item->expiresAfter(0); return [ 'success' => false, 'message' => $e->getMessage(), ]; } try { $data = $request->toArray(); } catch (ExceptionInterface $e) { $item->expiresAfter(0); return [ 'success' => false, 'message' => $e->getMessage(), ]; } return $data; } ); } /** * @param array $data see {@see self::fetchHotelDetails()} for the shape */ private function mapHotelData(array $data): CmsHotelData { return new CmsHotelData( name: $data['name'] ?? null, address: $data['address'] ?? null, images: $data['images'] ?? null, description: $data['description'] ?? null, features: $data['features'] ?? null, roomTypes: $data['room_types'] ?? null, additionalInformation: $data['additional_information'] ?? null, icons: $data['icons'] ?? null, region: isset($data['region']) ? $this->mapRegionData($data['region']) : null, ); } /** * @param array $region see {@see self::fetchHotelDetails()} for the shape */ private function mapRegionData(array $region): CmsRegionData { return new CmsRegionData( name: $region['name'] ?? null, latitude: self::toFloatOrNull($region['latitude'] ?? null), longitude: self::toFloatOrNull($region['longitude'] ?? null), webcam: $region['webcam'] ?? null, skiArea: $region['ski_area'] ?? null, skiAreaExtended: $region['ski_area_extended'] ?? null, description: $region['description'] ?? null, news: $region['news'] ?? null, length: self::toIntOrNull($region['length'] ?? null), altitude: self::toIntOrNull($region['altitude'] ?? null), lifts: self::toIntOrNull($region['lifts'] ?? null), images: $region['images'] ?? null, regionMaps: $region['region_maps'] ?? null, ); } private static function toIntOrNull(mixed $value): ?int { return is_numeric($value) ? (int) $value : null; } private static function toFloatOrNull(mixed $value): ?float { return is_numeric($value) ? (float) $value : null; } /** @return array */ public function getProductDetails(string $productCode, ?string $hotelCode = null): array { return $this->cache->get( sprintf('cms_product_%s_%s', $productCode, $hotelCode ?? ''), function (ItemInterface $item) use ($productCode, $hotelCode): array { $item->expiresAfter(3600); try { $request = $this->httpClient->request('GET', 'api/product', [ 'query' => [ 'product' => $productCode, 'hotel' => $hotelCode, 'key' => $this->apiKey, ], ]); } catch (ExceptionInterface $e) { $item->expiresAfter(0); return [ 'success' => false, 'message' => $e->getMessage(), ]; } try { $data = $request->toArray(); } catch (ExceptionInterface $e) { $item->expiresAfter(0); return [ 'success' => false, 'message' => $e->getMessage(), ]; } return $data; } ); } }