|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * Pimcore |
| 6 | + * |
| 7 | + * This source file is available under two different licenses: |
| 8 | + * - GNU General Public License version 3 (GPLv3) |
| 9 | + * - Pimcore Commercial License (PCL) |
| 10 | + * Full copyright and license information is available in |
| 11 | + * LICENSE.md which is distributed with this source code. |
| 12 | + * |
| 13 | + * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) |
| 14 | + * @license http://www.pimcore.org/license GPLv3 and PCL |
| 15 | + */ |
| 16 | + |
| 17 | +namespace AdvancedObjectSearchBundle\Factory\OpenSearch; |
| 18 | + |
| 19 | +use AdvancedObjectSearchBundle\Service; |
| 20 | +use AdvancedObjectSearchBundle\Tools\IndexConfigService; |
| 21 | +use OpenSearch\ClientBuilder; |
| 22 | +use Pimcore\Bundle\ElasticsearchClientBundle\SearchClient\ElasticsearchClientInterface; |
| 23 | +use Pimcore\Bundle\OpenSearchClientBundle\SearchClient\OpenSearchClientInterface; |
| 24 | +use Pimcore\SearchClient\SearchClientInterface; |
| 25 | +use Pimcore\Security\User\TokenStorageUserResolver; |
| 26 | +use Pimcore\Translation\Translator; |
| 27 | +use Psr\Container\ContainerInterface; |
| 28 | +use Psr\Log\LoggerInterface; |
| 29 | +use RuntimeException; |
| 30 | +use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 31 | + |
| 32 | +/** |
| 33 | + * @internal |
| 34 | + * @deprecated will be removed in version 7.0 |
| 35 | + */ |
| 36 | +final readonly class LegacyServiceFactory |
| 37 | +{ |
| 38 | + public function __construct( |
| 39 | + private LoggerInterface $logger, |
| 40 | + private TokenStorageUserResolver $userResolver, |
| 41 | + private EventDispatcherInterface $eventDispatcher, |
| 42 | + private Translator $translator, |
| 43 | + private IndexConfigService $indexConfigService, |
| 44 | + private SearchClientInterface $client |
| 45 | + ) |
| 46 | + { |
| 47 | + |
| 48 | + } |
| 49 | + |
| 50 | + public function create( |
| 51 | + ContainerInterface $filterLocator |
| 52 | + ): Service |
| 53 | + { |
| 54 | + $openSearchClient = match (true) { |
| 55 | + $this->client instanceof OpenSearchClientInterface => $this->client->getOriginalClient(), |
| 56 | + $this->client instanceof ElasticsearchClientInterface => ClientBuilder::create()->build(), |
| 57 | + default => null, |
| 58 | + }; |
| 59 | + |
| 60 | + if ($openSearchClient === null) { |
| 61 | + throw new RuntimeException('No client found for OpenSearch'); |
| 62 | + } |
| 63 | + |
| 64 | + $service = new Service( |
| 65 | + $this->logger, |
| 66 | + $this->userResolver, |
| 67 | + $filterLocator, |
| 68 | + $this->eventDispatcher, |
| 69 | + $this->translator, |
| 70 | + $this->indexConfigService, |
| 71 | + $openSearchClient |
| 72 | + ); |
| 73 | + |
| 74 | + $service->setSearchClientInterface($this->client); |
| 75 | + |
| 76 | + return $service; |
| 77 | + } |
| 78 | +} |
0 commit comments