Skip to content

Commit

Permalink
Merge pull request #6 from babeuloula/use-httplug
Browse files Browse the repository at this point in the history
Use HTTPlug instead of Guzzle
  • Loading branch information
jasonbosco authored Dec 22, 2020
2 parents 3453ef0 + e529b42 commit 88dada1
Show file tree
Hide file tree
Showing 23 changed files with 165 additions and 123 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Read the documentation here: [https://typesense.org/api/](https://typesense.org/

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

Typesense use [HTTPlug](http://httplug.io/). List of clients & adapters [here](http://docs.php-http.org/en/latest/clients.html)

## Compatibility

| Typesense Server | typesense-php |
Expand Down
22 changes: 18 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,31 @@
},
"require": {
"php": ">=7.4",
"guzzlehttp/guzzle": "^7.0",
"ext-json": "*",
"monolog/monolog": "^1.0"
"monolog/monolog": "^1.0|^2.1",
"nyholm/psr7": "^1.3",
"php-http/client-common": "^1.0",
"php-http/discovery": "^1.0",
"php-http/httplug": "^1.0",
"php-http/message-factory": "^1.0",
"psr/http-client-implementation": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.*"
"squizlabs/php_codesniffer": "3.*",
"symfony/http-client": "^5.2"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"scripts": {
"typesenseServer": [
"Composer\\Config::disableProcessTimeout",
"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"
"docker-compose up"
],
"lint": "phpcs -v",
"lint:fix": "phpcbf"
Expand Down
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.5'

services:
typesense:
image: typesense/typesense:0.17.0
environment:
TYPESENSE_DATA_DIR: /data
TYPESENSE_API_KEY: xyz
volumes:
- /tmp/typesense-server-data:/data
ports:
- 8108:8108
restart: "no"
3 changes: 2 additions & 1 deletion examples/alias_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

use Symfony\Component\HttpClient\HttplugClient;
use Typesense\Client;

try {
Expand All @@ -17,7 +18,7 @@
'protocol' => 'http',
],
],
'connection_timeout_seconds' => 2,
'client' => new HttplugClient(),
]
);
echo '<pre>';
Expand Down
3 changes: 2 additions & 1 deletion examples/collection_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

use Symfony\Component\HttpClient\HttplugClient;
use Typesense\Client;

try {
Expand All @@ -17,7 +18,7 @@
'protocol' => 'http',
],
],
'connection_timeout_seconds' => 2,
'client' => new HttplugClient(),
]
);
echo '<pre>';
Expand Down
3 changes: 2 additions & 1 deletion examples/curation_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

use Symfony\Component\HttpClient\HttplugClient;
use Typesense\Client;

try {
Expand All @@ -15,7 +16,7 @@
'protocol' => 'http',
],
],
'connection_timeout_seconds' => 2,
'client' => new HttplugClient(),
]
);
echo '<pre>';
Expand Down
3 changes: 2 additions & 1 deletion examples/info_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

use Symfony\Component\HttpClient\HttplugClient;
use Typesense\Client;

try {
Expand All @@ -17,7 +18,7 @@
'protocol' => 'http',
],
],
'connection_timeout_seconds' => 2,
'client' => new HttplugClient(),
]
);
echo '<pre>';
Expand Down
6 changes: 3 additions & 3 deletions examples/keys_operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

use Symfony\Component\HttpClient\HttplugClient;
use Typesense\Client;

try {
Expand All @@ -15,7 +16,7 @@
'protocol' => 'http',
],
],
'connection_timeout_seconds' => 2,
'client' => new HttplugClient(),
]
);
echo '<pre>';
Expand Down Expand Up @@ -123,8 +124,7 @@
'port' => '8108',
'protocol' => 'http',
],
],
'connection_timeout_seconds' => 2,
]
]
);

Expand Down
6 changes: 3 additions & 3 deletions src/Alias.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Typesense;

use GuzzleHttp\Exception\GuzzleException;
use Http\Client\Exception as HttpClientException;
use Typesense\Exceptions\TypesenseClientError;

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ public function endPointPath(): string

/**
* @return array
* @throws TypesenseClientError|GuzzleException
* @throws TypesenseClientError|HttpClientException
*/
public function retrieve(): array
{
Expand All @@ -56,7 +56,7 @@ public function retrieve(): array

/**
* @return array
* @throws TypesenseClientError|GuzzleException
* @throws TypesenseClientError|HttpClientException
*/
public function delete(): array
{
Expand Down
10 changes: 5 additions & 5 deletions src/Aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Typesense;

use GuzzleHttp\Exception\GuzzleException;
use Http\Client\Exception as HttpClientException;
use Typesense\Exceptions\TypesenseClientError;

/**
Expand Down Expand Up @@ -44,15 +44,15 @@ public function __construct(ApiCall $apiCall)
*/
public function endPointPath(string $aliasName): string
{
return sprintf('%s/%s', self::RESOURCE_PATH, $aliasName);
return sprintf('%s/%s', static::RESOURCE_PATH, $aliasName);
}

/**
* @param string $name
* @param array $mapping
*
* @return array
* @throws TypesenseClientError|GuzzleException
* @throws TypesenseClientError|HttpClientException
*/
public function upsert(string $name, array $mapping): array
{
Expand All @@ -61,11 +61,11 @@ public function upsert(string $name, array $mapping): array

/**
* @return array
* @throws TypesenseClientError|GuzzleException
* @throws TypesenseClientError|HttpClientException
*/
public function retrieve(): array
{
return $this->apiCall->get(self::RESOURCE_PATH, []);
return $this->apiCall->get(static::RESOURCE_PATH, []);
}

/**
Expand Down
Loading

0 comments on commit 88dada1

Please sign in to comment.