Skip to content

Commit bf0db47

Browse files
committed
docs(php): add remaining guides
1 parent cdf2e70 commit bf0db47

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed

website/docs/clients/guides/copy-or-move-index.mdx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ const { taskID } = await client.operationIndex({
3535
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
3636
```
3737

38+
</TabItem>
39+
<TabItem value="php">
40+
41+
```php
42+
$client = SearchClient::create(
43+
'<YOUR_APP_ID>',
44+
'<YOUR_APP_ID>'
45+
);
46+
47+
$response = $client->operationIndex(
48+
'<SOURCE_INDEX_NAME>',
49+
[
50+
'operation' => 'copy',
51+
'destination' => '<DESTINATION_INDEX_NAME>',
52+
]
53+
);
54+
55+
// Poll the task status with defaults values
56+
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
57+
```
58+
3859
</TabItem>
3960
<TabItem value="java">
4061

@@ -79,6 +100,27 @@ const { taskID } = await client.operationIndex({
79100
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
80101
```
81102

103+
</TabItem>
104+
<TabItem value="php">
105+
106+
```php
107+
$client = SearchClient::create(
108+
'<YOUR_APP_ID>',
109+
'<YOUR_APP_ID>'
110+
);
111+
112+
$response = $client->operationIndex(
113+
'<SOURCE_INDEX_NAME>',
114+
[
115+
'operation' => 'move',
116+
'destination' => '<DESTINATION_INDEX_NAME>',
117+
]
118+
);
119+
120+
// Poll the task status with defaults values
121+
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
122+
```
123+
82124
</TabItem>
83125
<TabItem value="java">
84126

@@ -126,6 +168,28 @@ const { taskID } = await client.operationIndex({
126168
await client.waitForTask({ indexName: '<SOURCE_INDEX_NAME>', taskID });
127169
```
128170

171+
</TabItem>
172+
<TabItem value="php">
173+
174+
```php
175+
$client = SearchClient::create(
176+
'<YOUR_APP_ID>',
177+
'<YOUR_APP_ID>'
178+
);
179+
180+
$response = $client->operationIndex(
181+
'<SOURCE_INDEX_NAME>',
182+
[
183+
'operation' => 'move',
184+
'destination' => '<DESTINATION_INDEX_NAME>',
185+
'scope' => ['rules'],
186+
]
187+
);
188+
189+
// Poll the task status with defaults values
190+
$client->waitForTask('<SOURCE_INDEX_NAME>', $response['taskID']);
191+
```
192+
129193
</TabItem>
130194
<TabItem value="java">
131195

website/docs/clients/guides/customized-client-usage.mdx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ await client.search(
4040
);
4141
```
4242

43+
</TabItem>
44+
<TabItem value="php">
45+
46+
```php
47+
$client->search(
48+
[
49+
'requests' => [
50+
[
51+
'indexName' => '<YOUR_INDEX_NAME>',
52+
'query' => '<YOUR_QUERY>',
53+
'facets' => ['author', 'genre'],
54+
],
55+
]
56+
],
57+
[
58+
// This header is added to the request
59+
'headers' => ['additional-header' => 'hello'],
60+
// As we re-define `hitsPerPage`, it will override the value defined in the method's parameters.
61+
'queryParameters' => ['hitsPerPage' => 100],
62+
]
63+
);
64+
```
65+
4366
</TabItem>
4467
<TabItem value="java">
4568

@@ -86,7 +109,23 @@ client.addAlgoliaAgent('my user agent', 'optional version');
86109
```
87110

88111
</TabItem>
112+
<TabItem value="php">
89113

114+
```php
115+
$client = SearchClient::create(
116+
'<YOUR_APP_ID>',
117+
'<YOUR_APP_ID>'
118+
);
119+
120+
// This will append `; my user agent (optional version)` to the current value of `x-algolia-agent` for every requests
121+
Algolia\AlgoliaSearch\Support\AlgoliaAgent::addCustomAlgoliaAgent(
122+
$client->getClientConfig()->getClientName(),
123+
"my user agent",
124+
"optional version"
125+
);
126+
```
127+
128+
</TabItem>
90129
<TabItem value="java">
91130

92131
```java
@@ -124,7 +163,31 @@ const client = searchClient('<YOUR_APP_ID>', '<YOUR_API_KEY>', {
124163
```
125164

126165
</TabItem>
166+
<TabItem value="php">
167+
168+
> In PHP, the requests are handled by the HTTP Client (by default GuzzleHttpClient)
169+
170+
```php
171+
use Algolia\AlgoliaSearch\Api\SearchClient;
172+
use Algolia\AlgoliaSearch\Configuration\SearchConfig;
173+
use Algolia\AlgoliaSearch\Http\HttpClientInterface;
174+
use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper;
175+
use Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts;
176+
177+
// Create a config and a clusterhosts objects with your credentials
178+
$config = SearchConfig::create('<YOUR_APP_ID>', '<YOUR_API_KEY>');
179+
$clusterHosts = ClusterHosts::createFromAppId('<YOUR_APP_ID>');
127180

181+
// Instanciate a MyHttpClient object implementing HttpClientInterface (replacing GuzzleHttpClient)
182+
$myHttpClient = new MyHttpClient(...);
183+
// Now create you custom Api wrapper
184+
$apiWrapper = new ApiWrapper($myHttpClient, $config, $clusterHosts);
185+
186+
// Instanciate your client using the constructor
187+
$client = new SearchClient($apiWrapper, $config);
188+
```
189+
190+
</TabItem>
128191
<TabItem value="java">
129192

130193
> Create your own requester by creating a class that implements `com.algolia.utils.Requester`, and use it by passing it to the client constructor.

website/docs/clients/guides/wait-for-a-task-to-finish.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,41 @@ await client.waitForTask({
4040
});
4141
```
4242

43+
</TabItem>
44+
<TabItem value="php">
45+
46+
```php
47+
$client = SearchClient::create(
48+
'<YOUR_APP_ID>',
49+
'<YOUR_APP_ID>'
50+
);
51+
52+
$response = $client->saveObject(
53+
'<YOUR_INDEX_NAME>',
54+
['title' => "My Algolia Object"],
55+
$requestOptions
56+
);
57+
58+
// Poll the task status with defaults values
59+
$client->waitForTask('<YOUR_INDEX_NAME>', $response['taskID']);
60+
61+
// Poll the task status with your options
62+
Algolia\AlgoliaSearch\Support\Helpers::retryUntil(
63+
$client,
64+
'getTask',
65+
['<YOUR_INDEX_NAME>', $response['taskID'], $requestOptions],
66+
function ($res) {
67+
return 'published' === $res['status'];
68+
},
69+
100, // Number of maximum retries to do
70+
5000, // Default timeout
71+
// Calculation of the time to wait between tries
72+
function ($timeout, $retryCount) {
73+
return min($retryCount * 200, $timeout) * 1000;
74+
}
75+
);
76+
```
77+
4378
</TabItem>
4479
<TabItem value="java">
4580

0 commit comments

Comments
 (0)