Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 509d0cf

Browse files
author
Reza Shadman
committed
Add initial implementation for an index guzzle repository == THIS IS FOR LIGHENING THE ROAD :D ==.
1 parent d52a48e commit 509d0cf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php namespace Quince\Pelastic\Api\Document;
2+
3+
use Quince\Pelastic\Api\GuzzleRepository;
4+
use Quince\Pelastic\Contracts\Api\Document\Index\IndexRepositoryInterface;
5+
use Quince\Pelastic\Contracts\Api\Document\Index\IndexRequestInterface;
6+
7+
class IndexGuzzleRepository extends GuzzleRepository implements IndexRepositoryInterface {
8+
9+
/**
10+
* Execute an index request
11+
*
12+
* @param IndexRequestInterface $request
13+
* @return mixed
14+
*/
15+
public function executeRequest(IndexRequestInterface $request)
16+
{
17+
$client = $this->getGuzzleClient();
18+
19+
$uri = $request->getIndex();
20+
21+
if (null !== ($type = $request->getType())) {
22+
$uri .= '/' . $type;
23+
}
24+
25+
if (null !== ($id = $request->getDocumentId())) {
26+
$uri .= '/' . $id;
27+
}
28+
29+
$guzzleReq = $client->createRequest('POST', $uri, [
30+
'body' => $request->getDocument()->toJson()
31+
]);
32+
33+
$response = $client->send($guzzleReq)->json();
34+
35+
return $response;
36+
}
37+
}

0 commit comments

Comments
 (0)