From 2c3934bc717d8cb6ff22c5c0a7745dfe565fa8b2 Mon Sep 17 00:00:00 2001 From: muratbinerbay Date: Fri, 7 Jun 2024 15:09:27 +0200 Subject: [PATCH] [Improvement]: Add possibility to pass metadata to gotenberg-chromium processor (#66) * Pass metadata to gotenberg-chromium processor * Add backwards compatibility layer for gotenberg-php v1 * Check the existence of metadata only once Co-authored-by: Sebastian Blank * Just use formValue to support both v1 and v2 Co-authored-by: JiaJia Ji * Remove empty new line * Revert "Remove empty new line" This reverts commit e057251794f765c64f465d8cf61fabdfa1263ab6. * Revert "Just use formValue to support both v1 and v2" This reverts commit 437b18f2a4d28be00baee95fa6d0e9f648cfb458. * Update minimum versions for gotenberg/gotenberg-php dependency * Ignore phpstan error because code should not be reachable when formValue is protected * Try checking formValue with is_callable Co-authored-by: Sebastian Blank * Pass metadata to gotenberg-chromium on version > 2.2 --------- Co-authored-by: Sebastian Blank Co-authored-by: JiaJia Ji --- composer.json | 2 +- src/Processor/Gotenberg.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9666e65..e2ab1be 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require-dev": { "phpstan/phpstan": "^1.10.5", "phpstan/phpstan-symfony": "^1.2.20", - "gotenberg/gotenberg-php": "^1.0 || ^2.0", + "gotenberg/gotenberg-php": "^1.1.8 || ^2.2", "chrome-php/chrome": "^1.8", "codeception/codeception": "^5.0.3", "codeception/module-symfony": "^3.1.0", diff --git a/src/Processor/Gotenberg.php b/src/Processor/Gotenberg.php index 61c121a..f55e9c4 100644 --- a/src/Processor/Gotenberg.php +++ b/src/Processor/Gotenberg.php @@ -166,6 +166,11 @@ public function getPdfFromString(string $html, array $params = [], bool $returnF $chromium->extraHttpHeaders($params['extraHttpHeaders']); } + // metadata is only passed on gotenberg-php > 2.2 + if (isset($params['metadata']) && method_exists($chromium, 'metadata')) { + $chromium->metadata($params['metadata']); + } + $request = $chromium->outputFilename($tempFileName)->html(Stream::string('processor.html', $html)); if ($returnFilePath) {