From 85c636b758a56a56d955ea78b160f5ac963ca866 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 8 Feb 2019 08:23:21 -0600 Subject: [PATCH] formatting --- CHANGELOG.md | 2 +- UPGRADE.md | 16 +++++++++++----- src/EngineManager.php | 30 ++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8acfbf53..f1c9c0fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## [Unreleased (2019-xx-xx)](https://github.com/laravel/scout/compare/v6.1.3...master) ### Changed -- Upgrade Algolia API client to v2 ([#349](https://github.com/laravel/scout/pull/349), [#353](https://github.com/laravel/scout/pull/353)) +- Upgraded Algolia API client to v2 ([#349](https://github.com/laravel/scout/pull/349), [#353](https://github.com/laravel/scout/pull/353)) ## [v6.1.3 (2018-12-11)](https://github.com/laravel/scout/compare/v6.1.2...v6.1.3) diff --git a/UPGRADE.md b/UPGRADE.md index 93499cae..b6bc5e73 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -6,12 +6,18 @@ Update your `laravel/scout` dependency to `^7.0` in your `composer.json` file. -### When using the Algolia driver +### Algolia Driver -Update your `algolia/algoliasearch-client-php` dependency to `^2.2` in your `composer.json` file. +If you are using Algolia as your search provider, update your `algolia/algoliasearch-client-php` dependency to `^2.2` in your `composer.json` file. -If you were relying on the exception `AlgoliaSearch\AlgoliaException`, you may need to adapt your code since it got renamed to `Algolia\AlgoliaSearch\Exceptions\AlgoliaException`. +#### Exception Renaming -If you were customizing engine searches giving a callback as the second argument of the method `search` in your models, the first argument of the given callback is now an instance of `Algolia\AlgoliaSearch\SearchIndex`. +The `AlgoliaSearch\AlgoliaException` exception class was renamed to `Algolia\AlgoliaSearch\Exceptions\AlgoliaException`. -If you were using the Algolia API Client source code directly, consider review the [full changelog here](https://github.com/algolia/algoliasearch-client-php/blob/master/docs/UPGRADE-from-v1-to-v2.md). +#### The `search` Method Callback + +If you are passing a callback to the `search` method, the callback will now receive an instance of `Algolia/AlgoliaSearch/SearchIndex` as its first argument. + +#### Misc. + +If you are using the Algolia API client directly, consider reviewing the [full changelog provided by Algolia](https://github.com/algolia/algoliasearch-client-php/blob/master/docs/UPGRADE-from-v1-to-v2.md). diff --git a/src/EngineManager.php b/src/EngineManager.php index 835533f4..65b6294f 100644 --- a/src/EngineManager.php +++ b/src/EngineManager.php @@ -2,7 +2,7 @@ namespace Laravel\Scout; -use Error; +use Exception; use Illuminate\Support\Manager; use Laravel\Scout\Engines\NullEngine; use Laravel\Scout\Engines\AlgoliaEngine; @@ -29,15 +29,7 @@ public function engine($name = null) */ public function createAlgoliaDriver() { - if (! class_exists(Algolia::class)) { - if (class_exists('AlgoliaSearch\Client')) { - throw new Error('Laravel Scout do not support Algolia API Client v1. Update your - `algolia/algoliasearch-client-php` dependency to `^2.2` in your `composer.json` file.'); - } - - throw new Error('Algolia API Client not found. Add the - `"algolia/algoliasearch-client-php": "^2.2"` dependency to your `composer.json` file.'); - } + $this->ensureAlgoliaClientIsInstalled(); UserAgent::addCustomUserAgent('Laravel Scout', '7.0.0'); @@ -46,6 +38,24 @@ public function createAlgoliaDriver() )); } + /** + * Ensure the Algolia API client is installed. + * + * @return void + */ + protected function ensureAlgoliaClientIsInstalled() + { + if (class_exists(Algolia::class)) { + return; + } + + if (class_exists('AlgoliaSearch\Client')) { + throw new Exception('Please upgrade your Algolia client to version: ^2.2.'); + } + + throw new Exception('Please install the Agolia client: algolia/algoliasearch-client-php.'); + } + /** * Create a Null engine instance. *