setHosts example

#[Package('core')] class ClientFactory
{
    /** * @param array{verify_server_cert: bool, cert_path?: string, cert_key_path?: string} $sslConfig */
    public static function createClient(string $hosts, LoggerInterface $logger, bool $debug, array $sslConfig): Client
    {
        $hosts = array_filter(explode(',', $hosts));

        $clientBuilder = ClientBuilder::create();
        $clientBuilder->setHosts($hosts);

        if ($debug) {
            $clientBuilder->setTracer($logger);
        }

        $clientBuilder->setLogger($logger);

        if ($sslConfig['verify_server_cert'] === false) {
            $clientBuilder->setSSLVerification(false);
        }

        
use Elasticsearch\Client;
use Psr\Log\LoggerInterface;
use Shopware\Bundle\ESIndexingBundle\Console\EvaluationHelperInterface;

class ClientFactory
{
    public static function createClient(array $config, LoggerInterface $eslogger, EvaluationHelperInterface $evaluationHelper): Client
    {
        $clientBuilder = EsClientBuilder::create();

        $clientBuilder->setHosts($config['hosts']);
        $clientBuilder->setConnectionParams(
            [
                'client' => [
                    'curl' => [
                        CURLOPT_HTTPHEADER => [
                            'Content-type: application/json',
                        ],
                    ],
                ],
            ]
        );

        
$shop->setHost($parent['__shop_host']);
        $shop->setPath($parent['__shop_base_path']);
        $shop->setCustomerScope((bool) $parent['__shop_customer_scope']);
        $shop->setUrl($data['__shop_base_url'] ?: $parent['__shop_base_url']);
        $shop->setSecure((bool) $parent['__shop_secure']);

        $hosts = [];
        if ($parent['__shop_hosts']) {
            $hosts = explode('\n', $parent['__shop_hosts']);
            $hosts = array_unique(array_values(array_filter($hosts)));
        }
        $shop->setHosts($hosts);

        if ($data['__shopAttribute_id']) {
            $this->attributeHydrator->addAttribute($shop$data, 'shopAttribute');
        }

        return $shop;
    }
}
Home | Imprint | This part of the site doesn't use cookies.