in src/OpenSearch/ClientBuilder.php [519:628]
public function build(): Client
{
$this->buildLoggers();
if (is_null($this->handler)) {
$this->handler = ClientBuilder::defaultHandler();
}
$sslOptions = null;
if (isset($this->sslKey)) {
$sslOptions['ssl_key'] = $this->sslKey;
}
if (isset($this->sslCert)) {
$sslOptions['cert'] = $this->sslCert;
}
if (isset($this->sslVerification)) {
$sslOptions['verify'] = $this->sslVerification;
}
if (!is_null($sslOptions)) {
$sslHandler = function (callable $handler, array $sslOptions) {
return function (array $request) use ($handler, $sslOptions) {
// Add our custom headers
foreach ($sslOptions as $key => $value) {
$request['client'][$key] = $value;
}
// Send the request using the handler and return the response.
return $handler($request);
};
};
$this->handler = $sslHandler($this->handler, $sslOptions);
}
if (is_null($this->serializer)) {
$this->serializer = new SmartSerializer();
} elseif (is_string($this->serializer)) {
$this->serializer = new $this->serializer();
}
$this->connectionParams['client']['port_in_header'] = $this->includePortInHostHeader;
if (is_null($this->connectionFactory)) {
if (is_null($this->connectionParams)) {
$this->connectionParams = [];
}
// Make sure we are setting Content-Type and Accept (unless the user has explicitly
// overridden it
if (! isset($this->connectionParams['client']['headers'])) {
$this->connectionParams['client']['headers'] = [];
}
$apiVersioning = getenv('ELASTIC_CLIENT_APIVERSIONING');
if (! isset($this->connectionParams['client']['headers']['Content-Type'])) {
if ($apiVersioning === 'true' || $apiVersioning === '1') {
$this->connectionParams['client']['headers']['Content-Type'] = ['application/vnd.elasticsearch+json;compatible-with=7'];
} else {
$this->connectionParams['client']['headers']['Content-Type'] = ['application/json'];
}
}
if (! isset($this->connectionParams['client']['headers']['Accept'])) {
if ($apiVersioning === 'true' || $apiVersioning === '1') {
$this->connectionParams['client']['headers']['Accept'] = ['application/vnd.elasticsearch+json;compatible-with=7'];
} else {
$this->connectionParams['client']['headers']['Accept'] = ['application/json'];
}
}
$this->connectionFactory = new ConnectionFactory($this->handler, $this->connectionParams, $this->serializer, $this->logger, $this->tracer);
}
if (is_null($this->hosts)) {
$this->hosts = $this->getDefaultHost();
}
if (is_null($this->selector)) {
$this->selector = new RoundRobinSelector();
} elseif (is_string($this->selector)) {
$this->selector = new $this->selector();
}
$this->buildTransport();
if (is_null($this->endpoint)) {
$serializer = $this->serializer;
$this->endpoint = function ($class) use ($serializer) {
$fullPath = '\\OpenSearch\\Endpoints\\' . $class;
$reflection = new ReflectionClass($fullPath);
$constructor = $reflection->getConstructor();
if ($constructor && $constructor->getParameters()) {
return new $fullPath($serializer);
} else {
return new $fullPath();
}
};
}
$registeredNamespaces = [];
foreach ($this->registeredNamespacesBuilders as $builder) {
/**
* @var NamespaceBuilderInterface $builder
*/
$registeredNamespaces[$builder->getName()] = $builder->getObject($this->transport, $this->serializer);
}
return $this->instantiate($this->transport, $this->endpoint, $registeredNamespaces);
}