Skip to content

Commit a4797cf

Browse files
Merge #359
359: Allow to configure custom http client r=curquiza a=norkunas # Pull Request ## Related issue Fixes #357 ## What does this PR do? - Allows to configure custom http client ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Co-authored-by: Tomas <[email protected]>
2 parents a420c1f + 2c3080e commit a4797cf

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

config/services.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
</service>
2929

3030
<service id="meilisearch.client" class="Meilisearch\Client" public="true" lazy="true">
31-
<argument /><!-- url -->
32-
<argument /><!-- api key -->
33-
<argument type="service" id="psr18.http_client" on-invalid="ignore" /><!-- http client -->
31+
<argument type="abstract">url defined in MeilisearchExtension</argument>
32+
<argument type="abstract">api key defined in MeilisearchExtension</argument>
33+
<argument type="abstract">http client defined in MeilisearchExtension</argument>
3434
<argument>null</argument><!-- request factory -->
35-
<argument /><!-- client agents -->
35+
<argument type="abstract">client agents defined in MeilisearchExtension</argument>
3636
<argument>null</argument><!-- stream factory -->
3737
</service>
3838
<service id="search.client" alias="meilisearch.client" public="true">

src/DependencyInjection/Configuration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public function getConfigTreeBuilder(): TreeBuilder
3535
->scalarNode('serializer')
3636
->defaultValue('serializer')
3737
->end()
38+
->scalarNode('http_client')
39+
->defaultValue('psr18.http_client')
40+
->end()
3841
->arrayNode('indices')
3942
->arrayPrototype()
4043
->children()

src/DependencyInjection/MeilisearchExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Meilisearch\Bundle\Services\UnixTimestampNormalizer;
99
use Symfony\Component\Config\FileLocator;
1010
use Symfony\Component\DependencyInjection\ContainerBuilder;
11+
use Symfony\Component\DependencyInjection\ContainerInterface;
1112
use Symfony\Component\DependencyInjection\Extension\Extension;
1213
use Symfony\Component\DependencyInjection\Loader;
1314
use Symfony\Component\DependencyInjection\Reference;
@@ -50,6 +51,7 @@ public function load(array $configs, ContainerBuilder $container): void
5051
$container->findDefinition('meilisearch.client')
5152
->replaceArgument(0, $config['url'])
5253
->replaceArgument(1, $config['api_key'])
54+
->replaceArgument(2, new Reference($config['http_client'], ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
5355
->replaceArgument(4, [MeilisearchBundle::qualifiedVersion()]);
5456

5557
$container->findDefinition('meilisearch.service')

tests/Unit/ConfigurationTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static function dataTestConfigurationTree(): iterable
3939
'batchSize' => 500,
4040
'serializer' => 'serializer',
4141
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
42+
'http_client' => 'psr18.http_client',
4243
'indices' => [],
4344
],
4445
];
@@ -59,6 +60,7 @@ public static function dataTestConfigurationTree(): iterable
5960
'batchSize' => 100,
6061
'serializer' => 'serializer',
6162
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
63+
'http_client' => 'psr18.http_client',
6264
'indices' => [],
6365
],
6466
];
@@ -85,6 +87,7 @@ public static function dataTestConfigurationTree(): iterable
8587
'batchSize' => 500,
8688
'serializer' => 'serializer',
8789
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
90+
'http_client' => 'psr18.http_client',
8891
'indices' => [
8992
0 => [
9093
'name' => 'posts',
@@ -156,6 +159,7 @@ public static function dataTestConfigurationTree(): iterable
156159
'batchSize' => 500,
157160
'serializer' => 'serializer',
158161
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
162+
'http_client' => 'psr18.http_client',
159163
],
160164
];
161165

@@ -191,6 +195,7 @@ public static function dataTestConfigurationTree(): iterable
191195
'batchSize' => 500,
192196
'serializer' => 'serializer',
193197
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
198+
'http_client' => 'psr18.http_client',
194199
],
195200
];
196201

@@ -228,6 +233,7 @@ public static function dataTestConfigurationTree(): iterable
228233
'batchSize' => 500,
229234
'serializer' => 'serializer',
230235
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
236+
'http_client' => 'psr18.http_client',
231237
],
232238
];
233239

@@ -265,6 +271,25 @@ public static function dataTestConfigurationTree(): iterable
265271
'batchSize' => 500,
266272
'serializer' => 'serializer',
267273
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
274+
'http_client' => 'psr18.http_client',
275+
],
276+
];
277+
278+
yield 'custom http client' => [
279+
'inputConfig' => [
280+
'meilisearch' => [
281+
'http_client' => 'acme.http_client',
282+
],
283+
],
284+
'expectedConfig' => [
285+
'url' => 'http://localhost:7700',
286+
'prefix' => null,
287+
'indices' => [],
288+
'nbResults' => 20,
289+
'batchSize' => 500,
290+
'serializer' => 'serializer',
291+
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
292+
'http_client' => 'acme.http_client',
268293
],
269294
];
270295
}

0 commit comments

Comments
 (0)