summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Response.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Response.php')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Response.php77
1 files changed, 43 insertions, 34 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Response.php b/vendor/ruflin/elastica/lib/Elastica/Response.php
index 5c0ef24d..b537fe80 100644
--- a/vendor/ruflin/elastica/lib/Elastica/Response.php
+++ b/vendor/ruflin/elastica/lib/Elastica/Response.php
@@ -1,69 +1,65 @@
<?php
-
namespace Elastica;
use Elastica\Exception\JSONParseException;
use Elastica\Exception\NotFoundException;
-use Elastica\JSON;
/**
- * Elastica Response object
+ * Elastica Response object.
*
* Stores query time, and result array -> is given to result set, returned by ...
*
- * @category Xodoa
- * @package Elastica
* @author Nicolas Ruflin <spam@ruflin.com>
*/
class Response
{
/**
- * Query time
+ * Query time.
*
* @var float Query time
*/
protected $_queryTime = null;
/**
- * Response string (json)
+ * Response string (json).
*
* @var string Response
*/
protected $_responseString = '';
/**
- * Error
+ * Error.
*
- * @var boolean Error
+ * @var bool Error
*/
protected $_error = false;
/**
- * Transfer info
+ * Transfer info.
*
* @var array transfer info
*/
protected $_transferInfo = array();
/**
- * Response
+ * Response.
*
* @var \Elastica\Response Response object
*/
protected $_response = null;
/**
- * HTTP response status code
+ * HTTP response status code.
*
* @var int
*/
protected $_status = null;
/**
- * Construct
+ * Construct.
*
* @param string|array $responseString Response string (json)
- * @param int $responseStatus http status code
+ * @param int $responseStatus http status code
*/
public function __construct($responseString, $responseStatus = null)
{
@@ -76,7 +72,7 @@ class Response
}
/**
- * Error message
+ * Error message.
*
* @return string Error message
*/
@@ -93,7 +89,7 @@ class Response
}
/**
- * True if response has error
+ * True if response has error.
*
* @return bool True if response has error
*/
@@ -109,7 +105,7 @@ class Response
}
/**
- * True if response has failed shards
+ * True if response has failed shards.
*
* @return bool True if response has failed shards
*/
@@ -125,7 +121,7 @@ class Response
}
/**
- * Checks if the query returned ok
+ * Checks if the query returned ok.
*
* @return bool True if ok
*/
@@ -138,11 +134,19 @@ class Response
if ($data['status'] >= 200 && $data['status'] <= 300) {
return true;
}
+
return false;
}
+
if (isset($data['items'])) {
+ if (isset($data['errors']) && true === $data['errors']) {
+ return false;
+ }
+
foreach ($data['items'] as $item) {
- if (false == $item['index']['ok']) {
+ if (isset($item['index']['ok']) && false == $item['index']['ok']) {
+ return false;
+ } elseif (isset($item['index']['status']) && ($item['index']['status'] < 200 || $item['index']['status'] >= 300)) {
return false;
}
}
@@ -166,9 +170,8 @@ class Response
return $this->_status;
}
-
/**
- * Response data array
+ * Response data array.
*
* @return array Response data array
*/
@@ -214,17 +217,19 @@ class Response
* Sets the transfer info of the curl request. This function is called
* from the \Elastica\Client::_callService .
*
- * @param array $transferInfo The curl transfer information.
- * @return \Elastica\Response Current object
+ * @param array $transferInfo The curl transfer information.
+ *
+ * @return $this
*/
public function setTransferInfo(array $transferInfo)
{
$this->_transferInfo = $transferInfo;
+
return $this;
}
/**
- * This is only available if DEBUG constant is set to true
+ * Returns query execution time.
*
* @return float Query time
*/
@@ -234,10 +239,11 @@ class Response
}
/**
- * Sets the query time
+ * Sets the query time.
+ *
+ * @param float $queryTime Query time
*
- * @param float $queryTime Query time
- * @return \Elastica\Response Current object
+ * @return $this
*/
public function setQueryTime($queryTime)
{
@@ -247,26 +253,28 @@ class Response
}
/**
- * Time request took
+ * Time request took.
*
* @throws \Elastica\Exception\NotFoundException
- * @return int Time request took
+ *
+ * @return int Time request took
*/
public function getEngineTime()
{
$data = $this->getData();
if (!isset($data['took'])) {
- throw new NotFoundException("Unable to find the field [took]from the response");
+ throw new NotFoundException('Unable to find the field [took]from the response');
}
return $data['took'];
}
/**
- * Get the _shard statistics for the response
+ * Get the _shard statistics for the response.
*
* @throws \Elastica\Exception\NotFoundException
+ *
* @return array
*/
public function getShardsStatistics()
@@ -274,16 +282,17 @@ class Response
$data = $this->getData();
if (!isset($data['_shards'])) {
- throw new NotFoundException("Unable to find the field [_shards] from the response");
+ throw new NotFoundException('Unable to find the field [_shards] from the response');
}
return $data['_shards'];
}
/**
- * Get the _scroll value for the response
+ * Get the _scroll value for the response.
*
* @throws \Elastica\Exception\NotFoundException
+ *
* @return string
*/
public function getScrollId()
@@ -291,7 +300,7 @@ class Response
$data = $this->getData();
if (!isset($data['_scroll_id'])) {
- throw new NotFoundException("Unable to find the field [_scroll_id] from the response");
+ throw new NotFoundException('Unable to find the field [_scroll_id] from the response');
}
return $data['_scroll_id'];