diff options
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Bulk.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Bulk.php | 115 |
1 files changed, 67 insertions, 48 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Bulk.php b/vendor/ruflin/elastica/lib/Elastica/Bulk.php index 439fa566..e7693dce 100644 --- a/vendor/ruflin/elastica/lib/Elastica/Bulk.php +++ b/vendor/ruflin/elastica/lib/Elastica/Bulk.php @@ -1,20 +1,13 @@ <?php - namespace Elastica; -use Elastica\Document; -use Elastica\Exception\Bulk\ResponseException as BulkResponseException; -use Elastica\Exception\Bulk\UdpException; -use Elastica\Exception\InvalidException; -use Elastica\Request; -use Elastica\Response; -use Elastica\Client; -use Elastica\Index; -use Elastica\Type; use Elastica\Bulk\Action; use Elastica\Bulk\Action\AbstractDocument as AbstractDocumentAction; -use Elastica\Bulk\ResponseSet; use Elastica\Bulk\Response as BulkResponse; +use Elastica\Bulk\ResponseSet; +use Elastica\Exception\Bulk\ResponseException as BulkResponseException; +use Elastica\Exception\Bulk\UdpException; +use Elastica\Exception\InvalidException; class Bulk { @@ -58,7 +51,8 @@ class Bulk /** * @param string|\Elastica\Index $index - * @return \Elastica\Bulk + * + * @return $this */ public function setIndex($index) { @@ -89,7 +83,8 @@ class Bulk /** * @param string|\Elastica\Type $type - * @return \Elastica\Bulk + * + * @return $this */ public function setType($type) { @@ -126,28 +121,32 @@ class Bulk { $path = ''; if ($this->hasIndex()) { - $path .= $this->getIndex() . '/'; + $path .= $this->getIndex().'/'; if ($this->hasType()) { - $path .= $this->getType() . '/'; + $path .= $this->getType().'/'; } } $path .= '_bulk'; + return $path; } /** * @param \Elastica\Bulk\Action $action - * @return \Elastica\Bulk + * + * @return $this */ public function addAction(Action $action) { $this->_actions[] = $action; + return $this; } /** * @param \Elastica\Bulk\Action[] $actions - * @return \Elastica\Bulk + * + * @return $this */ public function addActions(array $actions) { @@ -168,8 +167,9 @@ class Bulk /** * @param \Elastica\Document $document - * @param string $opType - * @return \Elastica\Bulk + * @param string $opType + * + * @return $this */ public function addDocument(Document $document, $opType = null) { @@ -180,8 +180,9 @@ class Bulk /** * @param \Elastica\Document[] $documents - * @param string $opType - * @return \Elastica\Bulk + * @param string $opType + * + * @return $this */ public function addDocuments(array $documents, $opType = null) { @@ -194,8 +195,9 @@ class Bulk /** * @param \Elastica\Script $data - * @param string $opType - * @return \Elastica\Bulk + * @param string $opType + * + * @return $this */ public function addScript(Script $script, $opType = null) { @@ -206,8 +208,9 @@ class Bulk /** * @param \Elastica\Document[] $scripts - * @param string $opType - * @return \Elastica\Bulk + * @param string $opType + * + * @return $this */ public function addScripts(array $scripts, $opType = null) { @@ -220,23 +223,23 @@ class Bulk /** * @param \Elastica\Script|\Elastica\Document\array $data - * @param string $opType - * @return \Elastica\Bulk + * @param string $opType + * + * @return $this */ public function addData($data, $opType = null) { - if(!is_array($data)){ + if (!is_array($data)) { $data = array($data); } - foreach ($data as $actionData){ - - if ($actionData instanceOf Script) { + foreach ($data as $actionData) { + if ($actionData instanceof Script) { $this->addScript($actionData, $opType); - }else if ($actionData instanceof Document) { + } elseif ($actionData instanceof Document) { $this->addDocument($actionData, $opType); - }else{ - throw new \InvalidArgumentException("Data should be a Document, a Script or an array containing Documents and/or Scripts"); + } else { + throw new \InvalidArgumentException('Data should be a Document, a Script or an array containing Documents and/or Scripts'); } } @@ -245,8 +248,10 @@ class Bulk /** * @param array $data - * @return \Elastica\Bulk + * * @throws \Elastica\Exception\InvalidException + * + * @return $this */ public function addRawData(array $data) { @@ -282,20 +287,30 @@ class Bulk /** * Set a url parameter on the request bulk request. - * @var string $name name of the parameter - * @var string $value value of the parameter + * + * @param string $name name of the parameter + * @param string $value value of the parameter + * + * @return $this */ - public function setRequestParam($name, $value) { - $this->_requestParams[ $name ] = $value; + public function setRequestParam($name, $value) + { + $this->_requestParams[$name] = $value; + + return $this; } /** * Set the amount of time that the request will wait the shards to come on line. * Requires Elasticsearch version >= 0.90.8. - * @var string $time timeout in Elasticsearch time format + * + * @param string $time timeout in Elasticsearch time format + * + * @return $this */ - public function setShardTimeout($time) { - $this->setRequestParam( 'timeout', $time ); + public function setShardTimeout($time) + { + return $this->setRequestParam('timeout', $time); } /** @@ -313,8 +328,9 @@ class Bulk { $data = ''; foreach ($this->getActions() as $action) { - $data.= $action->toString(); + $data .= $action->toString(); } + return $data; } @@ -329,6 +345,7 @@ class Bulk $data[] = $row; } } + return $data; } @@ -347,8 +364,10 @@ class Bulk /** * @param \Elastica\Response $response - * @throws Exception\Bulk\ResponseException - * @throws Exception\InvalidException + * + * @throws \Elastica\Exception\Bulk\ResponseException + * @throws \Elastica\Exception\InvalidException + * * @return \Elastica\Bulk\ResponseSet */ protected function _processResponse(Response $response) @@ -361,9 +380,8 @@ class Bulk if (isset($responseData['items']) && is_array($responseData['items'])) { foreach ($responseData['items'] as $key => $item) { - if (!isset($actions[$key])) { - throw new InvalidException('No response found for action #' . $key); + throw new InvalidException('No response found for action #'.$key); } $action = $actions[$key]; @@ -400,7 +418,8 @@ class Bulk /** * @param string $host - * @param int $port + * @param int $port + * * @throws \Elastica\Exception\Bulk\UdpException */ public function sendUdp($host = null, $port = null) |