Skip to content

Commit ff810bb

Browse files
- Updated Namespace to be Typesense only.
- Code reformatting. - Fix typo in config. - Rewrote generate_scoped_search_key in camelCase.
1 parent e1a6d2c commit ff810bb

30 files changed

Lines changed: 195 additions & 203 deletions

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ You can find some examples [here](https://github.com/devloopsnet/typesense-php/b
1818

1919
See detailed [API documentation](https://typesense.org/api).
2020

21+
## Compatibility
22+
23+
| Typesense Server | typesense-ruby |
24+
|------------------|----------------|
25+
| \>= v0.15.0 | \>= v2.0.4 |
26+
| \>= v0.12.0 | \>= v2.0.0 |
27+
| <= v0.11 | <= v1.0.0 |
28+
2129
## Contributing
2230

2331
Bug reports and pull requests are welcome on GitHub at [https://github.com/devloopsnet/typesense-php].

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"minimum-stability": "stable",
1616
"autoload": {
1717
"psr-4": {
18-
"Devloops\\Typesence\\": "src/"
18+
"Typesence\\": "src/"
1919
}
2020
},
2121
"require": {

examples/alias_operations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
include '../vendor/autoload.php';
44

5-
use Devloops\Typesence\Client;
5+
use \Typesence\Client;
66

77
try {
88
$client = new Client(

examples/collection_operations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
include '../vendor/autoload.php';
44

5-
use Devloops\Typesence\Client;
5+
use \Typesence\Client;
66

77
try {
88
$client = new Client(

examples/curation_operations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
include '../vendor/autoload.php';
44

5-
use Devloops\Typesence\Client;
5+
use \Typesence\Client;
66

77
try {
88
$client = new Client(

src/Alias.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
<?php
22

3+
namespace Typesence;
34

4-
namespace Devloops\Typesence;
5-
6-
use Devloops\Typesence\Lib\Configuration;
5+
use \Typesence\Lib\Configuration;
76

87
/**
98
* Class Alias
109
*
11-
* @package Devloops\Typesence
10+
* @package \Typesence
1211
* @date 4/5/20
1312
* @author Abdullah Al-Faqeir <abdullah@devloops.net>
1413
*/
1514
class Alias
1615
{
1716

1817
/**
19-
* @var \Devloops\Typesence\Lib\Configuration
18+
* @var \Typesence\Lib\Configuration
2019
*/
2120
private $config;
2221

@@ -26,14 +25,14 @@ class Alias
2625
private $name;
2726

2827
/**
29-
* @var \Devloops\Typesence\ApiCall
28+
* @var \Typesence\ApiCall
3029
*/
3130
private $apiCall;
3231

3332
/**
3433
* Alias constructor.
3534
*
36-
* @param \Devloops\Typesence\Lib\Configuration $config
35+
* @param \Typesence\Lib\Configuration $config
3736
* @param string $name
3837
*/
3938
public function __construct(Configuration $config, string $name)
@@ -53,7 +52,7 @@ public function endPointPath(): string
5352

5453
/**
5554
* @return array
56-
* @throws \Devloops\Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
55+
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
5756
*/
5857
public function retrieve(): array
5958
{
@@ -62,7 +61,7 @@ public function retrieve(): array
6261

6362
/**
6463
* @return array
65-
* @throws \Devloops\Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
64+
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
6665
*/
6766
public function delete(): array
6867
{

src/Aliases.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22

3+
namespace Typesence;
34

4-
namespace Devloops\Typesence;
5-
6-
use Devloops\Typesence\Lib\Configuration;
5+
use \Typesence\Lib\Configuration;
76

87
/**
98
* Class Aliases
109
*
11-
* @package Devloops\Typesence
10+
* @package \Typesence
1211
* @date 4/5/20
1312
* @author Abdullah Al-Faqeir <abdullah@devloops.net>
1413
*/
@@ -18,12 +17,12 @@ class Aliases implements \ArrayAccess
1817
public const RESOURCE_PATH = '/aliases';
1918

2019
/**
21-
* @var \Devloops\Typesence\Lib\Configuration
20+
* @var \Typesence\Lib\Configuration
2221
*/
2322
private $config;
2423

2524
/**
26-
* @var \Devloops\Typesence\ApiCall
25+
* @var \Typesence\ApiCall
2726
*/
2827
private $apiCall;
2928

@@ -35,7 +34,7 @@ class Aliases implements \ArrayAccess
3534
/**
3635
* Aliases constructor.
3736
*
38-
* @param \Devloops\Typesence\Lib\Configuration $config
37+
* @param \Typesence\Lib\Configuration $config
3938
*/
4039
public function __construct(Configuration $config)
4140
{
@@ -58,7 +57,7 @@ public function endPointPath(string $aliasName): string
5857
* @param array $mapping
5958
*
6059
* @return array
61-
* @throws \Devloops\Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
60+
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
6261
*/
6362
public function upsert(string $name, array $mapping): array
6463
{
@@ -67,7 +66,7 @@ public function upsert(string $name, array $mapping): array
6766

6867
/**
6968
* @return array
70-
* @throws \Devloops\Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
69+
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
7170
*/
7271
public function retrieve(): array
7372
{

src/ApiCall.php

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
<?php
22

3-
namespace Devloops\Typesence;
3+
namespace Typesence;
44

5-
use Devloops\Typesence\Lib\Node;
6-
use GuzzleHttp\Exception\GuzzleException;
7-
use Devloops\Typesence\Lib\Configuration;
5+
use \Typesence\Lib\Node;
6+
use \Typesence\Lib\Configuration;
87
use GuzzleHttp\Exception\ClientException;
98
use GuzzleHttp\Exception\RequestException;
10-
use Devloops\Typesence\Exceptions\ServerError;
11-
use Devloops\Typesence\Exceptions\ObjectNotFound;
12-
use Devloops\Typesence\Exceptions\RequestMalformed;
13-
use Devloops\Typesence\Exceptions\HTTPStatus0Error;
14-
use Devloops\Typesence\Exceptions\ServiceUnavailable;
15-
use Devloops\Typesence\Exceptions\RequestUnauthorized;
16-
use Devloops\Typesence\Exceptions\ObjectAlreadyExists;
17-
use Devloops\Typesence\Exceptions\ObjectUnprocessable;
18-
use Devloops\Typesence\Exceptions\TypesenseClientError;
9+
use \Typesence\Exceptions\ServerError;
10+
use \Typesence\Exceptions\ObjectNotFound;
11+
use \Typesence\Exceptions\RequestMalformed;
12+
use \Typesence\Exceptions\HTTPStatus0Error;
13+
use \Typesence\Exceptions\ServiceUnavailable;
14+
use \Typesence\Exceptions\RequestUnauthorized;
15+
use \Typesence\Exceptions\ObjectAlreadyExists;
16+
use \Typesence\Exceptions\ObjectUnprocessable;
17+
use \Typesence\Exceptions\TypesenseClientError;
1918

2019
/**
2120
* Class ApiCall
2221
*
23-
* @package Devloops\Typesence
22+
* @package \Typesence
2423
* @date 4/5/20
2524
* @author Abdullah Al-Faqeir <abdullah@devloops.net>
2625
*/
@@ -35,17 +34,17 @@ class ApiCall
3534
private $client;
3635

3736
/**
38-
* @var \Devloops\Typesence\Lib\Configuration
37+
* @var \Typesence\Lib\Configuration
3938
*/
4039
private $config;
4140

4241
/**
43-
* @var array|\Devloops\Typesence\Lib\Node[]
42+
* @var array|\Typesence\Lib\Node[]
4443
*/
4544
private static $nodes;
4645

4746
/**
48-
* @var \Devloops\Typesence\Lib\Node
47+
* @var \Typesence\Lib\Node
4948
*/
5049
private static $nearestNode;
5150

@@ -57,7 +56,7 @@ class ApiCall
5756
/**
5857
* ApiCall constructor.
5958
*
60-
* @param \Devloops\Typesence\Lib\Configuration $config
59+
* @param \Typesence\Lib\Configuration $config
6160
*/
6261
public function __construct(Configuration $config)
6362
{
@@ -75,11 +74,11 @@ public function __construct(Configuration $config)
7574
private function initializeNodes(): void
7675
{
7776
if (self::$nearestNode !== null) {
78-
$this->setNodeHealthcheck(self::$nearestNode, true);
77+
$this->setNodeHealthCheck(self::$nearestNode, true);
7978
}
8079

8180
foreach (self::$nodes as &$node) {
82-
$this->setNodeHealthcheck($node, true);
81+
$this->setNodeHealthCheck($node, true);
8382
}
8483
}
8584

@@ -89,7 +88,7 @@ private function initializeNodes(): void
8988
* @param bool $asJson
9089
*
9190
* @return string|array
92-
* @throws \Devloops\Typesence\Exceptions\TypesenseClientError
91+
* @throws \Typesence\Exceptions\TypesenseClientError
9392
* @throws \Exception|\GuzzleHttp\Exception\GuzzleException
9493
*/
9594
public function get(string $endPoint, array $params, bool $asJson = true)
@@ -106,7 +105,7 @@ public function get(string $endPoint, array $params, bool $asJson = true)
106105
* @param bool $asJson
107106
*
108107
* @return array|string
109-
* @throws \Devloops\Typesence\Exceptions\TypesenseClientError
108+
* @throws \Typesence\Exceptions\TypesenseClientError
110109
* @throws \GuzzleHttp\Exception\GuzzleException
111110
*/
112111
public function post(string $endPoint, $body, bool $asJson = true): array
@@ -121,7 +120,7 @@ public function post(string $endPoint, $body, bool $asJson = true): array
121120
* @param array $body
122121
*
123122
* @return array
124-
* @throws \Devloops\Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
123+
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
125124
*/
126125
public function put(string $endPoint, array $body): array
127126
{
@@ -134,7 +133,7 @@ public function put(string $endPoint, array $body): array
134133
* @param string $endPoint
135134
*
136135
* @return array
137-
* @throws \Devloops\Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
136+
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
138137
*/
139138
public function delete(string $endPoint): array
140139
{
@@ -150,7 +149,7 @@ public function delete(string $endPoint): array
150149
* @param array $options
151150
*
152151
* @return string|array
153-
* @throws \Devloops\Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
152+
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
154153
* @throws \Exception
155154
*/
156155
private function makeRequest(string $method, string $endPoint, bool $asJson, array $options)
@@ -178,7 +177,7 @@ private function makeRequest(string $method, string $endPoint, bool $asJson, arr
178177

179178
$statusCode = $response->getStatusCode();
180179
if (0 < $statusCode && $statusCode < 500) {
181-
$this->setNodeHealthcheck($node, true);
180+
$this->setNodeHealthCheck($node, true);
182181
}
183182

184183
if (!(200 <= $statusCode && $statusCode < 300)) {
@@ -196,20 +195,20 @@ private function makeRequest(string $method, string $endPoint, bool $asJson, arr
196195
->getStatusCode() === 408) {
197196
continue;
198197
}
199-
$this->setNodeHealthcheck($node, false);
198+
$this->setNodeHealthCheck($node, false);
200199
throw $this->getException($exception->getResponse()
201200
->getStatusCode())
202201
->setMessage($exception->getMessage());
203202
} catch (RequestException $exception) {
204-
$this->setNodeHealthcheck($node, false);
203+
$this->setNodeHealthCheck($node, false);
205204
throw $this->getException($exception->getResponse()
206205
->getStatusCode())
207206
->setMessage($exception->getMessage());
208207
} catch (TypesenseClientError $exception) {
209-
$this->setNodeHealthcheck($node, false);
208+
$this->setNodeHealthCheck($node, false);
210209
throw $exception;
211210
} catch (\Exception $exception) {
212-
$this->setNodeHealthcheck($node, false);
211+
$this->setNodeHealthCheck($node, false);
213212
$last_exception = $exception;
214213
sleep($this->config->getRetryIntervalSeconds());
215214
}
@@ -234,14 +233,14 @@ private function getRequestOptions(): array
234233
}
235234

236235
/**
237-
* @param \Devloops\Typesence\Lib\Node $node
236+
* @param \Typesence\Lib\Node $node
238237
*
239238
* @return bool
240239
*/
241240
private function nodeDueForHealthCheck(Node $node): bool
242241
{
243242
$currentTimestamp = time();
244-
$checkNode = ($currentTimestamp - $node->getLastAccessTs()) > $this->config->getHealthcheckIntervalSeconds();
243+
$checkNode = ($currentTimestamp - $node->getLastAccessTs()) > $this->config->getHealthCheckIntervalSeconds();
245244
if ($checkNode) {
246245
//
247246
}
@@ -250,10 +249,10 @@ private function nodeDueForHealthCheck(Node $node): bool
250249
}
251250

252251
/**
253-
* @param \Devloops\Typesence\Lib\Node $node
252+
* @param \Typesence\Lib\Node $node
254253
* @param bool $isHealthy
255254
*/
256-
public function setNodeHealthcheck(Node $node, bool $isHealthy): void
255+
public function setNodeHealthCheck(Node $node, bool $isHealthy): void
257256
{
258257
$node->setHealthy($isHealthy);
259258
$node->setLastAccessTs(time());
@@ -263,7 +262,7 @@ public function setNodeHealthcheck(Node $node, bool $isHealthy): void
263262
* Returns a healthy host from the pool in a round-robin fashion
264263
* Might return an unhealthy host periodically to check for recovery.
265264
*
266-
* @return \Devloops\Typesence\Lib\Node
265+
* @return \Typesence\Lib\Node
267266
*/
268267
public function getNode(): Lib\Node
269268
{
@@ -292,7 +291,7 @@ public function getNode(): Lib\Node
292291
/**
293292
* @param int $httpCode
294293
*
295-
* @return \Devloops\Typesence\Exceptions\TypesenseClientError
294+
* @return \Typesence\Exceptions\TypesenseClientError
296295
*/
297296
public function getException(int $httpCode): TypesenseClientError
298297
{

0 commit comments

Comments
 (0)