本文整理汇总了PHP中Elasticsearch\ClientBuilder::defaultHandler方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientBuilder::defaultHandler方法的具体用法?PHP ClientBuilder::defaultHandler怎么用?PHP ClientBuilder::defaultHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elasticsearch\ClientBuilder
的用法示例。
在下文中一共展示了ClientBuilder::defaultHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* @return Client
*/
public function build()
{
$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();
}
if (is_null($this->connectionFactory)) {
$connectionParams = [];
$this->connectionFactory = new ConnectionFactory($this->handler, $connectionParams, $this->serializer, $this->logger, $this->tracer);
}
if (is_null($this->hosts)) {
$this->hosts = $this->getDefaultHost();
}
if (is_null($this->selector)) {
$this->selector = new Selectors\RoundRobinSelector();
} elseif (is_string($this->selector)) {
$this->selector = new $this->selector();
}
$this->buildTransport();
if (is_null($this->endpoint)) {
$transport = $this->transport;
$serializer = $this->serializer;
$this->endpoint = function ($class) use($transport, $serializer) {
$fullPath = '\\Elasticsearch\\Endpoints\\' . $class;
if ($class === 'Bulk' || $class === 'Msearch' || $class === 'MPercolate') {
return new $fullPath($transport, $serializer);
} else {
return new $fullPath($transport);
}
};
}
return new Client($this->transport, $this->endpoint);
}