diff options
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Transport')
9 files changed, 405 insertions, 201 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Transport/AbstractTransport.php b/vendor/ruflin/elastica/lib/Elastica/Transport/AbstractTransport.php index d2ce0fb2..c40b5107 100644 --- a/vendor/ruflin/elastica/lib/Elastica/Transport/AbstractTransport.php +++ b/vendor/ruflin/elastica/lib/Elastica/Transport/AbstractTransport.php @@ -1,17 +1,14 @@ <?php - namespace Elastica\Transport; use Elastica\Connection; -use Elastica\Request; use Elastica\Exception\InvalidException; use Elastica\Param; +use Elastica\Request; /** - * Elastica Abstract Transport object + * Elastica Abstract Transport object. * - * @category Xodoa - * @package Elastica * @author Nicolas Ruflin <spam@ruflin.com> */ abstract class AbstractTransport extends Param @@ -22,7 +19,7 @@ abstract class AbstractTransport extends Param protected $_connection; /** - * Construct transport + * Construct transport. * * @param \Elastica\Connection $connection Connection object */ @@ -43,23 +40,28 @@ abstract class AbstractTransport extends Param /** * @param \Elastica\Connection $connection Connection object + * + * @return $this */ public function setConnection(Connection $connection) { $this->_connection = $connection; + + return $this; } /** - * Executes the transport request + * Executes the transport request. + * + * @param \Elastica\Request $request Request object + * @param array $params Hostname, port, path, ... * - * @param \Elastica\Request $request Request object - * @param array $params Hostname, port, path, ... * @return \Elastica\Response Response object */ abstract public function exec(Request $request, array $params); /** - * Create a transport + * Create a transport. * * The $transport parameter can be one of the following values: * @@ -68,10 +70,12 @@ abstract class AbstractTransport extends Param * * array: An array with a "type" key which must be set to one of the two options. All other * keys in the array will be set as parameters in the transport instance * - * @param mixed $transport A transport definition + * @param mixed $transport A transport definition * @param \Elastica\Connection $connection A connection instance - * @param array $params Parameters for the transport class + * @param array $params Parameters for the transport class + * * @throws \Elastica\Exception\InvalidException + * * @return AbstractTransport */ public static function create($transport, Connection $connection, array $params = array()) @@ -85,16 +89,16 @@ abstract class AbstractTransport extends Param } if (is_string($transport)) { - $className = 'Elastica\\Transport\\' . $transport; + $className = 'Elastica\\Transport\\'.$transport; if (!class_exists($className)) { throw new InvalidException('Invalid transport'); } - $transport = new $className; + $transport = new $className(); } - if ($transport instanceof AbstractTransport) { + if ($transport instanceof self) { $transport->setConnection($connection); foreach ($params as $key => $value) { diff --git a/vendor/ruflin/elastica/lib/Elastica/Transport/Guzzle.php b/vendor/ruflin/elastica/lib/Elastica/Transport/Guzzle.php index 96ad8971..5c98d83b 100644 --- a/vendor/ruflin/elastica/lib/Elastica/Transport/Guzzle.php +++ b/vendor/ruflin/elastica/lib/Elastica/Transport/Guzzle.php @@ -1,133 +1,132 @@ <?php - namespace Elastica\Transport; -use Elastica\Exception\Connection\HttpException; +use Elastica\Connection; use Elastica\Exception\Connection\GuzzleException; use Elastica\Exception\PartialShardFailureException; use Elastica\Exception\ResponseException; -use Elastica\Exception\InvalidException; -use Elastica\Connection; +use Elastica\JSON; use Elastica\Request; use Elastica\Response; -use Elastica\JSON; use GuzzleHttp\Client; use GuzzleHttp\Exception\TransferException; -use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Stream\Stream; /** - * Elastica Guzzle Transport object + * Elastica Guzzle Transport object. * - * @package Elastica * @author Milan Magudia <milan@magudia.com> */ class Guzzle extends AbstractTransport { /** - * Http scheme + * Http scheme. * * @var string Http scheme */ protected $_scheme = 'http'; /** - * Curl resource to reuse + * Curl resource to reuse. * * @var resource Guzzle resource to reuse */ protected static $_guzzleClientConnection = null; /** - * Makes calls to the elasticsearch server + * Makes calls to the elasticsearch server. * * All calls that are made to the server are done through this function * - * @param \Elastica\Request $request - * @param array $params Host, Port, ... + * @param \Elastica\Request $request + * @param array $params Host, Port, ... + * * @throws \Elastica\Exception\ConnectionException * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\Connection\HttpException - * @return \Elastica\Response Response object + * + * @return \Elastica\Response Response object */ public function exec(Request $request, array $params) { $connection = $this->getConnection(); - try { - $client = $this->_getGuzzleClient($this->_getBaseUrl($connection), $connection->isPersistent()); + $client = $this->_getGuzzleClient($this->_getBaseUrl($connection), $connection->isPersistent()); - $options = array(); - if ($connection->getTimeout()) { - $options['timeout'] = $connection->getTimeout(); - } + $options = array( + 'exceptions' => false, // 4xx and 5xx is expected and NOT an exceptions in this context + ); + if ($connection->getTimeout()) { + $options['timeout'] = $connection->getTimeout(); + } - if ($connection->getProxy()) { - $options['proxy'] = $connection->getProxy(); - } + $proxy = $connection->getProxy(); - $req = $client->createRequest($request->getMethod(), $this->_getActionPath($request), $options); - $req->setHeaders($connection->hasConfig('headers') ?: array()); + // See: https://github.com/facebook/hhvm/issues/4875 + if (is_null($proxy) && defined('HHVM_VERSION')) { + $proxy = getenv('http_proxy') ?: null; + } + + if (!is_null($proxy)) { + $options['proxy'] = $proxy; + } - $data = $request->getData(); - if (!empty($data) || '0' === $data) { + $req = $client->createRequest($request->getMethod(), $this->_getActionPath($request), $options); + $req->setHeaders($connection->hasConfig('headers') ? $connection->getConfig('headers') : array()); - if ($req->getMethod() == Request::GET) { - $req->setMethod(Request::POST); - } + $data = $request->getData(); + if (!empty($data) || '0' === $data) { + if ($req->getMethod() == Request::GET) { + $req->setMethod(Request::POST); + } - if ($this->hasParam('postWithRequestBody') && $this->getParam('postWithRequestBody') == true) { - $request->setMethod(Request::POST); - $req->setMethod(Request::POST); - } + if ($this->hasParam('postWithRequestBody') && $this->getParam('postWithRequestBody') == true) { + $request->setMethod(Request::POST); + $req->setMethod(Request::POST); + } - if (is_array($data)) { - $content = JSON::stringify($data, 'JSON_ELASTICSEARCH'); - } else { - $content = $data; - } - $req->setBody(Stream::factory($content)); + if (is_array($data)) { + $content = JSON::stringify($data, 'JSON_ELASTICSEARCH'); + } else { + $content = $data; } + $req->setBody(Stream::factory($content)); + } + try { $start = microtime(true); $res = $client->send($req); $end = microtime(true); + } catch (TransferException $ex) { + throw new GuzzleException($ex, $request, new Response($ex->getMessage())); + } - $response = new Response((string)$res->getBody(), $res->getStatusCode()); - - if (defined('DEBUG') && DEBUG) { - $response->setQueryTime($end - $start); - } - - $response->setTransferInfo( - array( - 'request_header' => $request->getMethod(), - 'http_code' => $res->getStatusCode() - ) - ); - - if ($response->hasError()) { - throw new ResponseException($request, $response); - } + $response = new Response((string) $res->getBody(), $res->getStatusCode()); + $response->setQueryTime($end - $start); - if ($response->hasFailedShards()) { - throw new PartialShardFailureException($request, $response); - } + $response->setTransferInfo( + array( + 'request_header' => $request->getMethod(), + 'http_code' => $res->getStatusCode(), + ) + ); - return $response; + if ($response->hasError()) { + throw new ResponseException($request, $response); + } - } catch (ClientException $e) { - // ignore 4xx errors - } catch (TransferException $e) { - throw new GuzzleException($e, $request, new Response($e->getMessage())); + if ($response->hasFailedShards()) { + throw new PartialShardFailureException($request, $response); } + return $response; } /** - * Return Guzzle resource + * Return Guzzle resource. + * + * @param bool $persistent False if not persistent connection * - * @param bool $persistent False if not persistent connection * @return resource Connection resource */ protected function _getGuzzleClient($baseUrl, $persistent = true) @@ -140,9 +139,9 @@ class Guzzle extends AbstractTransport } /** - * Builds the base url for the guzzle connection + * Builds the base url for the guzzle connection. * - * @param \Elastica\Connection $connection + * @param \Elastica\Connection $connection */ protected function _getBaseUrl(Connection $connection) { @@ -152,26 +151,27 @@ class Guzzle extends AbstractTransport if (!empty($url)) { $baseUri = $url; } else { - $baseUri = $this->_scheme . '://' . $connection->getHost() . ':' . $connection->getPort() . '/' . $connection->getPath(); + $baseUri = $this->_scheme.'://'.$connection->getHost().':'.$connection->getPort().'/'.$connection->getPath(); } + return rtrim($baseUri, '/'); } /** - * Builds the action path url for each request + * Builds the action path url for each request. * - * @param \Elastica\Request $request + * @param \Elastica\Request $request */ protected function _getActionPath(Request $request) { $action = $request->getPath(); if ($action) { - $action = '/'. ltrim($action, '/'); + $action = '/'.ltrim($action, '/'); } $query = $request->getQuery(); if (!empty($query)) { - $action .= '?' . http_build_query($query); + $action .= '?'.http_build_query($query); } return $action; diff --git a/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php b/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php index 5606dbbc..1a33c0a6 100644 --- a/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php +++ b/vendor/ruflin/elastica/lib/Elastica/Transport/Http.php @@ -1,5 +1,4 @@ <?php - namespace Elastica\Transport; use Elastica\Exception\Connection\HttpException; @@ -10,39 +9,39 @@ use Elastica\Request; use Elastica\Response; /** - * Elastica Http Transport object + * Elastica Http Transport object. * - * @category Xodoa - * @package Elastica * @author Nicolas Ruflin <spam@ruflin.com> */ class Http extends AbstractTransport { /** - * Http scheme + * Http scheme. * * @var string Http scheme */ protected $_scheme = 'http'; /** - * Curl resource to reuse + * Curl resource to reuse. * * @var resource Curl resource to reuse */ protected static $_curlConnection = null; /** - * Makes calls to the elasticsearch server + * Makes calls to the elasticsearch server. * * All calls that are made to the server are done through this function * - * @param \Elastica\Request $request - * @param array $params Host, Port, ... + * @param \Elastica\Request $request + * @param array $params Host, Port, ... + * * @throws \Elastica\Exception\ConnectionException * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\Connection\HttpException - * @return \Elastica\Response Response object + * + * @return \Elastica\Response Response object */ public function exec(Request $request, array $params) { @@ -56,7 +55,7 @@ class Http extends AbstractTransport if (!empty($url)) { $baseUri = $url; } else { - $baseUri = $this->_scheme . '://' . $connection->getHost() . ':' . $connection->getPort() . '/' . $connection->getPath(); + $baseUri = $this->_scheme.'://'.$connection->getHost().':'.$connection->getPort().'/'.$connection->getPath(); } $baseUri .= $request->getPath(); @@ -64,14 +63,26 @@ class Http extends AbstractTransport $query = $request->getQuery(); if (!empty($query)) { - $baseUri .= '?' . http_build_query($query); + $baseUri .= '?'.http_build_query($query); } curl_setopt($conn, CURLOPT_URL, $baseUri); curl_setopt($conn, CURLOPT_TIMEOUT, $connection->getTimeout()); curl_setopt($conn, CURLOPT_FORBID_REUSE, 0); + /* @see Connection::setConnectTimeout() */ + $connectTimeout = $connection->getConnectTimeout(); + if ($connectTimeout > 0) { + curl_setopt($conn, CURLOPT_CONNECTTIMEOUT, $connectTimeout); + } + $proxy = $connection->getProxy(); + + // See: https://github.com/facebook/hhvm/issues/4875 + if (is_null($proxy) && defined('HHVM_VERSION')) { + $proxy = getenv('http_proxy') ?: null; + } + if (!is_null($proxy)) { curl_setopt($conn, CURLOPT_PROXY, $proxy); } @@ -83,7 +94,7 @@ class Http extends AbstractTransport if (!empty($headersConfig)) { $headers = array(); while (list($header, $headerValue) = each($headersConfig)) { - array_push($headers, $header . ': ' . $headerValue); + array_push($headers, $header.': '.$headerValue); } curl_setopt($conn, CURLOPT_HTTPHEADER, $headers); @@ -116,11 +127,6 @@ class Http extends AbstractTransport curl_setopt($conn, CURLOPT_CUSTOMREQUEST, $httpMethod); - if (defined('DEBUG') && DEBUG) { - // Track request headers when in debug mode - curl_setopt($conn, CURLINFO_HEADER_OUT, true); - } - $start = microtime(true); // cURL opt returntransfer leaks memory, therefore OB instead. @@ -133,15 +139,10 @@ class Http extends AbstractTransport // Checks if error exists $errorNumber = curl_errno($conn); - $response = new Response($responseString, curl_getinfo($this->_getConnection(), CURLINFO_HTTP_CODE)); - - if (defined('DEBUG') && DEBUG) { - $response->setQueryTime($end - $start); - } - + $response = new Response($responseString, curl_getinfo($conn, CURLINFO_HTTP_CODE)); + $response->setQueryTime($end - $start); $response->setTransferInfo(curl_getinfo($conn)); - if ($response->hasError()) { throw new ResponseException($request, $response); } @@ -158,7 +159,7 @@ class Http extends AbstractTransport } /** - * Called to add additional curl params + * Called to add additional curl params. * * @param resource $curlConnection Curl connection */ @@ -172,9 +173,10 @@ class Http extends AbstractTransport } /** - * Return Curl resource + * Return Curl resource. + * + * @param bool $persistent False if not persistent connection * - * @param bool $persistent False if not persistent connection * @return resource Connection resource */ protected function _getConnection($persistent = true) diff --git a/vendor/ruflin/elastica/lib/Elastica/Transport/HttpAdapter.php b/vendor/ruflin/elastica/lib/Elastica/Transport/HttpAdapter.php new file mode 100644 index 00000000..efc27ab5 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Transport/HttpAdapter.php @@ -0,0 +1,156 @@ +<?php +namespace Elastica\Transport; + +use Elastica\Connection; +use Elastica\Exception\PartialShardFailureException; +use Elastica\Exception\ResponseException; +use Elastica\JSON; +use Elastica\Request as ElasticaRequest; +use Elastica\Response as ElasticaResponse; +use Ivory\HttpAdapter\HttpAdapterInterface; +use Ivory\HttpAdapter\Message\Request as HttpAdapterRequest; +use Ivory\HttpAdapter\Message\Response as HttpAdapterResponse; +use Ivory\HttpAdapter\Message\Stream\StringStream; + +class HttpAdapter extends AbstractTransport +{ + /** + * @var HttpAdapterInterface + */ + private $httpAdapter; + + /** + * @var string + */ + private $_scheme = 'http'; + + /** + * Construct transport. + */ + public function __construct(Connection $connection = null, HttpAdapterInterface $httpAdapter) + { + parent::__construct($connection); + $this->httpAdapter = $httpAdapter; + } + + /** + * Makes calls to the elasticsearch server. + * + * All calls that are made to the server are done through this function + * + * @param \Elastica\Request $elasticaRequest + * @param array $params Host, Port, ... + * + * @throws \Elastica\Exception\ConnectionException + * @throws \Elastica\Exception\ResponseException + * @throws \Elastica\Exception\Connection\HttpException + * + * @return \Elastica\Response Response object + */ + public function exec(ElasticaRequest $elasticaRequest, array $params) + { + $connection = $this->getConnection(); + + if ($timeout = $connection->getTimeout()) { + $this->httpAdapter->getConfiguration()->setTimeout($timeout); + } + + $httpAdapterRequest = $this->_createHttpAdapterRequest($elasticaRequest, $connection); + + $start = microtime(true); + $httpAdapterResponse = $this->httpAdapter->sendRequest($httpAdapterRequest); + $end = microtime(true); + + $elasticaResponse = $this->_createElasticaResponse($httpAdapterResponse, $connection); + $elasticaResponse->setQueryTime($end - $start); + + $elasticaResponse->setTransferInfo( + array( + 'request_header' => $httpAdapterRequest->getMethod(), + 'http_code' => $httpAdapterResponse->getStatusCode(), + ) + ); + + if ($elasticaResponse->hasError()) { + throw new ResponseException($elasticaRequest, $elasticaResponse); + } + + if ($elasticaResponse->hasFailedShards()) { + throw new PartialShardFailureException($elasticaRequest, $elasticaResponse); + } + + return $elasticaResponse; + } + + /** + * @param HttpAdapterResponse $httpAdapterResponse + * + * @return ElasticaResponse + */ + protected function _createElasticaResponse(HttpAdapterResponse $httpAdapterResponse) + { + return new ElasticaResponse((string) $httpAdapterResponse->getBody(), $httpAdapterResponse->getStatusCode()); + } + + /** + * @param ElasticaRequest $elasticaRequest + * @param Connection $connection + * + * @return HttpAdapterRequest + */ + protected function _createHttpAdapterRequest(ElasticaRequest $elasticaRequest, Connection $connection) + { + $data = $elasticaRequest->getData(); + $body = null; + $method = $elasticaRequest->getMethod(); + $headers = $connection->hasConfig('headers') ?: array(); + if (!empty($data) || '0' === $data) { + if ($method == ElasticaRequest::GET) { + $method = ElasticaRequest::POST; + } + + if ($this->hasParam('postWithRequestBody') && $this->getParam('postWithRequestBody') == true) { + $elasticaRequest->setMethod(ElasticaRequest::POST); + $method = ElasticaRequest::POST; + } + + if (is_array($data)) { + $body = JSON::stringify($data, 'JSON_ELASTICSEARCH'); + } else { + $body = $data; + } + } + + $url = $this->_getUri($elasticaRequest, $connection); + $streamBody = new StringStream($body); + + return new HttpAdapterRequest($url, $method, HttpAdapterRequest::PROTOCOL_VERSION_1_1, $headers, $streamBody); + } + + /** + * @param ElasticaRequest $request + * @param \Elastica\Connection $connection + * + * @return string + */ + protected function _getUri(ElasticaRequest $request, Connection $connection) + { + $url = $connection->hasConfig('url') ? $connection->getConfig('url') : ''; + + if (!empty($url)) { + $baseUri = $url; + } else { + $baseUri = $this->_scheme.'://'.$connection->getHost().':'.$connection->getPort().'/'.$connection->getPath(); + } + + $baseUri .= $request->getPath(); + + $query = $request->getQuery(); + + if (!empty($query)) { + $baseUri .= '?'.http_build_query($query); + } + + return $baseUri; + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Transport/Https.php b/vendor/ruflin/elastica/lib/Elastica/Transport/Https.php index 64704039..b2b489dd 100644 --- a/vendor/ruflin/elastica/lib/Elastica/Transport/Https.php +++ b/vendor/ruflin/elastica/lib/Elastica/Transport/Https.php @@ -1,25 +1,22 @@ <?php - namespace Elastica\Transport; /** - * Elastica Http Transport object + * Elastica Http Transport object. * - * @category Xodoa - * @package Elastica * @author Nicolas Ruflin <spam@ruflin.com> */ class Https extends Http { /** - * Https scheme + * Https scheme. * * @var string https scheme */ protected $_scheme = 'https'; /** - * Overloads setupCurl to set SSL params + * Overloads setupCurl to set SSL params. * * @param resource $connection Curl connection resource */ diff --git a/vendor/ruflin/elastica/lib/Elastica/Transport/Memcache.php b/vendor/ruflin/elastica/lib/Elastica/Transport/Memcache.php index cf047b58..fb56cdf4 100644 --- a/vendor/ruflin/elastica/lib/Elastica/Transport/Memcache.php +++ b/vendor/ruflin/elastica/lib/Elastica/Transport/Memcache.php @@ -1,7 +1,7 @@ <?php - namespace Elastica\Transport; +use Elastica\Exception\Connection\MemcacheException; use Elastica\Exception\InvalidException; use Elastica\Exception\PartialShardFailureException; use Elastica\Exception\ResponseException; @@ -10,31 +10,32 @@ use Elastica\Request; use Elastica\Response; /** - * Elastica Memcache Transport object + * Elastica Memcache Transport object. * - * @category Xodoa - * @package Elastica * @author Nicolas Ruflin <spam@ruflin.com> + * + * @deprecated The memcached transport is deprecated as of ES 1.5, and will be removed in ES 2.0 */ class Memcache extends AbstractTransport { + const MAX_KEY_LENGTH = 250; + /** - * Makes calls to the elasticsearch server + * Makes calls to the elasticsearch server. * * @param \Elastica\Request $request - * @param array $params Host, Port, ... + * @param array $params Host, Port, ... + * * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\InvalidException - * @return \Elastica\Response Response object + * + * @return \Elastica\Response Response object */ public function exec(Request $request, array $params) { $memcache = new \Memcache(); $memcache->connect($this->getConnection()->getHost(), $this->getConnection()->getPort()); - // Finds right function name - $function = strtolower($request->getMethod()); - $data = $request->getData(); $content = ''; @@ -52,22 +53,34 @@ class Memcache extends AbstractTransport $responseString = ''; - switch ($function) { - case 'post': - case 'put': - $memcache->set($request->getPath(), $content); + $start = microtime(true); + + switch ($request->getMethod()) { + case Request::POST: + case Request::PUT: + $key = $request->getPath(); + $this->_checkKeyLength($key); + $memcache->set($key, $content); break; - case 'get': - $responseString = $memcache->get($request->getPath() . '?source=' . $content); + case Request::GET: + $key = $request->getPath().'?source='.$content; + $this->_checkKeyLength($key); + $responseString = $memcache->get($key); break; - case 'delete': + case Request::DELETE: + $key = $request->getPath().'?source='.$content; + $this->_checkKeyLength($key); + $responseString = $memcache->delete($key); break; default: - throw new InvalidException('Method ' . $function . ' is not supported in memcache transport'); - + case Request::HEAD: + throw new InvalidException('Method '.$request->getMethod().' is not supported in memcache transport'); } + $end = microtime(true); + $response = new Response($responseString); + $response->setQueryTime($end - $start); if ($response->hasError()) { throw new ResponseException($request, $response); @@ -79,4 +92,18 @@ class Memcache extends AbstractTransport return $response; } + + /** + * Check if key that will be used dont exceed 250 symbols. + * + * @param string $key + * + * @throws Elastica\Exception\Connection\MemcacheException If key is too long + */ + private function _checkKeyLength($key) + { + if (strlen($key) >= self::MAX_KEY_LENGTH) { + throw new MemcacheException('Memcache key is too long'); + } + } } diff --git a/vendor/ruflin/elastica/lib/Elastica/Transport/Null.php b/vendor/ruflin/elastica/lib/Elastica/Transport/Null.php index 704e0e12..70dd9af1 100644 --- a/vendor/ruflin/elastica/lib/Elastica/Transport/Null.php +++ b/vendor/ruflin/elastica/lib/Elastica/Transport/Null.php @@ -1,44 +1,13 @@ <?php - namespace Elastica\Transport; -use Elastica\JSON; -use Elastica\Request; -use Elastica\Response; - /** - * Elastica Null Transport object + * Elastica Null Transport object. + * + * This class is for backward compatibility reason for all php < 7 versions. For PHP 7 and above use NullTransport as Null is reserved. * - * @package Elastica * @author James Boehmer <james.boehmer@jamesboehmer.com> */ -class Null extends AbstractTransport +class Null extends NullTransport { - /** - * Null transport. - * - * @param \Elastica\Request $request - * @param array $params Hostname, port, path, ... - * @return \Elastica\Response Response empty object - */ - public function exec(Request $request, array $params) - { - $response = array( - "took" => 0, - "timed_out" => FALSE, - "_shards" => array( - "total" => 0, - "successful" => 0, - "failed" => 0 - ), - "hits" => array( - "total" => 0, - "max_score" => NULL, - "hits" => array() - ), - "params" => $params - ); - - return new Response(JSON::stringify($response)); - } } diff --git a/vendor/ruflin/elastica/lib/Elastica/Transport/NullTransport.php b/vendor/ruflin/elastica/lib/Elastica/Transport/NullTransport.php new file mode 100644 index 00000000..d24f2110 --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Transport/NullTransport.php @@ -0,0 +1,46 @@ +<?php +namespace Elastica\Transport; + +use Elastica\JSON; +use Elastica\Request; +use Elastica\Response; + +/** + * Elastica Null Transport object. + * + * This is used in case you just need a test transport that doesn't do any connection to an elasticsearch + * host but still returns a valid response object + * + * @author James Boehmer <james.boehmer@jamesboehmer.com> + */ +class NullTransport extends AbstractTransport +{ + /** + * Null transport. + * + * @param \Elastica\Request $request + * @param array $params Hostname, port, path, ... + * + * @return \Elastica\Response Response empty object + */ + public function exec(Request $request, array $params) + { + $response = array( + 'took' => 0, + 'timed_out' => false, + '_shards' => array( + 'total' => 0, + 'successful' => 0, + 'failed' => 0, + ), + 'hits' => array( + 'total' => 0, + 'max_score' => null, + 'hits' => array(), + ), + 'params' => $params, + ); + + return new Response(JSON::stringify($response)); + } +} diff --git a/vendor/ruflin/elastica/lib/Elastica/Transport/Thrift.php b/vendor/ruflin/elastica/lib/Elastica/Transport/Thrift.php index f58c51a2..5790f665 100644 --- a/vendor/ruflin/elastica/lib/Elastica/Transport/Thrift.php +++ b/vendor/ruflin/elastica/lib/Elastica/Transport/Thrift.php @@ -1,7 +1,7 @@ <?php - namespace Elastica\Transport; +use Elastica\Connection; use Elastica\Exception\Connection\ThriftException; use Elastica\Exception\PartialShardFailureException; use Elastica\Exception\ResponseException; @@ -9,23 +9,22 @@ use Elastica\Exception\RuntimeException; use Elastica\JSON; use Elastica\Request; use Elastica\Response; -use Elastica\Connection; use Elasticsearch\Method; -use Elasticsearch\RestResponse; use Elasticsearch\RestClient; use Elasticsearch\RestRequest; -use Thrift\Transport\TSocket; -use Thrift\Transport\TFramedTransport; -use Thrift\Transport\TBufferedTransport; -use Thrift\Protocol\TBinaryProtocolAccelerated; +use Elasticsearch\RestResponse; use Thrift\Exception\TException; +use Thrift\Protocol\TBinaryProtocolAccelerated; +use Thrift\Transport\TBufferedTransport; +use Thrift\Transport\TFramedTransport; +use Thrift\Transport\TSocket; /** - * Elastica Thrift Transport object + * Elastica Thrift Transport object. * - * @category Xodoa - * @package Elastica * @author Mikhail Shamin <munk13@gmail.com> + * + * @deprecated The thrift transport is deprecated as of ES 1.5, and will be removed in ES 2.0 */ class Thrift extends AbstractTransport { @@ -35,9 +34,10 @@ class Thrift extends AbstractTransport protected $_clients = array(); /** - * Construct transport + * Construct transport. * * @param \Elastica\Connection $connection Connection object + * * @throws \Elastica\Exception\RuntimeException */ public function __construct(Connection $connection = null) @@ -50,10 +50,11 @@ class Thrift extends AbstractTransport /** * @param string $host - * @param int $port - * @param int $sendTimeout msec - * @param int $recvTimeout msec - * @param bool $framedTransport + * @param int $port + * @param int $sendTimeout msec + * @param int $recvTimeout msec + * @param bool $framedTransport + * * @return \Elasticsearch\RestClient */ protected function _createClient($host, $port, $sendTimeout = null, $recvTimeout = null, $framedTransport = false) @@ -84,28 +85,32 @@ class Thrift extends AbstractTransport /** * @param string $host - * @param int $port - * @param int $sendTimeout - * @param int $recvTimeout - * @param bool $framedTransport + * @param int $port + * @param int $sendTimeout + * @param int $recvTimeout + * @param bool $framedTransport + * * @return \Elasticsearch\RestClient */ protected function _getClient($host, $port, $sendTimeout = null, $recvTimeout = null, $framedTransport = false) { - $key = $host . ':' . $port; + $key = $host.':'.$port; if (!isset($this->_clients[$key])) { $this->_clients[$key] = $this->_createClient($host, $port, $sendTimeout, $recvTimeout, $framedTransport); } + return $this->_clients[$key]; } /** - * Makes calls to the elasticsearch server + * Makes calls to the elasticsearch server. * * @param \Elastica\Request $request - * @param array $params Host, Port, ... + * @param array $params Host, Port, ... + * * @throws \Elastica\Exception\Connection\ThriftException * @throws \Elastica\Exception\ResponseException + * * @return \Elastica\Response Response object */ public function exec(Request $request, array $params) @@ -156,9 +161,7 @@ class Thrift extends AbstractTransport throw new ThriftException($e, $request, $response); } - if (defined('DEBUG') && DEBUG) { - $response->setQueryTime($end - $start); - } + $response->setQueryTime($end - $start); if ($response->hasError()) { throw new ResponseException($request, $response); |