summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Connection.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Connection.php')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Connection.php138
1 files changed, 92 insertions, 46 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Connection.php b/vendor/ruflin/elastica/lib/Elastica/Connection.php
index b9d910c9..0084b6ee 100644
--- a/vendor/ruflin/elastica/lib/Elastica/Connection.php
+++ b/vendor/ruflin/elastica/lib/Elastica/Connection.php
@@ -1,30 +1,28 @@
<?php
-
namespace Elastica;
+
use Elastica\Exception\InvalidException;
use Elastica\Transport\AbstractTransport;
/**
- * Elastica connection instance to an elasticasearch node
+ * Elastica connection instance to an elasticasearch node.
*
- * @category Xodoa
- * @package Elastica
* @author Nicolas Ruflin <spam@ruflin.com>
*/
class Connection extends Param
{
/**
- * Default elastic search port
+ * Default elastic search port.
*/
const DEFAULT_PORT = 9200;
/**
- * Default host
+ * Default host.
*/
const DEFAULT_HOST = 'localhost';
/**
- * Default transport
+ * Default transport.
*
* @var string
*/
@@ -37,7 +35,14 @@ class Connection extends Param
const TIMEOUT = 300;
/**
- * Creates a new connection object. A connection is enabled by default
+ * Number of seconds after a connection timeout occurs for every request during the connection phase.
+ *
+ * @see Connection::setConnectTimeout();
+ */
+ const CONNECT_TIMEOUT = 0;
+
+ /**
+ * Creates a new connection object. A connection is enabled by default.
*
* @param array $params OPTIONAL Connection params: host, port, transport, timeout. All are optional
*/
@@ -57,12 +62,13 @@ class Connection extends Param
*/
public function getPort()
{
- return $this->hasParam('port')?$this->getParam('port'):self::DEFAULT_PORT;
+ return $this->hasParam('port') ? $this->getParam('port') : self::DEFAULT_PORT;
}
/**
- * @param int $port
- * @return \Elastica\Connection
+ * @param int $port
+ *
+ * @return $this
*/
public function setPort($port)
{
@@ -74,12 +80,13 @@ class Connection extends Param
*/
public function getHost()
{
- return $this->hasParam('host')?$this->getParam('host'):self::DEFAULT_HOST;
+ return $this->hasParam('host') ? $this->getParam('host') : self::DEFAULT_HOST;
}
/**
- * @param string $host
- * @return \Elastica\Connection
+ * @param string $host
+ *
+ * @return $this
*/
public function setHost($host)
{
@@ -91,7 +98,7 @@ class Connection extends Param
*/
public function getProxy()
{
- return $this->hasParam('proxy')?$this->getParam('proxy'):null;
+ return $this->hasParam('proxy') ? $this->getParam('proxy') : null;
}
/**
@@ -99,8 +106,10 @@ class Connection extends Param
* empty string to disable proxy and proxy string to set actual http proxy.
*
* @see http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROXY
- * @param string|null $proxy
- * @return \Elastica\Connection
+ *
+ * @param string|null $proxy
+ *
+ * @return $this
*/
public function setProxy($proxy)
{
@@ -112,12 +121,13 @@ class Connection extends Param
*/
public function getTransport()
{
- return $this->hasParam('transport')?$this->getParam('transport'):self::DEFAULT_TRANSPORT;
+ return $this->hasParam('transport') ? $this->getParam('transport') : self::DEFAULT_TRANSPORT;
}
/**
- * @param string|array $transport
- * @return \Elastica\Connection
+ * @param string|array $transport
+ *
+ * @return $this
*/
public function setTransport($transport)
{
@@ -129,12 +139,13 @@ class Connection extends Param
*/
public function getPath()
{
- return $this->hasParam('path')?$this->getParam('path'):'';
+ return $this->hasParam('path') ? $this->getParam('path') : '';
}
/**
- * @param string $path
- * @return \Elastica\Connection
+ * @param string $path
+ *
+ * @return $this
*/
public function setPath($path)
{
@@ -142,8 +153,9 @@ class Connection extends Param
}
/**
- * @param int $timeout Timeout in seconds
- * @return \Elastica\Connection
+ * @param int $timeout Timeout in seconds
+ *
+ * @return $this
*/
public function setTimeout($timeout)
{
@@ -155,14 +167,40 @@ class Connection extends Param
*/
public function getTimeout()
{
- return (int) $this->hasParam('timeout')?$this->getParam('timeout'):self::TIMEOUT;
+ return (int) $this->hasParam('timeout') ? $this->getParam('timeout') : self::TIMEOUT;
}
/**
- * Enables a connection
+ * Number of seconds after a connection timeout occurs for every request during the connection phase.
+ * Use a small value if you need a fast fail in case of dead, unresponsive or unreachable servers (~5 sec).
+ *
+ * Set to zero to switch to the default built-in connection timeout (300 seconds in curl).
+ *
+ * @see http://curl.haxx.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html
*
- * @param bool $enabled OPTIONAL (default = true)
- * @return \Elastica\Connection
+ * @param int $timeout Connect timeout in seconds
+ *
+ * @return $this
+ */
+ public function setConnectTimeout($timeout)
+ {
+ return $this->setParam('connectTimeout', $timeout);
+ }
+
+ /**
+ * @return int Connection timeout in seconds
+ */
+ public function getConnectTimeout()
+ {
+ return (int) $this->hasParam('connectTimeout') ? $this->getParam('connectTimeout') : self::CONNECT_TIMEOUT;
+ }
+
+ /**
+ * Enables a connection.
+ *
+ * @param bool $enabled OPTIONAL (default = true)
+ *
+ * @return $this
*/
public function setEnabled($enabled = true)
{
@@ -178,10 +216,11 @@ class Connection extends Param
}
/**
- * Returns an instance of the transport type
+ * Returns an instance of the transport type.
+ *
+ * @throws \Elastica\Exception\InvalidException If invalid transport type
*
* @return \Elastica\Transport\AbstractTransport Transport object
- * @throws \Elastica\Exception\InvalidException If invalid transport type
*/
public function getTransportObject()
{
@@ -195,12 +234,13 @@ class Connection extends Param
*/
public function isPersistent()
{
- return (bool) $this->hasParam('persistent')?$this->getParam('persistent'):true;
+ return (bool) $this->hasParam('persistent') ? $this->getParam('persistent') : true;
}
/**
- * @param array $config
- * @return \Elastica\Connection
+ * @param array $config
+ *
+ * @return $this
*/
public function setConfig(array $config)
{
@@ -208,9 +248,10 @@ class Connection extends Param
}
/**
- * @param string $key
- * @param mixed $value
- * @return \Elastica\Connection
+ * @param string $key
+ * @param mixed $value
+ *
+ * @return $this
*/
public function addConfig($key, $value)
{
@@ -220,7 +261,8 @@ class Connection extends Param
}
/**
- * @param string $key
+ * @param string $key
+ *
* @return bool
*/
public function hasConfig($key)
@@ -232,11 +274,13 @@ class Connection extends Param
/**
* Returns a specific config key or the whole
- * config array if not set
+ * config array if not set.
+ *
+ * @param string $key Config key
*
- * @param string $key Config key
* @throws \Elastica\Exception\InvalidException
- * @return array|string Config value
+ *
+ * @return array|string Config value
*/
public function getConfig($key = '')
{
@@ -246,25 +290,27 @@ class Connection extends Param
}
if (!array_key_exists($key, $config)) {
- throw new InvalidException('Config key is not set: ' . $key);
+ throw new InvalidException('Config key is not set: '.$key);
}
return $config[$key];
}
/**
- * @param \Elastica\Connection|array $params Params to create a connection
+ * @param \Elastica\Connection|array $params Params to create a connection
+ *
* @throws Exception\InvalidException
- * @return \Elastica\Connection
+ *
+ * @return self
*/
public static function create($params = array())
{
$connection = null;
- if ($params instanceof Connection) {
+ if ($params instanceof self) {
$connection = $params;
} elseif (is_array($params)) {
- $connection = new Connection($params);
+ $connection = new self($params);
} else {
throw new InvalidException('Invalid data type');
}