From b26c12f927155cce257478e462ee99c144564144 Mon Sep 17 00:00:00 2001 From: Maelan LE BORGNE Date: Thu, 3 Oct 2024 16:01:37 +0200 Subject: [PATCH] cleanup after review --- src/Builder/AsyncBuilderTrait.php | 9 ++++++++- src/Builder/Pdf/AbstractChromiumPdfBuilder.php | 1 - src/DependencyInjection/Configuration.php | 6 +++--- src/DependencyInjection/SensiolabsGotenbergExtension.php | 6 +++--- .../SensiolabsGotenbergExtensionTest.php | 1 - 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Builder/AsyncBuilderTrait.php b/src/Builder/AsyncBuilderTrait.php index 9d1c534f..20cf2574 100644 --- a/src/Builder/AsyncBuilderTrait.php +++ b/src/Builder/AsyncBuilderTrait.php @@ -14,6 +14,9 @@ trait AsyncBuilderTrait * @var array */ private array $webhookExtraHeaders = []; + /** + * @var \Closure(): string + */ private \Closure $operationIdGenerator; private WebhookConfigurationRegistryInterface $webhookConfigurationRegistry; @@ -32,7 +35,8 @@ public function generateAsync(): string 'Gotenberg-Webhook-Extra-Http-Headers' => json_encode($this->webhookExtraHeaders, \JSON_THROW_ON_ERROR), ]; if (null !== $this->fileName) { - $headers['Gotenberg-Output-Filename'] = basename($this->fileName, '.pdf'); + // Gotenberg will add the extension to the file name (e.g. filename : "file.pdf" => generated file : "file.pdf.pdf"). + $headers['Gotenberg-Output-Filename'] = $this->fileName; } $this->client->call($this->getEndpoint(), $this->getMultipartFormData(), $headers); @@ -71,6 +75,9 @@ public function webhookExtraHeaders(array $extraHeaders): static return $this; } + /** + * @param \Closure(): string $operationIdGenerator + */ public function operationIdGenerator(\Closure $operationIdGenerator): static { $this->operationIdGenerator = $operationIdGenerator; diff --git a/src/Builder/Pdf/AbstractChromiumPdfBuilder.php b/src/Builder/Pdf/AbstractChromiumPdfBuilder.php index 5dccd7b1..68f6cb4a 100644 --- a/src/Builder/Pdf/AbstractChromiumPdfBuilder.php +++ b/src/Builder/Pdf/AbstractChromiumPdfBuilder.php @@ -588,7 +588,6 @@ protected function addConfiguration(string $configurationName, mixed $value): vo 'fail_on_console_exceptions' => $this->failOnConsoleExceptions($value), 'skip_network_idle_event' => $this->skipNetworkIdleEvent($value), 'metadata' => $this->metadata($value), - 'webhook' => null, default => throw new InvalidBuilderConfiguration(sprintf('Invalid option "%s": no method does not exist in class "%s" to configured it.', $configurationName, static::class)), }; } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 59cd609a..c05b8e24 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -673,17 +673,17 @@ private function addNamedWebhookDefinition(): NodeDefinition ->children() ->scalarNode('name') ->validate() - ->ifTrue(static function ($option) { + ->ifTrue(static function (mixed $option): bool { return !\is_string($option); }) - ->thenInvalid('Invalid header name %s') + ->thenInvalid('Invalid webhook configuration name %s') ->end() ->end() ->append($this->addWebhookConfigurationNode('success')) ->append($this->addWebhookConfigurationNode('error')) ->end() ->validate() - ->ifTrue(static function ($option): bool { + ->ifTrue(static function (mixed $option): bool { return !isset($option['success']); }) ->thenInvalid('Invalid webhook configuration : At least a "success" key is required.') diff --git a/src/DependencyInjection/SensiolabsGotenbergExtension.php b/src/DependencyInjection/SensiolabsGotenbergExtension.php index 8790e8aa..e6db866d 100644 --- a/src/DependencyInjection/SensiolabsGotenbergExtension.php +++ b/src/DependencyInjection/SensiolabsGotenbergExtension.php @@ -100,9 +100,9 @@ public function load(array $configs, ContainerBuilder $container): void */ private function cleanUserOptions(array $userConfigurations): array { - return array_filter($userConfigurations, static function ($config): bool { - return null !== $config; - }); + return array_filter($userConfigurations, static function ($config, $configName): bool { + return null !== $config && 'webhook' !== $configName; + }, \ARRAY_FILTER_USE_BOTH); } /** diff --git a/tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php b/tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php index 135c8f40..eac569be 100644 --- a/tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php +++ b/tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php @@ -65,7 +65,6 @@ public function testGotenbergConfiguredWithValidConfig(): void 'skip_network_idle_event' => true, 'pdf_format' => 'PDF/A-1b', 'pdf_universal_access' => true, - 'webhook' => ['config_name' => 'bar'], ], 'url' => [ 'paper_width' => 21,