Skip to content

Commit 88dada1

Browse files
authored
Merge pull request #6 from babeuloula/use-httplug
Use HTTPlug instead of Guzzle
2 parents 3453ef0 + e529b42 commit 88dada1

23 files changed

Lines changed: 165 additions & 123 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Read the documentation here: [https://typesense.org/api/](https://typesense.org/
1616

1717
Here are some examples that walk you through how to use the client: [doc/examples](examples)
1818

19+
Typesense use [HTTPlug](http://httplug.io/). List of clients & adapters [here](http://docs.php-http.org/en/latest/clients.html)
20+
1921
## Compatibility
2022

2123
| Typesense Server | typesense-php |

composer.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,31 @@
3131
},
3232
"require": {
3333
"php": ">=7.4",
34-
"guzzlehttp/guzzle": "^7.0",
3534
"ext-json": "*",
36-
"monolog/monolog": "^1.0"
35+
"monolog/monolog": "^1.0|^2.1",
36+
"nyholm/psr7": "^1.3",
37+
"php-http/client-common": "^1.0",
38+
"php-http/discovery": "^1.0",
39+
"php-http/httplug": "^1.0",
40+
"php-http/message-factory": "^1.0",
41+
"psr/http-client-implementation": "^1.0",
42+
"psr/http-message": "^1.0"
3743
},
3844
"require-dev": {
39-
"squizlabs/php_codesniffer": "3.*"
45+
"squizlabs/php_codesniffer": "3.*",
46+
"symfony/http-client": "^5.2"
47+
},
48+
"config": {
49+
"optimize-autoloader": true,
50+
"preferred-install": {
51+
"*": "dist"
52+
},
53+
"sort-packages": true
4054
},
4155
"scripts": {
4256
"typesenseServer": [
4357
"Composer\\Config::disableProcessTimeout",
44-
"docker run -i -p 8108:8108 -v/tmp/typesense-server-data-1c/:/data typesense/typesense:0.17.0 --data-dir /data --api-key=xyz --listen-port 8108 --enable-cors"
58+
"docker-compose up"
4559
],
4660
"lint": "phpcs -v",
4761
"lint:fix": "phpcbf"

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.5'
2+
3+
services:
4+
typesense:
5+
image: typesense/typesense:0.17.0
6+
environment:
7+
TYPESENSE_DATA_DIR: /data
8+
TYPESENSE_API_KEY: xyz
9+
volumes:
10+
- /tmp/typesense-server-data:/data
11+
ports:
12+
- 8108:8108
13+
restart: "no"

examples/alias_operations.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
include '../vendor/autoload.php';
66

7+
use Symfony\Component\HttpClient\HttplugClient;
78
use Typesense\Client;
89

910
try {
@@ -17,7 +18,7 @@
1718
'protocol' => 'http',
1819
],
1920
],
20-
'connection_timeout_seconds' => 2,
21+
'client' => new HttplugClient(),
2122
]
2223
);
2324
echo '<pre>';

examples/collection_operations.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
include '../vendor/autoload.php';
66

7+
use Symfony\Component\HttpClient\HttplugClient;
78
use Typesense\Client;
89

910
try {
@@ -17,7 +18,7 @@
1718
'protocol' => 'http',
1819
],
1920
],
20-
'connection_timeout_seconds' => 2,
21+
'client' => new HttplugClient(),
2122
]
2223
);
2324
echo '<pre>';

examples/curation_operations.php

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

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

5+
use Symfony\Component\HttpClient\HttplugClient;
56
use Typesense\Client;
67

78
try {
@@ -15,7 +16,7 @@
1516
'protocol' => 'http',
1617
],
1718
],
18-
'connection_timeout_seconds' => 2,
19+
'client' => new HttplugClient(),
1920
]
2021
);
2122
echo '<pre>';

examples/info_operations.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
include '../vendor/autoload.php';
66

7+
use Symfony\Component\HttpClient\HttplugClient;
78
use Typesense\Client;
89

910
try {
@@ -17,7 +18,7 @@
1718
'protocol' => 'http',
1819
],
1920
],
20-
'connection_timeout_seconds' => 2,
21+
'client' => new HttplugClient(),
2122
]
2223
);
2324
echo '<pre>';

examples/keys_operations.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

5+
use Symfony\Component\HttpClient\HttplugClient;
56
use Typesense\Client;
67

78
try {
@@ -15,7 +16,7 @@
1516
'protocol' => 'http',
1617
],
1718
],
18-
'connection_timeout_seconds' => 2,
19+
'client' => new HttplugClient(),
1920
]
2021
);
2122
echo '<pre>';
@@ -123,8 +124,7 @@
123124
'port' => '8108',
124125
'protocol' => 'http',
125126
],
126-
],
127-
'connection_timeout_seconds' => 2,
127+
]
128128
]
129129
);
130130

src/Alias.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Typesense;
44

5-
use GuzzleHttp\Exception\GuzzleException;
5+
use Http\Client\Exception as HttpClientException;
66
use Typesense\Exceptions\TypesenseClientError;
77

88
/**
@@ -47,7 +47,7 @@ public function endPointPath(): string
4747

4848
/**
4949
* @return array
50-
* @throws TypesenseClientError|GuzzleException
50+
* @throws TypesenseClientError|HttpClientException
5151
*/
5252
public function retrieve(): array
5353
{
@@ -56,7 +56,7 @@ public function retrieve(): array
5656

5757
/**
5858
* @return array
59-
* @throws TypesenseClientError|GuzzleException
59+
* @throws TypesenseClientError|HttpClientException
6060
*/
6161
public function delete(): array
6262
{

src/Aliases.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Typesense;
44

5-
use GuzzleHttp\Exception\GuzzleException;
5+
use Http\Client\Exception as HttpClientException;
66
use Typesense\Exceptions\TypesenseClientError;
77

88
/**
@@ -44,15 +44,15 @@ public function __construct(ApiCall $apiCall)
4444
*/
4545
public function endPointPath(string $aliasName): string
4646
{
47-
return sprintf('%s/%s', self::RESOURCE_PATH, $aliasName);
47+
return sprintf('%s/%s', static::RESOURCE_PATH, $aliasName);
4848
}
4949

5050
/**
5151
* @param string $name
5252
* @param array $mapping
5353
*
5454
* @return array
55-
* @throws TypesenseClientError|GuzzleException
55+
* @throws TypesenseClientError|HttpClientException
5656
*/
5757
public function upsert(string $name, array $mapping): array
5858
{
@@ -61,11 +61,11 @@ public function upsert(string $name, array $mapping): array
6161

6262
/**
6363
* @return array
64-
* @throws TypesenseClientError|GuzzleException
64+
* @throws TypesenseClientError|HttpClientException
6565
*/
6666
public function retrieve(): array
6767
{
68-
return $this->apiCall->get(self::RESOURCE_PATH, []);
68+
return $this->apiCall->get(static::RESOURCE_PATH, []);
6969
}
7070

7171
/**

0 commit comments

Comments
 (0)