Skip to content

docs(php): update migration guide for PHP #935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion website/docs/clients/guides/send-data-to-algolia.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ $records = [
$requests = [];

foreach ($records as $record) {
$requests += [
$requests[] = [
'action' => 'addObject',
'body' => $record
];
Expand Down
23 changes: 22 additions & 1 deletion website/docs/clients/migration-guides/php.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ title: PHP
|-----------------------------------------------|:---------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `"algolia/algoliasearch-client-php": "^3.2"` | `"algolia/algoliasearch-client-php": "^4.0@alpha"` | **During the beta phase**, the clients are available under the package 4.x.x-alpha , you can find a full list [here](https://packagist.org/packages/algolia/algoliasearch-client-php). |
| `Algolia\AlgoliaSearch` | `Algolia\AlgoliaSearch\Api` | Exported clients have now the namespace suffixed by `Api`. |
| `Algolia\AlgoliaSearch\Support\UserAgent` | `Algolia\AlgoliaSearch\Support\AlgoliaAgent` | `UserAgent` class has been renamed to `AlgoliaAgent` for consistency across client languages (`addCustomUserAgent` method also became `addAlgoliaAgent`). |
| `Algolia\AlgoliaSearch\SearchIndex` | **removed** | Since the method `initIndex` doesn't exist anymore, we decided to merge the `SearchIndex` class inside the `SearchClient` one, now all the methods related to search endpoints are located there. |
| `Algolia\AlgoliaSearch\Cache\FileCacheDriver` | **removed** | This implementation of the `CacheInterface` is not available anymore in the Client. If you feel the need for it, [please open an issue](https://github.com/algolia/api-clients-automation/issues/new?assignees=&labels=&template=Feature_request.md) |


### Usage

To get started, first uninstall the previously added clients.
Expand Down Expand Up @@ -55,3 +56,23 @@ $searchResults2 = $client->search([
],
]);
```

### Generate a secured Api Key

The `SearchClient::generateSecuredApiKey()` from the previous client was removed, but you can still create them:

```php
use Algolia\AlgoliaSearch\Support\Helpers;

// Key will be valid for 25 hours.
$validUntil = time() + (3600 * 25);

$urlEncodedRestrictions = Helpers::buildQuery([
'restrictIndices' => '<YOUR_INDEX_NAME>',
'validUntil' => $validUntil,
]);

$content = hash_hmac('sha256', $urlEncodedRestrictions, '<YOUR_SEARCH_KEY>').$urlEncodedRestrictions;
$securedSearchKey = base64_encode($content);

```