Skip to content

Commit

Permalink
Merge #359
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
meili-bors[bot] and norkunas authored Oct 17, 2024
2 parents a420c1f + 2c3080e commit a4797cf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
</service>

<service id="meilisearch.client" class="Meilisearch\Client" public="true" lazy="true">
<argument /><!-- url -->
<argument /><!-- api key -->
<argument type="service" id="psr18.http_client" on-invalid="ignore" /><!-- http client -->
<argument type="abstract">url defined in MeilisearchExtension</argument>
<argument type="abstract">api key defined in MeilisearchExtension</argument>
<argument type="abstract">http client defined in MeilisearchExtension</argument>
<argument>null</argument><!-- request factory -->
<argument /><!-- client agents -->
<argument type="abstract">client agents defined in MeilisearchExtension</argument>
<argument>null</argument><!-- stream factory -->
</service>
<service id="search.client" alias="meilisearch.client" public="true">
Expand Down
3 changes: 3 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('serializer')
->defaultValue('serializer')
->end()
->scalarNode('http_client')
->defaultValue('psr18.http_client')
->end()
->arrayNode('indices')
->arrayPrototype()
->children()
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/MeilisearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Meilisearch\Bundle\Services\UnixTimestampNormalizer;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -50,6 +51,7 @@ public function load(array $configs, ContainerBuilder $container): void
$container->findDefinition('meilisearch.client')
->replaceArgument(0, $config['url'])
->replaceArgument(1, $config['api_key'])
->replaceArgument(2, new Reference($config['http_client'], ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
->replaceArgument(4, [MeilisearchBundle::qualifiedVersion()]);

$container->findDefinition('meilisearch.service')
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static function dataTestConfigurationTree(): iterable
'batchSize' => 500,
'serializer' => 'serializer',
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
'http_client' => 'psr18.http_client',
'indices' => [],
],
];
Expand All @@ -59,6 +60,7 @@ public static function dataTestConfigurationTree(): iterable
'batchSize' => 100,
'serializer' => 'serializer',
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
'http_client' => 'psr18.http_client',
'indices' => [],
],
];
Expand All @@ -85,6 +87,7 @@ public static function dataTestConfigurationTree(): iterable
'batchSize' => 500,
'serializer' => 'serializer',
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
'http_client' => 'psr18.http_client',
'indices' => [
0 => [
'name' => 'posts',
Expand Down Expand Up @@ -156,6 +159,7 @@ public static function dataTestConfigurationTree(): iterable
'batchSize' => 500,
'serializer' => 'serializer',
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
'http_client' => 'psr18.http_client',
],
];

Expand Down Expand Up @@ -191,6 +195,7 @@ public static function dataTestConfigurationTree(): iterable
'batchSize' => 500,
'serializer' => 'serializer',
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
'http_client' => 'psr18.http_client',
],
];

Expand Down Expand Up @@ -228,6 +233,7 @@ public static function dataTestConfigurationTree(): iterable
'batchSize' => 500,
'serializer' => 'serializer',
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
'http_client' => 'psr18.http_client',
],
];

Expand Down Expand Up @@ -265,6 +271,25 @@ public static function dataTestConfigurationTree(): iterable
'batchSize' => 500,
'serializer' => 'serializer',
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
'http_client' => 'psr18.http_client',
],
];

yield 'custom http client' => [
'inputConfig' => [
'meilisearch' => [
'http_client' => 'acme.http_client',
],
],
'expectedConfig' => [
'url' => 'http://localhost:7700',
'prefix' => null,
'indices' => [],
'nbResults' => 20,
'batchSize' => 500,
'serializer' => 'serializer',
'doctrineSubscribedEvents' => ['postPersist', 'postUpdate', 'preRemove'],
'http_client' => 'acme.http_client',
],
];
}
Expand Down

0 comments on commit a4797cf

Please sign in to comment.