|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Omikron\FactFinder\Oxid\Utilities\Ssr; |
| 6 | + |
| 7 | +use Omikron\FactFinder\Communication\Client\ClientBuilder; |
| 8 | +use Omikron\FactFinder\Communication\Version; |
| 9 | +use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface; |
| 10 | + |
| 11 | +class SearchAdapter |
| 12 | +{ |
| 13 | + public function __construct( |
| 14 | + private ClientBuilder $clientBuilder, |
| 15 | + private ModuleSettingServiceInterface $moduleSettingService, |
| 16 | + ) { |
| 17 | + } |
| 18 | + |
| 19 | + public function search(string $paramString, bool $navigationRequest): string |
| 20 | + { |
| 21 | + $client = $this->clientBuilder |
| 22 | + ->withServerUrl((string) $this->moduleSettingService->getString('ffServerUrl', 'ffwebcomponents')) |
| 23 | + ->withApiKey((string) $this->moduleSettingService->getString('ffApiKey', 'ffwebcomponents')) |
| 24 | + ->withVersion(Version::NG) |
| 25 | + ->build(); |
| 26 | + |
| 27 | + $endpoint = $this->createEndpoint($paramString, $navigationRequest); |
| 28 | + $response = $client->request('GET', $endpoint); |
| 29 | + |
| 30 | + return $response->getBody()->getContents(); |
| 31 | + } |
| 32 | + |
| 33 | + private function createEndpoint(string $paramString, bool $navigationRequest): string |
| 34 | + { |
| 35 | + $channel = (string) $this->moduleSettingService->getCollection('ffChannel', 'ffwebcomponents')['en']; |
| 36 | + $endpoint = $navigationRequest ? 'navigation' : 'search'; |
| 37 | + |
| 38 | + return "rest/v5/{$endpoint}/{$channel}?{$paramString}"; |
| 39 | + } |
| 40 | +} |
0 commit comments