Skip to content

Commit

Permalink
Allow to configure custom http client
Browse files Browse the repository at this point in the history
  • Loading branch information
norkunas committed Oct 16, 2024
1 parent a420c1f commit dd8b48a
Show file tree
Hide file tree
Showing 3 changed files with 9 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

0 comments on commit dd8b48a

Please sign in to comment.