|
7 | 7 | use Closure;
|
8 | 8 | use Illuminate\Cache\CacheManager;
|
9 | 9 | use Illuminate\Cache\Repository;
|
| 10 | +use Illuminate\Container\Container; |
10 | 11 | use Illuminate\Filesystem\FilesystemAdapter;
|
11 | 12 | use Illuminate\Filesystem\FilesystemManager;
|
12 | 13 | use Illuminate\Foundation\Application;
|
13 | 14 | use Illuminate\Session\SessionManager;
|
14 | 15 | use Illuminate\Support\ServiceProvider;
|
15 | 16 | use InvalidArgumentException;
|
| 17 | +use Laravel\Scout\EngineManager; |
16 | 18 | use League\Flysystem\Filesystem;
|
17 | 19 | use League\Flysystem\GridFS\GridFSAdapter;
|
18 | 20 | use League\Flysystem\ReadOnly\ReadOnlyFilesystemAdapter;
|
19 | 21 | use MongoDB\GridFS\Bucket;
|
20 | 22 | use MongoDB\Laravel\Cache\MongoStore;
|
21 | 23 | use MongoDB\Laravel\Eloquent\Model;
|
22 | 24 | use MongoDB\Laravel\Queue\MongoConnector;
|
| 25 | +use MongoDB\Laravel\Scout\ScoutEngine; |
23 | 26 | use RuntimeException;
|
24 | 27 | use Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler;
|
25 | 28 |
|
@@ -102,6 +105,7 @@ public function register()
|
102 | 105 | });
|
103 | 106 |
|
104 | 107 | $this->registerFlysystemAdapter();
|
| 108 | + $this->registerScoutEngine(); |
105 | 109 | }
|
106 | 110 |
|
107 | 111 | private function registerFlysystemAdapter(): void
|
@@ -155,4 +159,21 @@ private function registerFlysystemAdapter(): void
|
155 | 159 | });
|
156 | 160 | });
|
157 | 161 | }
|
| 162 | + |
| 163 | + private function registerScoutEngine(): void |
| 164 | + { |
| 165 | + $this->app->resolving(EngineManager::class, function (EngineManager $engineManager) { |
| 166 | + $engineManager->extend('mongodb', function (Container $app) { |
| 167 | + $connectionName = $app->get('config')->get('scout.mongodb.connection', 'mongodb'); |
| 168 | + $connection = $app->get('db')->connection($connectionName); |
| 169 | + $softDelete = (bool) $app->get('config')->get('scout.soft_delete', false); |
| 170 | + |
| 171 | + assert($connection instanceof Connection, new InvalidArgumentException(sprintf('The connection "%s" is not a MongoDB connection.', $connectionName))); |
| 172 | + |
| 173 | + return new ScoutEngine($connection->getMongoDB(), $softDelete); |
| 174 | + }); |
| 175 | + |
| 176 | + return $engineManager; |
| 177 | + }); |
| 178 | + } |
158 | 179 | }
|
0 commit comments