├── LICENSE ├── composer.json ├── config └── algolia.php └── src ├── AlgoliaFactory.php ├── AlgoliaManager.php ├── AlgoliaServiceProvider.php └── Facades └── Algolia.php /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Vincent Klaiber 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vinkla/algolia", 3 | "description": "An Algolia bridge for Laravel", 4 | "keywords": [ 5 | "algolia", 6 | "laravel" 7 | ], 8 | "license": "MIT", 9 | "authors": [ 10 | { 11 | "name": "Vincent Klaiber", 12 | "homepage": "https://github.com/vinkla" 13 | } 14 | ], 15 | "require": { 16 | "php": "^7.4", 17 | "algolia/algoliasearch-client-php": "^2.5", 18 | "graham-campbell/manager": "^4.4", 19 | "illuminate/contracts": "^7.0", 20 | "illuminate/support": "^7.0" 21 | }, 22 | "require-dev": { 23 | "graham-campbell/analyzer": "^3.0", 24 | "graham-campbell/testbench": "^5.4", 25 | "mockery/mockery": "^1.3", 26 | "phpunit/phpunit": "^9.0", 27 | "squizlabs/php_codesniffer": "^3.5" 28 | }, 29 | "config": { 30 | "preferred-install": "dist" 31 | }, 32 | "extra": { 33 | "branch-alias": { 34 | "dev-master": "6.0-dev" 35 | }, 36 | "laravel": { 37 | "providers": [ 38 | "Vinkla\\Algolia\\AlgoliaServiceProvider" 39 | ], 40 | "aliases": { 41 | "Algolia": "Vinkla\\Algolia\\Facades\\Algolia" 42 | } 43 | } 44 | }, 45 | "autoload": { 46 | "psr-4": { 47 | "Vinkla\\Algolia\\": "src/" 48 | } 49 | }, 50 | "autoload-dev": { 51 | "psr-4": { 52 | "Vinkla\\Tests\\Algolia\\": "tests/" 53 | } 54 | }, 55 | "minimum-stability": "dev", 56 | "prefer-stable": true 57 | } 58 | -------------------------------------------------------------------------------- /config/algolia.php: -------------------------------------------------------------------------------- 1 | 'main', 28 | 29 | /* 30 | |-------------------------------------------------------------------------- 31 | | Algolia Connections 32 | |-------------------------------------------------------------------------- 33 | | 34 | | Here are each of the connections setup for your application. Example 35 | | configuration has been included, but you may add as many connections as 36 | | you would like. 37 | | 38 | */ 39 | 40 | 'connections' => [ 41 | 42 | 'main' => [ 43 | 'id' => 'your-application-id', 44 | 'key' => 'your-api-key', 45 | ], 46 | 47 | 'alternative' => [ 48 | 'id' => 'your-application-id', 49 | 'key' => 'your-api-key', 50 | ], 51 | 52 | ], 53 | 54 | ]; 55 | -------------------------------------------------------------------------------- /src/AlgoliaFactory.php: -------------------------------------------------------------------------------- 1 | getConfig($config); 25 | 26 | return $this->getClient($config); 27 | } 28 | 29 | /** 30 | * @throws \InvalidArgumentException 31 | */ 32 | protected function getConfig(array $config): array 33 | { 34 | $keys = ['id', 'key']; 35 | 36 | foreach ($keys as $key) { 37 | if (!array_key_exists($key, $config)) { 38 | throw new InvalidArgumentException("Missing configuration key [$key]."); 39 | } 40 | } 41 | 42 | return Arr::only($config, $keys); 43 | } 44 | 45 | protected function getClient(array $auth): SearchClient 46 | { 47 | return SearchClient::create( 48 | $auth['id'], 49 | $auth['key'] 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/AlgoliaManager.php: -------------------------------------------------------------------------------- 1 | factory = $factory; 29 | } 30 | 31 | protected function createConnection(array $config): SearchClient 32 | { 33 | return $this->factory->make($config); 34 | } 35 | 36 | protected function getConfigName(): string 37 | { 38 | return 'algolia'; 39 | } 40 | 41 | public function getFactory(): AlgoliaFactory 42 | { 43 | return $this->factory; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/AlgoliaServiceProvider.php: -------------------------------------------------------------------------------- 1 | setupConfig(); 27 | } 28 | 29 | protected function setupConfig(): void 30 | { 31 | $source = realpath($raw = __DIR__ . '/../config/algolia.php') ?: $raw; 32 | 33 | if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) { 34 | $this->publishes([$source => config_path('algolia.php')]); 35 | } elseif ($this->app instanceof LumenApplication) { 36 | $this->app->configure('algolia'); 37 | } 38 | 39 | $this->mergeConfigFrom($source, 'algolia'); 40 | } 41 | 42 | public function register(): void 43 | { 44 | $this->registerFactory(); 45 | $this->registerManager(); 46 | $this->registerBindings(); 47 | } 48 | 49 | protected function registerFactory(): void 50 | { 51 | $this->app->singleton('algolia.factory', function () { 52 | return new AlgoliaFactory(); 53 | }); 54 | 55 | $this->app->alias('algolia.factory', AlgoliaFactory::class); 56 | } 57 | 58 | protected function registerManager(): void 59 | { 60 | $this->app->singleton('algolia', function (Container $app) { 61 | $config = $app['config']; 62 | $factory = $app['algolia.factory']; 63 | 64 | return new AlgoliaManager($config, $factory); 65 | }); 66 | 67 | $this->app->alias('algolia', AlgoliaManager::class); 68 | } 69 | 70 | protected function registerBindings(): void 71 | { 72 | $this->app->bind('algolia.connection', function (Container $app) { 73 | $manager = $app['algolia']; 74 | 75 | return $manager->connection(); 76 | }); 77 | 78 | $this->app->alias('algolia.connection', SearchClient::class); 79 | } 80 | 81 | /** 82 | * @return string[] 83 | */ 84 | public function provides(): array 85 | { 86 | return [ 87 | 'algolia', 88 | 'algolia.factory', 89 | 'algolia.connection', 90 | ]; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Facades/Algolia.php: -------------------------------------------------------------------------------- 1 |