src/Search/Elastica/ClientManager.php
final public function getClient(string $cluster = 'default'): Client
    {
        if (isset($this->clients[$cluster])) {
            return $this->clients[$cluster];
        }

        if (!$this->hasCluster($cluster)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'The cluster [%s] is not one of the available clusters [%s].',
                    $cluster,
                    implode(',', $this->getAvailableClusters())
                )
            );
        }

        $config = $this->clusters[$cluster];

        if (isset($config['debug'])) {
            $config['log'] = filter_var($config['debug'], FILTER_VALIDATE_BOOLEAN);
            unset($config['debug']);
        } else {
            $config['log'] = false;
        }

        if (isset($config['round_robin'])) {
            $config['roundRobin'] = filter_var($config['round_robin'], FILTER_VALIDATE_BOOLEAN);
            unset($config['round_robin']);
        }

        $config = $this->configureCluster($cluster, $config);
        $servers = $config['servers'];
        $configuredServers = [];
        unset($config['servers']);

        foreach ($servers as $server) {
            $configuredServers[] = array_merge($config, $server);
        }

        $config['servers'] = $configuredServers;

        return $this->clients[$cluster] = new Client($config, null, $config['log'] ? $this->logger : null);
    }
final public function getClient(string $cluster = 'default'): Client
    {
        if (isset($this->clients[$cluster])) {
            return $this->clients[$cluster];
        }

        if (!$this->hasCluster($cluster)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'The cluster [%s] is not one of the available clusters [%s].',
                    $cluster,
                    implode(',', $this->getAvailableClusters())
                )
            );
        }

        $config = $this->clusters[$cluster];

        if (isset($config['debug'])) {
            $config['log'] = filter_var($config['debug'], FILTER_VALIDATE_BOOLEAN);
            unset($config['debug']);
        } else {
            $config['log'] = false;
        }

        if (isset($config['round_robin'])) {
            $config['roundRobin'] = filter_var($config['round_robin'], FILTER_VALIDATE_BOOLEAN);
            unset($config['round_robin']);
        }

        $config = $this->configureCluster($cluster, $config);
        $servers = $config['servers'];
        $configuredServers = [];
        unset($config['servers']);

        foreach ($servers as $server) {
            $configuredServers[] = array_merge($config, $server);
        }

        $config['servers'] = $configuredServers;

        return $this->clients[$cluster] = new Client($config, null, $config['log'] ? $this->logger : null);
    }
final public function getClient ( string $ cluster = 'default' ) : Client { if ( isset ( $ this -> clients [ $ cluster ] ) ) { return $ this -> clients [ $ cluster ] ; } if ( ! $ this -> hasCluster ( $ cluster ) ) { throw new \ InvalidArgumentException ( sprintf ( 'The cluster [%s] is not one of the available clusters [%s].' , $ cluster , implode ( ',' , $ this -> getAvailableClusters ( ) ) ) ) ; } $ config = $ this -> clusters [ $ cluster ] ; if ( isset ( $ config [ 'debug' ] ) ) { $ config [ 'log' ] = filter_var ( $ config [ 'debug' ] , FILTER_VALIDATE_BOOLEAN ) ; unset ( $ config [ 'debug' ] ) ; } else { $ config [ 'log' ] = false ; } if ( isset ( $ config [ 'round_robin' ] ) ) { $ config [ 'roundRobin' ] = filter_var ( $ config [ 'round_robin' ] , FILTER_VALIDATE_BOOLEAN ) ; unset ( $ config [ 'round_robin' ] ) ; } $ config = $ this -> configureCluster ( $ cluster , $ config ) ; $ servers = $ config [ 'servers' ] ; $ configuredServers = [ ] ; unset ( $ config [ 'servers' ] ) ; foreach ( $ servers as $ server ) { $ configuredServers [ ] = array_merge ( $ config , $ server ) ; } $ config [ 'servers' ] = $ configuredServers ; return $ this -> clients [ $ cluster ] = new Client ( $ config , null , $ config [ 'log' ] ? $ this -> logger : null ) ; }
Gets an elastica client using the config from the provided cluster name.

All calls with the same cluster name will return the same client instance.

@param string $cluster

@return Client
Gets an elastica client using the config from the provided cluster name .