Skip to content

Commit

Permalink
[FEATURE] Add http_Client as config (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neirda24 authored Apr 16, 2024
1 parent 2fe18f7 commit 71a9a43
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
$services->set('sensiolabs_gotenberg.client', GotenbergClient::class)
->args([
abstract_arg('base_uri to gotenberg API'),
service(HttpClientInterface::class),
service('sensiolabs_gotenberg.http_client'),
])
->alias(GotenbergClientInterface::class, 'sensiolabs_gotenberg.client');

Expand Down
1 change: 1 addition & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The default configuration for the bundle looks like :
sensiolabs_gotenberg:
base_uri: 'http://localhost:3000'
base_directory: '%kernel.project_dir%'
http_client: null # Defaults to 'http_client'
default_options:
html:
paper_width: null # 8.5
Expand Down
7 changes: 6 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class Configuration implements ConfigurationInterface
{
Expand All @@ -26,8 +27,12 @@ public function getConfigTreeBuilder(): TreeBuilder
->info('Base directory will be used for assets, files, markdown')
->defaultValue('%kernel.project_dir%')
->end()
->scalarNode('http_client')
->info('HTTP Client reference to use. Defaults to "http_client".')
->defaultValue('http_client')
->end()
->arrayNode('default_options')
->addDefaultsIfNotSet()
->addDefaultsIfNotSet()
->append($this->addHtmlNode())
->append($this->addUrlNode())
->append($this->addMarkdownNode())
Expand Down
5 changes: 4 additions & 1 deletion src/DependencyInjection/SensiolabsGotenbergExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Sensiolabs\GotenbergBundle\Builder\PdfBuilderInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand All @@ -17,13 +18,15 @@ public function load(array $configs, ContainerBuilder $container): void

$configuration = new Configuration();

/** @var array{base_uri: string, base_directory: string, default_options: array{html: array<string, mixed>, url: array<string, mixed>, markdown: array<string, mixed>, office: array<string, mixed>}} $config */
/** @var array{base_uri: string, http_client: string|null, base_directory: string, default_options: array{html: array<string, mixed>, url: array<string, mixed>, markdown: array<string, mixed>, office: array<string, mixed>}} $config */
$config = $this->processConfiguration($configuration, $configs);

$container->registerForAutoconfiguration(PdfBuilderInterface::class)
->addTag('sensiolabs_gotenberg.builder')
;

$container->setAlias('sensiolabs_gotenberg.http_client', new Alias($config['http_client'] ?? 'http_client', false));

$definition = $container->getDefinition('sensiolabs_gotenberg.client');
$definition->replaceArgument(0, $config['base_uri']);

Expand Down
1 change: 1 addition & 0 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private static function getBundleDefaultConfig(): array
return [
'base_uri' => 'http://localhost:3000',
'base_directory' => '%kernel.project_dir%',
'http_client' => 'http_client',
'default_options' => [
'html' => [
'paper_width' => null,
Expand Down

0 comments on commit 71a9a43

Please sign in to comment.