PHP Class yii\elasticsearch\Connection

Since: 2.0
Author: Carsten Brandt ([email protected])
Inheritance: extends yii\base\Component
Afficher le fichier Open project: yiisoft/yii2-elasticsearch Class Usage Examples

Méthodes publiques

Свойство Type Description
$activeNode the active node. Key of one of the [[nodes]]. Will be randomly selected on Connection::open.
$auth Authentication data used to connect to the ElasticSearch node. Array elements: - username: the username for authentication. - password: the password for authentication. Array either MUST contain both username and password on not contain any authentication credentials.
$autodetectCluster whether to autodetect available cluster nodes on Connection::open
$connectionTimeout timeout to use for connecting to an elasticsearch node. This value will be used to configure the curl CURLOPT_CONNECTTIMEOUT option. If not set, no explicit timeout will be set for curl.
$dataTimeout timeout to use when reading the response from an elasticsearch node. This value will be used to configure the curl CURLOPT_TIMEOUT option. If not set, no explicit timeout will be set for curl.
$defaultProtocol If [[autodetectCluster]] is true, all nodes received from cluster will be set to use the protocol defined by [[defaultProtocol]]
$nodes The elasticsearch cluster nodes to connect to. This is populated with the result of a cluster nodes request when [[autodetectCluster]] is true. Additional special options: - auth: overrides [[auth]] property. For example: php [ 'http_address' => 'inet[/127.0.0.1:9200]', 'auth' => ['username' => 'yiiuser', 'password' => 'yiipw'], // Overrides the auth property of the class with specific login and password 'auth' => ['username' => 'yiiuser', 'password' => 'yiipw'], // Disabled auth regardless of auth property of the class ] - protocol: explicitly sets the protocol for the current node (useful when manually defining a HTTPS cluster)

Méthodes publiques

Méthode Description
__sleep ( ) : array Closes the connection when this component is being serialized.
close ( ) Closes the currently active DB connection.
createBulkCommand ( array $config = [] ) : BulkCommand Creates a bulk command for execution.
createCommand ( array $config = [] ) : Command Creates a command for execution.
delete ( string | array $url, array $options = [], string $body = null, boolean $raw = false ) : mixed Performs DELETE HTTP request
get ( string | array $url, array $options = [], string $body = null, boolean $raw = false ) : mixed Performs GET HTTP request
getClusterState ( )
getDriverName ( ) : string Returns the name of the DB driver for the current [[dsn]].
getIsActive ( ) : boolean Returns a value indicating whether the DB connection is established.
getNodeInfo ( )
getQueryBuilder ( ) : QueryBuilder Creates new query builder instance
head ( string | array $url, array $options = [], string $body = null ) : mixed Performs HEAD HTTP request
init ( )
open ( ) Establishes a DB connection.
post ( string | array $url, array $options = [], string $body = null, boolean $raw = false ) : mixed Performs POST HTTP request
put ( string | array $url, array $options = [], string $body = null, boolean $raw = false ) : mixed Performs PUT HTTP request

Méthodes protégées

Méthode Description
decodeErrorBody ( $body ) : mixed Try to decode error information if it is valid json, return it if not.
httpRequest ( string $method, string $url, string $requestBody = null, boolean $raw = false ) : mixed Performs HTTP request
initConnection ( ) Initializes the DB connection.
populateNodes ( ) Populates [[nodes]] with the result of a cluster nodes request.
selectActiveNode ( ) select active node randomly

Private Methods

Méthode Description
createUrl ( string | array $path, array $options = [] ) : array Creates URL
resetCurlHandle ( )

Method Details

__sleep() public méthode

Closes the connection when this component is being serialized.
public __sleep ( ) : array
Résultat array

close() public méthode

It does nothing if the connection is already closed.
public close ( )

createBulkCommand() public méthode

Creates a bulk command for execution.
Since: 2.0.5
public createBulkCommand ( array $config = [] ) : BulkCommand
$config array the configuration for the [[BulkCommand]] class
Résultat BulkCommand the DB command

createCommand() public méthode

Creates a command for execution.
public createCommand ( array $config = [] ) : Command
$config array the configuration for the Command class
Résultat Command the DB command

decodeErrorBody() protected méthode

Try to decode error information if it is valid json, return it if not.
protected decodeErrorBody ( $body ) : mixed
$body
Résultat mixed

delete() public méthode

Performs DELETE HTTP request
public delete ( string | array $url, array $options = [], string $body = null, boolean $raw = false ) : mixed
$url string | array URL
$options array URL options
$body string request body
$raw boolean if response body contains JSON and should be decoded
Résultat mixed response

get() public méthode

Performs GET HTTP request
public get ( string | array $url, array $options = [], string $body = null, boolean $raw = false ) : mixed
$url string | array URL
$options array URL options
$body string request body
$raw boolean if response body contains JSON and should be decoded
Résultat mixed response

getClusterState() public méthode

public getClusterState ( )

getDriverName() public méthode

Returns the name of the DB driver for the current [[dsn]].
public getDriverName ( ) : string
Résultat string name of the DB driver

getIsActive() public méthode

Returns a value indicating whether the DB connection is established.
public getIsActive ( ) : boolean
Résultat boolean whether the DB connection is established

getNodeInfo() public méthode

public getNodeInfo ( )

getQueryBuilder() public méthode

Creates new query builder instance
public getQueryBuilder ( ) : QueryBuilder
Résultat QueryBuilder

head() public méthode

Performs HEAD HTTP request
public head ( string | array $url, array $options = [], string $body = null ) : mixed
$url string | array URL
$options array URL options
$body string request body
Résultat mixed response

httpRequest() protected méthode

Performs HTTP request
protected httpRequest ( string $method, string $url, string $requestBody = null, boolean $raw = false ) : mixed
$method string method name
$url string URL
$requestBody string request body
$raw boolean if response body contains JSON and should be decoded
Résultat mixed if request failed

init() public méthode

public init ( )

initConnection() protected méthode

This method is invoked right after the DB connection is established. The default implementation triggers an [[EVENT_AFTER_OPEN]] event.
protected initConnection ( )

open() public méthode

It does nothing if a DB connection has already been established.
public open ( )

populateNodes() protected méthode

Populates [[nodes]] with the result of a cluster nodes request.
Since: 2.0.4
protected populateNodes ( )

post() public méthode

Performs POST HTTP request
public post ( string | array $url, array $options = [], string $body = null, boolean $raw = false ) : mixed
$url string | array URL
$options array URL options
$body string request body
$raw boolean if response body contains JSON and should be decoded
Résultat mixed response

put() public méthode

Performs PUT HTTP request
public put ( string | array $url, array $options = [], string $body = null, boolean $raw = false ) : mixed
$url string | array URL
$options array URL options
$body string request body
$raw boolean if response body contains JSON and should be decoded
Résultat mixed response

selectActiveNode() protected méthode

select active node randomly
protected selectActiveNode ( )

Property Details

$activeNode public_oe property

the active node. Key of one of the [[nodes]]. Will be randomly selected on Connection::open.
public $activeNode

$auth public_oe property

Authentication data used to connect to the ElasticSearch node. Array elements: - username: the username for authentication. - password: the password for authentication. Array either MUST contain both username and password on not contain any authentication credentials.
See also: http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_configuration.html#_example_configuring_http_basic_auth
public $auth

$autodetectCluster public_oe property

whether to autodetect available cluster nodes on Connection::open
public $autodetectCluster

$connectionTimeout public_oe property

timeout to use for connecting to an elasticsearch node. This value will be used to configure the curl CURLOPT_CONNECTTIMEOUT option. If not set, no explicit timeout will be set for curl.
public $connectionTimeout

$dataTimeout public_oe property

timeout to use when reading the response from an elasticsearch node. This value will be used to configure the curl CURLOPT_TIMEOUT option. If not set, no explicit timeout will be set for curl.
public $dataTimeout

$defaultProtocol public_oe property

If [[autodetectCluster]] is true, all nodes received from cluster will be set to use the protocol defined by [[defaultProtocol]]
Since: 2.0.5
public $defaultProtocol

$nodes public_oe property

The elasticsearch cluster nodes to connect to. This is populated with the result of a cluster nodes request when [[autodetectCluster]] is true. Additional special options: - auth: overrides [[auth]] property. For example: php [ 'http_address' => 'inet[/127.0.0.1:9200]', 'auth' => ['username' => 'yiiuser', 'password' => 'yiipw'], // Overrides the auth property of the class with specific login and password 'auth' => ['username' => 'yiiuser', 'password' => 'yiipw'], // Disabled auth regardless of auth property of the class ] - protocol: explicitly sets the protocol for the current node (useful when manually defining a HTTPS cluster)
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-nodes-info.html#cluster-nodes-info
public $nodes