Skip to content

Commit 83b921e

Browse files
committed
Tweaks and typo fixes
1 parent 8618a5d commit 83b921e

31 files changed

Lines changed: 233 additions & 187 deletions

README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
PHP client for the Typesense API: https://github.com/typesense/typesense
44

5-
Follows the Typesense [API specification](https://github.com/typesense/typesense-api-spec).
6-
75
## Installation
86

97
```
10-
$ composer require devloopsnet/typesens-php
8+
$ composer require typesense/typesense-php
119
```
1210

13-
You can also add `devloopsnet/typesense-php` to your project's `composer.json`.
11+
You can also add `typesense/typesense-php` to your project's `composer.json`.
1412

1513
## Usage
1614

17-
You can find some examples [here](https://github.com/devloopsnet/typesense-php/blob/master/examples/collection_operations.php).
15+
You can find some examples [here](https://github.com/typesense/typesense-php/blob/master/examples/collection_operations.php).
1816

1917
See detailed [API documentation](https://typesense.org/api).
2018

@@ -28,14 +26,11 @@ See detailed [API documentation](https://typesense.org/api).
2826

2927
## Contributing
3028

31-
Bug reports and pull requests are welcome on GitHub at [https://github.com/devloopsnet/typesense-php].
32-
33-
## Author
34-
35-
[Abdullah Al-Faqeir](https://github.org/abdullahfaqeir)
36-
37-
## License
29+
Bug reports and pull requests are welcome on GitHub at [https://github.com/typesense/typesense-php].
3830

39-
`typesense-php` is distributed under the Apache 2 license.
31+
## Credits
4032

33+
This client was originally developed by [Abdullah Al-Faqeir](https://github.org/abdullahfaqeir) and was
34+
[adopted](https://github.com/devloopsnet/typesense-php/issues/4) as the official PHP client library for Typesense in Oct 2020.
4135

36+
Ongoing development and support is now provided by Typesense, in addition to our collaborators.

composer.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
{
2-
"name": "devloopsnet/typesens-php",
2+
"name": "typesense/typesense-php",
33
"description": "PHP client for Typesense https://github.com/typesense/typesense",
44
"type": "library",
5-
"homepage": "https://www.devloops.net",
5+
"homepage": "https://github.com/typesense/typesense-php",
66
"license": "Apache-2.0",
77
"authors": [
8+
{
9+
"name": "Typesense",
10+
"email": "contact@typesense.org",
11+
"homepage": "https://typesense.org",
12+
"role": "Developer"
13+
},
814
{
915
"name": "Abdullah Al-Faqeir",
1016
"email": "abdullah@devloops.net",
1117
"homepage": "https://www.devloops.net",
1218
"role": "Developer"
1319
}
1420
],
21+
"support": {
22+
"docs": "https://typesense.org/api",
23+
"source": "https://github.com/typesense/typesense-php",
24+
"issues": "https://github.com/typesense/typesense-php/issues"
25+
},
1526
"minimum-stability": "stable",
1627
"autoload": {
1728
"psr-4": {
18-
"Typesence\\": "src/"
29+
"Typesense\\": "src/"
1930
}
2031
},
2132
"require": {
22-
"php/php": ">7.4.*",
33+
"php": ">=7.4",
2334
"guzzlehttp/guzzle": "^7.0",
2435
"ext-json": "*"
36+
},
37+
"scripts": {
38+
"typesenseServer": "docker run -i -p 8108:8108 -v/tmp/typesense-server-data-1c/:/data typesense/typesense:0.15.0 --data-dir /data --api-key=xyz --listen-port 8108 --enable-cors"
2539
}
2640
}

examples/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### Running the examples
2+
3+
Start a local typesense server via docker:
4+
5+
```shell script
6+
composer run-script typesenseServer
7+
```
8+
9+
Then:
10+
11+
```shell script
12+
cd examples
13+
php <example_name>.php
14+
```

examples/alias_operations.php

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

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

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

77
try {
88
$client = new Client(
99
[
10-
'api_key' => 'abcd',
10+
'api_key' => 'xyz',
1111
'nodes' => [
1212
[
1313
'host' => 'localhost',
@@ -19,6 +19,16 @@
1919
]
2020
);
2121
echo '<pre>';
22+
try {
23+
print_r($client->aliases['books']->delete());
24+
} catch (Exception $e) {
25+
// Don't error out if the collection was not found
26+
}
27+
try {
28+
print_r($client->collections['books_january']->delete());
29+
} catch (Exception $e) {
30+
// Don't error out if the collection was not found
31+
}
2232
echo "--------Create Collection-------\n";
2333
print_r(
2434
$client->collections->create(

examples/collection_operations.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

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

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

77
try {
88
$client = new Client(
99
[
10-
'api_key' => 'abcd',
10+
'api_key' => 'xyz',
1111
'nodes' => [
1212
[
1313
'host' => 'localhost',
@@ -19,7 +19,13 @@
1919
]
2020
);
2121
echo '<pre>';
22-
//print_r($client->collections['books']->delete());
22+
23+
try {
24+
print_r($client->collections['books']->delete());
25+
} catch (Exception $e) {
26+
// Don't error out if the collection was not found
27+
}
28+
2329
echo "--------Create Collection-------\n";
2430
print_r(
2531
$client->collections->create(
@@ -125,7 +131,8 @@
125131
echo "\n";
126132
echo "--------Import Documents-------\n";
127133
$docsToImport = [];
128-
foreach ($exportedDocStrs as $exportedDocStr) {
134+
$exportedDocStrsArray = explode('\n', $exportedDocStrs);
135+
foreach ($exportedDocStrsArray as $exportedDocStr) {
129136
$docsToImport[] = json_decode($exportedDocStr, true);
130137
}
131138
$importRes =

examples/curation_operations.php

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

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

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

77
try {
88
$client = new Client(
99
[
10-
'api_key' => 'abcd',
10+
'api_key' => 'xyz',
1111
'nodes' => [
1212
[
1313
'host' => 'localhost',
@@ -19,6 +19,11 @@
1919
]
2020
);
2121
echo '<pre>';
22+
try {
23+
print_r($client->collections['books']->delete());
24+
} catch (Exception $e) {
25+
// Don't error out if the collection was not found
26+
}
2227
echo "--------Create Collection-------\n";
2328
print_r(
2429
$client->collections->create(

src/Alias.php

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

3-
namespace Typesence;
3+
namespace Typesense;
44

5-
use \Typesence\Lib\Configuration;
5+
use \Typesense\Lib\Configuration;
66

77
/**
88
* Class Alias
99
*
10-
* @package \Typesence
10+
* @package \Typesense
1111
* @date 4/5/20
1212
* @author Abdullah Al-Faqeir <abdullah@devloops.net>
1313
*/
1414
class Alias
1515
{
1616

1717
/**
18-
* @var \Typesence\Lib\Configuration
18+
* @var \Typesense\Lib\Configuration
1919
*/
2020
private Configuration $config;
2121

@@ -25,14 +25,14 @@ class Alias
2525
private string $name;
2626

2727
/**
28-
* @var \Typesence\ApiCall
28+
* @var \Typesense\ApiCall
2929
*/
3030
private ApiCall $apiCall;
3131

3232
/**
3333
* Alias constructor.
3434
*
35-
* @param \Typesence\Lib\Configuration $config
35+
* @param \Typesense\Lib\Configuration $config
3636
* @param string $name
3737
*/
3838
public function __construct(Configuration $config, string $name)
@@ -52,7 +52,7 @@ public function endPointPath(): string
5252

5353
/**
5454
* @return array
55-
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
55+
* @throws \Typesense\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
5656
*/
5757
public function retrieve(): array
5858
{
@@ -61,7 +61,7 @@ public function retrieve(): array
6161

6262
/**
6363
* @return array
64-
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
64+
* @throws \Typesense\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
6565
*/
6666
public function delete(): array
6767
{

src/Aliases.php

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

3-
namespace Typesence;
3+
namespace Typesense;
44

5-
use \Typesence\Lib\Configuration;
5+
use \Typesense\Lib\Configuration;
66

77
/**
88
* Class Aliases
99
*
10-
* @package \Typesence
10+
* @package \Typesense
1111
* @date 4/5/20
1212
* @author Abdullah Al-Faqeir <abdullah@devloops.net>
1313
*/
@@ -17,12 +17,12 @@ class Aliases implements \ArrayAccess
1717
public const RESOURCE_PATH = '/aliases';
1818

1919
/**
20-
* @var \Typesence\Lib\Configuration
20+
* @var \Typesense\Lib\Configuration
2121
*/
2222
private Configuration $config;
2323

2424
/**
25-
* @var \Typesence\ApiCall
25+
* @var \Typesense\ApiCall
2626
*/
2727
private ApiCall $apiCall;
2828

@@ -34,7 +34,7 @@ class Aliases implements \ArrayAccess
3434
/**
3535
* Aliases constructor.
3636
*
37-
* @param \Typesence\Lib\Configuration $config
37+
* @param \Typesense\Lib\Configuration $config
3838
*/
3939
public function __construct(Configuration $config)
4040
{
@@ -57,7 +57,7 @@ public function endPointPath(string $aliasName): string
5757
* @param array $mapping
5858
*
5959
* @return array
60-
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
60+
* @throws \Typesense\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
6161
*/
6262
public function upsert(string $name, array $mapping): array
6363
{
@@ -66,11 +66,11 @@ public function upsert(string $name, array $mapping): array
6666

6767
/**
6868
* @return array
69-
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
69+
* @throws \Typesense\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
7070
*/
7171
public function retrieve(): array
7272
{
73-
return $this->apiCall->get($this->endPointPath(self::RESOURCE_PATH), []);
73+
return $this->apiCall->get(self::RESOURCE_PATH, []);
7474
}
7575

7676
/**

0 commit comments

Comments
 (0)