Skip to content

Commit 54cdaa9

Browse files
committed
Support for operations endpoint
1 parent e4abbc6 commit 54cdaa9

5 files changed

Lines changed: 91 additions & 4 deletions

File tree

examples/cluster_operations.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/** @noinspection ForgottenDebugOutputInspection */
4+
5+
include '../vendor/autoload.php';
6+
7+
use Symfony\Component\HttpClient\HttplugClient;
8+
use Typesense\Client;
9+
10+
try {
11+
$client = new Client(
12+
[
13+
'api_key' => 'xyz',
14+
'nodes' => [
15+
[
16+
'host' => 'localhost',
17+
'port' => '8108',
18+
'protocol' => 'http',
19+
],
20+
],
21+
'client' => new HttplugClient(),
22+
]
23+
);
24+
echo '<pre>';
25+
26+
print_r($client->operations->perform('snapshot', ['snapshot_path' => '/tmp/snapshot']));
27+
} catch (Exception $e) {
28+
echo $e->getMessage();
29+
}

src/Client.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class Client
5050
*/
5151
public Health $health;
5252

53+
/**
54+
* @var Operations
55+
*/
56+
public Operations $operations;
57+
5358
/**
5459
* @var ApiCall
5560
*/
@@ -73,6 +78,7 @@ public function __construct(array $config)
7378
$this->debug = new Debug($this->apiCall);
7479
$this->metrics = new Metrics($this->apiCall);
7580
$this->health = new Health($this->apiCall);
81+
$this->operations = new Operations($this->apiCall);
7682
}
7783

7884
/**
@@ -122,4 +128,12 @@ public function getHealth(): Health
122128
{
123129
return $this->health;
124130
}
131+
132+
/**
133+
* @return Operations
134+
*/
135+
public function getOperations(): Operations
136+
{
137+
return $this->operations;
138+
}
125139
}

src/Operations.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Typesense;
4+
5+
use Http\Client\Exception as HttpClientException;
6+
use Typesense\Exceptions\TypesenseClientError;
7+
8+
/**
9+
* Class Operations
10+
*
11+
* @package \Typesense
12+
*/
13+
class Operations
14+
{
15+
public const RESOURCE_PATH = '/operations';
16+
17+
/**
18+
* @var ApiCall
19+
*/
20+
private ApiCall $apiCall;
21+
22+
/**
23+
* Alias constructor.
24+
*
25+
* @param ApiCall $apiCall
26+
*/
27+
public function __construct(ApiCall $apiCall)
28+
{
29+
$this->apiCall = $apiCall;
30+
}
31+
32+
/**
33+
* @param string $operationName
34+
* @param array $queryParameters
35+
*
36+
* @return array
37+
* @throws TypesenseClientError|HttpClientException
38+
*/
39+
public function perform(string $operationName, array $queryParameters = []): array
40+
{
41+
return $this->apiCall->post(
42+
sprintf('%s/%s', static::RESOURCE_PATH, $operationName),
43+
null,
44+
true,
45+
$queryParameters
46+
);
47+
}
48+
}

src/Synonym.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* Class synonym
1010
*
1111
* @package \Typesense
12-
* @date 4/5/20
13-
* @author Typesense <contact@typesense.org>
1412
*/
1513
class Synonym
1614
{

src/Synonyms.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
* Class Synonyms
1010
*
1111
* @package \Typesense
12-
* @date 4/5/20
13-
* @author Typesense <contact@typesense.org>
1412
*/
1513
class Synonyms implements \ArrayAccess
1614
{

0 commit comments

Comments
 (0)