From 7ae906e097d76895edd4c75bf81ab35e200333d4 Mon Sep 17 00:00:00 2001 From: "hubert.lenoir" Date: Thu, 3 Oct 2024 09:26:42 +0200 Subject: [PATCH 01/30] chore: prepare 1.x Co-authored-by: Neirda24 Co-authored-by: StevenRenaux --- .gitattributes | 2 + .php-cs-fixer.dist.php | 1 + .phpstorm.meta.php | 9 +- README.md | 3 +- bin/config.dump-reference | 23 + composer-dependency-analyser.php | 1 + composer.json | 3 + config/builder.php | 37 + config/builder_pdf.php | 93 +-- config/builder_screenshot.php | 46 +- config/debug.php | 11 +- docs/pdf/builders_api/ConvertPdfBuilder.md | 37 +- docs/pdf/builders_api/FlattenPdfBuilder.md | 27 + docs/pdf/builders_api/HtmlPdfBuilder.md | 260 +++--- .../pdf/builders_api/LibreOfficePdfBuilder.md | 73 +- docs/pdf/builders_api/MarkdownPdfBuilder.md | 267 +++--- docs/pdf/builders_api/MergePdfBuilder.md | 48 +- docs/pdf/builders_api/SplitPdfBuilder.md | 64 +- docs/pdf/builders_api/UrlPdfBuilder.md | 262 +++--- docs/pdf/flatten-builder.md | 36 + docs/pdf/merge-builder.md | 29 + docs/pdf/office-builder.md | 70 +- docs/pdf/split-builder.md | 31 +- .../builders_api/HtmlScreenshotBuilder.md | 164 ++-- .../builders_api/MarkdownScreenshotBuilder.md | 169 ++-- .../builders_api/UrlScreenshotBuilder.md | 166 ++-- phpstan.dist.neon | 64 +- phpunit.xml | 4 +- src/Builder/AbstractBuilder.php | 156 ++++ src/Builder/AsyncBuilderInterface.php | 15 - src/Builder/AsyncBuilderTrait.php | 136 ---- src/Builder/Attributes/ExposeSemantic.php | 14 + .../Attributes/NormalizeGotenbergPayload.php | 11 + src/Builder/Attributes/SemanticNode.php | 12 + src/Builder/Behaviors/Chromium/AssetTrait.php | 57 ++ .../Behaviors/Chromium/ContentTrait.php | 130 +++ .../Behaviors/Chromium/CookieTrait.php | 125 +++ .../Chromium/CustomHttpHeadersTrait.php | 80 ++ .../Chromium/EmulatedMediaTypeTrait.php | 35 + .../Behaviors/Chromium/FailOnTrait.php | 84 ++ .../Chromium/PdfPagePropertiesTrait.php | 247 ++++++ .../Chromium/PerformanceModeTrait.php | 31 + .../ScreenshotPagePropertiesTrait.php | 112 +++ .../Chromium/WaitBeforeRenderingTrait.php | 47 ++ src/Builder/Behaviors/ChromiumPdfTrait.php | 21 + .../Behaviors/ChromiumScreenshotTrait.php | 18 + .../AssetBaseDirFormatterAwareTrait.php | 15 + .../Dependencies/DependencyAwareTrait.php | 10 + .../Dependencies/LoggerAwareTrait.php | 21 + .../Dependencies/RequestAwareTrait.php | 23 + .../Behaviors/Dependencies/TwigAwareTrait.php | 22 + .../Dependencies/UrlGeneratorAwareTrait.php | 22 + src/Builder/Behaviors/DownloadFromTrait.php | 58 ++ src/Builder/Behaviors/FlattenTrait.php | 34 + .../LibreOffice/PagePropertiesTrait.php | 318 ++++++++ src/Builder/Behaviors/LibreOfficeTrait.php | 14 + src/Builder/Behaviors/MetadataTrait.php | 81 ++ src/Builder/Behaviors/PdfFormatTrait.php | 52 ++ src/Builder/Behaviors/SplitTrait.php | 66 ++ src/Builder/Behaviors/WebhookTrait.php | 193 +++++ src/Builder/BodyBag.php | 41 + src/Builder/BuilderAssetInterface.php | 8 + src/Builder/BuilderAsyncInterface.php | 10 + src/Builder/BuilderFileInterface.php | 10 + src/Builder/BuilderInterface.php | 7 + src/Builder/CookieAwareTrait.php | 150 ---- src/Builder/DefaultBuilderTrait.php | 226 ------ src/Builder/DownloadFromTrait.php | 54 -- src/Builder/GotenbergFileResult.php | 85 -- src/Builder/HeadersBag.php | 41 + src/Builder/Payload.php | 59 ++ .../Pdf/AbstractChromiumPdfBuilder.php | 764 ----------------- src/Builder/Pdf/AbstractPdfBuilder.php | 43 - src/Builder/Pdf/ConvertPdfBuilder.php | 98 +-- src/Builder/Pdf/FlattenPdfBuilder.php | 64 ++ src/Builder/Pdf/HtmlPdfBuilder.php | 45 +- src/Builder/Pdf/LibreOfficePdfBuilder.php | 415 +--------- src/Builder/Pdf/MarkdownPdfBuilder.php | 86 +- src/Builder/Pdf/MergePdfBuilder.php | 119 +-- src/Builder/Pdf/PdfBuilderInterface.php | 13 - src/Builder/Pdf/SplitPdfBuilder.php | 125 +-- src/Builder/Pdf/UrlPdfBuilder.php | 97 +-- .../Result/AbstractGotenbergResult.php | 34 + src/Builder/Result/GotenbergAsyncResult.php | 23 + src/Builder/Result/GotenbergFileResult.php | 113 +++ .../AbstractChromiumScreenshotBuilder.php | 463 ----------- .../Screenshot/AbstractScreenshotBuilder.php | 40 - .../Screenshot/HtmlScreenshotBuilder.php | 45 +- .../Screenshot/MarkdownScreenshotBuilder.php | 86 +- .../Screenshot/ScreenshotBuilderInterface.php | 13 - .../Screenshot/UrlScreenshotBuilder.php | 96 +-- src/Builder/Util/NormalizerFactory.php | 166 ++++ src/Builder/Util/ValidatorFactory.php | 89 ++ src/Builder/ValueObject/RenderedPart.php | 14 + src/Client/GotenbergClient.php | 53 +- src/Client/GotenbergClientInterface.php | 12 +- src/Client/GotenbergResponse.php | 55 -- src/Configurator/BuilderConfigurator.php | 41 + src/DataCollector/GotenbergDataCollector.php | 30 +- ...blePdfBuilder.php => TraceableBuilder.php} | 42 +- .../Builder/TraceableScreenshotBuilder.php | 113 --- src/Debug/Client/TraceableGotenbergClient.php | 45 + src/Debug/TraceableGotenbergPdf.php | 94 ++- src/Debug/TraceableGotenbergScreenshot.php | 36 +- src/DependencyInjection/BuilderStack.php | 138 ++++ .../CompilerPass/GotenbergPass.php | 54 +- src/DependencyInjection/Configuration.php | 768 +----------------- .../SensiolabsGotenbergExtension.php | 235 +++--- src/Enumeration/NodeType.php | 14 + .../ProcessBuilderOnControllerResponse.php | 2 +- src/GotenbergPdf.php | 31 +- src/GotenbergPdfInterface.php | 32 +- src/GotenbergScreenshot.php | 14 +- src/GotenbergScreenshotInterface.php | 14 +- src/NodeBuilder/ArrayNodeBuilder.php | 57 ++ src/NodeBuilder/BooleanNodeBuilder.php | 31 + src/NodeBuilder/EnumNodeBuilder.php | 75 ++ src/NodeBuilder/FloatNodeBuilder.php | 24 + src/NodeBuilder/IntegerNodeBuilder.php | 47 ++ src/NodeBuilder/MetadataNodeBuilder.php | 22 + src/NodeBuilder/NativeEnumNodeBuilder.php | 33 + src/NodeBuilder/NodeBuilder.php | 16 + src/NodeBuilder/NodeBuilderInterface.php | 12 + src/NodeBuilder/ScalarNodeBuilder.php | 49 ++ src/NodeBuilder/UnitNodeBuilder.php | 13 + src/NodeBuilder/VariableNodeBuilder.php | 19 + src/NodeBuilder/WebhookNodeBuilder.php | 31 + src/SensiolabsGotenbergBundle.php | 34 +- src/Twig/GotenbergRuntime.php | 16 +- src/Webhook/WebhookConfigurationRegistry.php | 99 --- .../WebhookConfigurationRegistryInterface.php | 33 - .../Collector/sensiolabs_gotenberg.html.twig | 57 +- tests/Builder/AbstractBuilderTestCase.php | 78 -- tests/Builder/AsyncBuilderTraitTest.php | 224 ----- tests/Builder/Behaviors/BehaviorTrait.php | 41 + .../Behaviors/Chromium/AssetTestCaseTrait.php | 70 ++ .../Chromium/CookieTestCaseTrait.php | 178 ++++ .../CustomHttpHeadersTestCaseTrait.php | 72 ++ .../EmulatedMediaTypeTestCaseTrait.php | 28 + .../Chromium/FailOnTestCaseTrait.php | 57 ++ .../PdfPagePropertiesTestCaseTrait.php | 278 +++++++ .../Chromium/PerformanceModeTestCaseTrait.php | 27 + .../ScreenshotPagePropertiesTestCaseTrait.php | 88 ++ .../WaitBeforeRenderingTestCaseTrait.php | 37 + .../Behaviors/ChromiumPdfTestCaseTrait.php | 50 ++ .../ChromiumScreenshotTestCaseTrait.php | 38 + .../Behaviors/DownloadFromTestCaseTrait.php | 50 ++ .../Behaviors/FlattenTestCaseTrait.php | 28 + .../PagePropertiesTestCaseTrait.php | 270 ++++++ .../Behaviors/LibreOfficeTestCaseTrait.php | 32 + .../Behaviors/MetadataTestCaseTrait.php | 47 ++ .../Behaviors/PdfFormatTestCaseTrait.php | 51 ++ .../Builder/Behaviors/SplitTestCaseTrait.php | 61 ++ .../Behaviors/WebhookTestCaseTrait.php | 276 +++++++ tests/Builder/DefaultBuilderTraitTest.php | 142 ---- tests/Builder/GotenbergBuilderTestCase.php | 146 ++++ tests/Builder/GotenbergClientAsserter.php | 96 +++ tests/Builder/GotenbergFileResultTest.php | 68 -- .../Pdf/AbstractChromiumPdfBuilderTest.php | 472 ----------- tests/Builder/Pdf/AbstractPdfBuilderTest.php | 103 --- tests/Builder/Pdf/ConvertPdfBuilderTest.php | 152 ++-- tests/Builder/Pdf/FlattenPdfBuilderTest.php | 72 ++ tests/Builder/Pdf/HtmlPdfBuilderTest.php | 237 ++++-- .../Builder/Pdf/LibreOfficePdfBuilderTest.php | 245 ++---- tests/Builder/Pdf/MarkdownPdfBuilderTest.php | 152 +++- tests/Builder/Pdf/MergePdfBuilderTest.php | 158 ++-- tests/Builder/Pdf/SplitPdfBuilderTest.php | 219 +++-- tests/Builder/Pdf/UrlPdfBuilderTest.php | 182 ++--- .../AbstractChromiumScreenshotBuilderTest.php | 101 --- .../AbstractScreenshotBuilderTest.php | 101 --- .../Screenshot/HtmlScreenshotBuilderTest.php | 126 ++- .../MarkdownScreenshotBuilderTest.php | 198 +++-- .../Screenshot/UrlScreenshotBuilderTest.php | 149 ++-- tests/Client/GotenbergClientTest.php | 38 +- .../CompilerPass/GotenbergPassTest.php | 58 +- .../DependencyInjection/ConfigurationTest.php | 395 +++++++-- .../SensiolabsGotenbergExtensionTest.php | 557 ++++++++----- .../WebhookConfigurationRegistryTest.php | 114 --- tests/Enumeration/EmulatedMediaTypeTest.php | 20 + tests/Enumeration/ImageResolutionDPITest.php | 20 + tests/Enumeration/NodeTypeTest.php | 20 + tests/Enumeration/PaperSizeTest.php | 23 +- tests/Enumeration/PartTest.php | 20 + tests/Enumeration/PdfFormatTest.php | 20 + tests/Enumeration/UnitTest.php | 2 - tests/Fixtures/assets/pdf/other_document.pdf | Bin 0 -> 13624 bytes tests/Fixtures/files/wrapper.html | 2 +- tests/Fixtures/templates/wrapper.html.twig | 13 + tests/Formatter/AssetBaseDirFormatterTest.php | 2 - tests/GotenbergPdfTest.php | 281 ++++--- tests/GotenbergScreenshotTest.php | 123 ++- tests/PHPStanRules/AlwaysUsedMethodRule.php | 16 + tests/Processor/ChainProcessorTest.php | 2 - tests/Processor/FileProcessorTest.php | 2 - tests/Processor/NullProcessorTest.php | 2 - tests/SensiolabsGotenbergBundleTest.php | 6 +- tests/Twig/GotenbergRuntimeTest.php | 80 +- 197 files changed, 9407 insertions(+), 8102 deletions(-) create mode 100755 bin/config.dump-reference create mode 100644 config/builder.php create mode 100644 docs/pdf/builders_api/FlattenPdfBuilder.md create mode 100644 docs/pdf/flatten-builder.md create mode 100644 src/Builder/AbstractBuilder.php delete mode 100644 src/Builder/AsyncBuilderInterface.php delete mode 100644 src/Builder/AsyncBuilderTrait.php create mode 100644 src/Builder/Attributes/ExposeSemantic.php create mode 100644 src/Builder/Attributes/NormalizeGotenbergPayload.php create mode 100644 src/Builder/Attributes/SemanticNode.php create mode 100644 src/Builder/Behaviors/Chromium/AssetTrait.php create mode 100644 src/Builder/Behaviors/Chromium/ContentTrait.php create mode 100644 src/Builder/Behaviors/Chromium/CookieTrait.php create mode 100644 src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php create mode 100644 src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php create mode 100644 src/Builder/Behaviors/Chromium/FailOnTrait.php create mode 100644 src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php create mode 100644 src/Builder/Behaviors/Chromium/PerformanceModeTrait.php create mode 100644 src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php create mode 100644 src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php create mode 100644 src/Builder/Behaviors/ChromiumPdfTrait.php create mode 100644 src/Builder/Behaviors/ChromiumScreenshotTrait.php create mode 100644 src/Builder/Behaviors/Dependencies/AssetBaseDirFormatterAwareTrait.php create mode 100644 src/Builder/Behaviors/Dependencies/DependencyAwareTrait.php create mode 100644 src/Builder/Behaviors/Dependencies/LoggerAwareTrait.php create mode 100644 src/Builder/Behaviors/Dependencies/RequestAwareTrait.php create mode 100644 src/Builder/Behaviors/Dependencies/TwigAwareTrait.php create mode 100644 src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php create mode 100644 src/Builder/Behaviors/DownloadFromTrait.php create mode 100644 src/Builder/Behaviors/FlattenTrait.php create mode 100644 src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php create mode 100644 src/Builder/Behaviors/LibreOfficeTrait.php create mode 100644 src/Builder/Behaviors/MetadataTrait.php create mode 100644 src/Builder/Behaviors/PdfFormatTrait.php create mode 100644 src/Builder/Behaviors/SplitTrait.php create mode 100644 src/Builder/Behaviors/WebhookTrait.php create mode 100644 src/Builder/BodyBag.php create mode 100644 src/Builder/BuilderAssetInterface.php create mode 100644 src/Builder/BuilderAsyncInterface.php create mode 100644 src/Builder/BuilderFileInterface.php create mode 100644 src/Builder/BuilderInterface.php delete mode 100644 src/Builder/CookieAwareTrait.php delete mode 100644 src/Builder/DefaultBuilderTrait.php delete mode 100644 src/Builder/DownloadFromTrait.php delete mode 100644 src/Builder/GotenbergFileResult.php create mode 100644 src/Builder/HeadersBag.php create mode 100644 src/Builder/Payload.php delete mode 100644 src/Builder/Pdf/AbstractChromiumPdfBuilder.php delete mode 100644 src/Builder/Pdf/AbstractPdfBuilder.php create mode 100644 src/Builder/Pdf/FlattenPdfBuilder.php delete mode 100644 src/Builder/Pdf/PdfBuilderInterface.php create mode 100644 src/Builder/Result/AbstractGotenbergResult.php create mode 100644 src/Builder/Result/GotenbergAsyncResult.php create mode 100644 src/Builder/Result/GotenbergFileResult.php delete mode 100644 src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php delete mode 100644 src/Builder/Screenshot/AbstractScreenshotBuilder.php delete mode 100644 src/Builder/Screenshot/ScreenshotBuilderInterface.php create mode 100644 src/Builder/Util/NormalizerFactory.php create mode 100644 src/Builder/Util/ValidatorFactory.php create mode 100644 src/Builder/ValueObject/RenderedPart.php delete mode 100644 src/Client/GotenbergResponse.php create mode 100644 src/Configurator/BuilderConfigurator.php rename src/Debug/Builder/{TraceablePdfBuilder.php => TraceableBuilder.php} (63%) delete mode 100644 src/Debug/Builder/TraceableScreenshotBuilder.php create mode 100644 src/Debug/Client/TraceableGotenbergClient.php create mode 100644 src/DependencyInjection/BuilderStack.php create mode 100644 src/Enumeration/NodeType.php create mode 100644 src/NodeBuilder/ArrayNodeBuilder.php create mode 100644 src/NodeBuilder/BooleanNodeBuilder.php create mode 100644 src/NodeBuilder/EnumNodeBuilder.php create mode 100644 src/NodeBuilder/FloatNodeBuilder.php create mode 100644 src/NodeBuilder/IntegerNodeBuilder.php create mode 100644 src/NodeBuilder/MetadataNodeBuilder.php create mode 100644 src/NodeBuilder/NativeEnumNodeBuilder.php create mode 100644 src/NodeBuilder/NodeBuilder.php create mode 100644 src/NodeBuilder/NodeBuilderInterface.php create mode 100644 src/NodeBuilder/ScalarNodeBuilder.php create mode 100644 src/NodeBuilder/UnitNodeBuilder.php create mode 100644 src/NodeBuilder/VariableNodeBuilder.php create mode 100644 src/NodeBuilder/WebhookNodeBuilder.php delete mode 100644 src/Webhook/WebhookConfigurationRegistry.php delete mode 100644 src/Webhook/WebhookConfigurationRegistryInterface.php delete mode 100644 tests/Builder/AbstractBuilderTestCase.php delete mode 100644 tests/Builder/AsyncBuilderTraitTest.php create mode 100644 tests/Builder/Behaviors/BehaviorTrait.php create mode 100644 tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/Chromium/CookieTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/Chromium/CustomHttpHeadersTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/Chromium/EmulatedMediaTypeTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/Chromium/FailOnTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/Chromium/PdfPagePropertiesTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/Chromium/PerformanceModeTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/Chromium/WaitBeforeRenderingTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/ChromiumPdfTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/ChromiumScreenshotTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/DownloadFromTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/FlattenTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/LibreOffice/PagePropertiesTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/LibreOfficeTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/MetadataTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/PdfFormatTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/SplitTestCaseTrait.php create mode 100644 tests/Builder/Behaviors/WebhookTestCaseTrait.php delete mode 100644 tests/Builder/DefaultBuilderTraitTest.php create mode 100644 tests/Builder/GotenbergBuilderTestCase.php create mode 100644 tests/Builder/GotenbergClientAsserter.php delete mode 100644 tests/Builder/GotenbergFileResultTest.php delete mode 100644 tests/Builder/Pdf/AbstractChromiumPdfBuilderTest.php delete mode 100644 tests/Builder/Pdf/AbstractPdfBuilderTest.php create mode 100644 tests/Builder/Pdf/FlattenPdfBuilderTest.php delete mode 100644 tests/Builder/Screenshot/AbstractChromiumScreenshotBuilderTest.php delete mode 100644 tests/Builder/Screenshot/AbstractScreenshotBuilderTest.php delete mode 100644 tests/DependencyInjection/WebhookConfigurationRegistryTest.php create mode 100644 tests/Enumeration/EmulatedMediaTypeTest.php create mode 100644 tests/Enumeration/ImageResolutionDPITest.php create mode 100644 tests/Enumeration/NodeTypeTest.php create mode 100644 tests/Enumeration/PartTest.php create mode 100644 tests/Enumeration/PdfFormatTest.php create mode 100644 tests/Fixtures/assets/pdf/other_document.pdf create mode 100644 tests/Fixtures/templates/wrapper.html.twig create mode 100644 tests/PHPStanRules/AlwaysUsedMethodRule.php diff --git a/.gitattributes b/.gitattributes index 90063091..f23b77ce 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,8 @@ +/bin export-ignore /docs export-ignore /tests export-ignore /.php-cs-fixer.dist.php export-ignore +/composer-dependency-analyser.php export-ignore /phpstan.neon export-ignore /phpunit.xml export-ignore /.git* export-ignore diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index a9c4fa75..853175d1 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,6 +2,7 @@ $finder = (new PhpCsFixer\Finder()) ->in([ + __DIR__ . '/bin', __DIR__ . '/config', __DIR__ . '/docs', __DIR__ . '/src', diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index ab5c4a24..f1c3bf5a 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -2,14 +2,7 @@ namespace PHPSTORM_META { expectedArguments( - \Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder::fileName(), - 1, - \Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_INLINE, - \Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_ATTACHMENT, - ); - - expectedArguments( - \Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractScreenshotBuilder::fileName(), + \Sensiolabs\GotenbergBundle\Builder\AbstractBuilder::fileName(), 1, \Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_INLINE, \Symfony\Component\HttpFoundation\HeaderUtils::DISPOSITION_ATTACHMENT, diff --git a/README.md b/README.md index a6466577..53e5a71f 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,8 @@ class YourController 6. [Merge Builder](./docs/pdf/merge-builder.md) 7. [Convert Builder](./docs/pdf/convert-builder.md) 8. [Split Builder](./docs/pdf/split-builder.md) -9. [PDF customization](./docs/pdf/customization.md) (available for every builder except LibreOffice, Merge and Split) +9. [Flatten Builder](./docs/pdf/flatten-builder.md) +10. [PDF customization](./docs/pdf/customization.md) (available for HTML, Markdown and Url builder) #### Screenshot diff --git a/bin/config.dump-reference b/bin/config.dump-reference new file mode 100755 index 00000000..aca74b21 --- /dev/null +++ b/bin/config.dump-reference @@ -0,0 +1,23 @@ +#!/usr/bin/env php +registerExtension($gotenbergBundle->getContainerExtension()); + +$gotenbergBundle->build($containerBuilder); + +/** @var SensiolabsGotenbergExtension $gotenbergExtension */ +$gotenbergExtension = $containerBuilder->getExtension('sensiolabs_gotenberg'); + +echo $yamlDumper->dump($gotenbergExtension->getConfiguration([], $containerBuilder)); diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php index ac1f0b48..4c7fe6a0 100644 --- a/composer-dependency-analyser.php +++ b/composer-dependency-analyser.php @@ -8,6 +8,7 @@ $config = new Configuration(); return $config + ->addPathToScan(__DIR__.'/bin', isDev: true) ->addPathToScan(__DIR__.'/src', isDev: false) ->addPathToScan(__DIR__.'/src/DataCollector', isDev: true) ->addPathToScan(__DIR__.'/src/Debug', isDev: true) diff --git a/composer.json b/composer.json index 60eab4f1..b90ee303 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ ], "require": { "php": ">=8.1", + "ext-json": "*", "psr/container": "^2.0", "psr/log": "^3.0", "symfony/config": "^6.4 || ^7.0", @@ -49,6 +50,7 @@ "symfony/stopwatch": "^6.4 || ^7.0", "symfony/twig-bundle": "^6.4 || ^7.0", "symfony/var-dumper": "^6.4 || ^7.0", + "symfony/yaml": "^6.4 || ^7.0", "twig/twig": "^3.14" }, "config": { @@ -59,6 +61,7 @@ }, "suggest": { "symfony/monolog-bundle": "Enables logging througout the generating process.", + "symfony/routing": "Allows you to use webhook to generate URL or route.", "symfony/twig-bundle": "Allows you to use Twig to render templates into PDF.", "monolog/monolog": "Enables logging througout the generating process.", "async-aws/s3": "Upload any file to aws s3 compatible endpoints supporting multi part upload without memory overhead.", diff --git a/config/builder.php b/config/builder.php new file mode 100644 index 00000000..7c14a660 --- /dev/null +++ b/config/builder.php @@ -0,0 +1,37 @@ +services(); + + $services->defaults() + ->tag('monolog.logger', ['channel' => 'sensiolabs_gotenberg']) + ; + + $services->set('.sensiolabs_gotenberg.abstract_builder', AbstractBuilder::class) + ->abstract() + ->args([ + service('sensiolabs_gotenberg.client'), + service_locator([ + 'asset_base_dir_formatter' => service('.sensiolabs_gotenberg.asset.base_dir_formatter'), + 'logger' => service('logger')->nullOnInvalid(), + 'request_stack' => service('request_stack')->nullOnInvalid(), + 'router' => service('router.default')->nullOnInvalid(), + 'twig' => service('twig')->nullOnInvalid(), + ]), + ]) + ; + + $services->set('sensiolabs_gotenberg.builder_configurator', BuilderConfigurator::class) + ->args([ + abstract_arg('Mapping of methods per builder for each configuration key'), + abstract_arg('Mapping of values per builder for each configuration key'), + ]) + ; +}; diff --git a/config/builder_pdf.php b/config/builder_pdf.php index b302dc0e..9bacf22d 100644 --- a/config/builder_pdf.php +++ b/config/builder_pdf.php @@ -1,6 +1,7 @@ tag('monolog.logger', ['channel' => 'sensiolabs_gotenberg']) ; + // HTML $services->set('.sensiolabs_gotenberg.pdf_builder.html', HtmlPdfBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - service('request_stack'), - service('twig')->nullOnInvalid(), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.pdf_builder') + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) ; + // URL $services->set('.sensiolabs_gotenberg.pdf_builder.url', UrlPdfBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - service('request_stack'), - service('twig')->nullOnInvalid(), - service('router')->nullOnInvalid(), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) ->call('setRequestContext', [service('.sensiolabs_gotenberg.request_context')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.pdf_builder') ; + // Markdown $services->set('.sensiolabs_gotenberg.pdf_builder.markdown', MarkdownPdfBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - service('request_stack'), - service('twig')->nullOnInvalid(), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.pdf_builder') + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) ; + // Office $services->set('.sensiolabs_gotenberg.pdf_builder.office', LibreOfficePdfBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.pdf_builder') + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) ; + // Merge $services->set('.sensiolabs_gotenberg.pdf_builder.merge', MergePdfBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.pdf_builder') + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) ; + // Convert $services->set('.sensiolabs_gotenberg.pdf_builder.convert', ConvertPdfBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.pdf_builder') + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) ; + // Split $services->set('.sensiolabs_gotenberg.pdf_builder.split', SplitPdfBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.pdf_builder') + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) + ; + + // Flatten + $services->set('.sensiolabs_gotenberg.pdf_builder.flatten', FlattenPdfBuilder::class) + ->share(false) + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) ; }; diff --git a/config/builder_screenshot.php b/config/builder_screenshot.php index 565d25ce..147b9b9e 100644 --- a/config/builder_screenshot.php +++ b/config/builder_screenshot.php @@ -13,44 +13,28 @@ ->tag('monolog.logger', ['channel' => 'sensiolabs_gotenberg']) ; + // HTML $services->set('.sensiolabs_gotenberg.screenshot_builder.html', HtmlScreenshotBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - service('request_stack'), - service('twig')->nullOnInvalid(), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.screenshot_builder') + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) ; - $services->set('.sensiolabs_gotenberg.screenshot_builder.url', UrlScreenshotBuilder::class) + // Markdown + $services->set('.sensiolabs_gotenberg.screenshot_builder.markdown', MarkdownScreenshotBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - service('request_stack'), - service('twig')->nullOnInvalid(), - service('router')->nullOnInvalid(), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) - ->call('setRequestContext', [service('.sensiolabs_gotenberg.request_context')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.screenshot_builder') + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) ; - $services->set('.sensiolabs_gotenberg.screenshot_builder.markdown', MarkdownScreenshotBuilder::class) + // URL + $services->set('.sensiolabs_gotenberg.screenshot_builder.url', UrlScreenshotBuilder::class) ->share(false) - ->args([ - service('sensiolabs_gotenberg.client'), - service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - service('.sensiolabs_gotenberg.webhook_configuration_registry'), - service('request_stack'), - service('twig')->nullOnInvalid(), - ]) - ->call('setLogger', [service('logger')->nullOnInvalid()]) - ->tag('sensiolabs_gotenberg.screenshot_builder') + ->parent('.sensiolabs_gotenberg.abstract_builder') + ->tag('sensiolabs_gotenberg.builder') + ->configurator(service('sensiolabs_gotenberg.builder_configurator')) + ->call('setRequestContext', [service('.sensiolabs_gotenberg.request_context')->nullOnInvalid()]) ; }; diff --git a/config/debug.php b/config/debug.php index 7eefb68b..d157a882 100644 --- a/config/debug.php +++ b/config/debug.php @@ -1,6 +1,7 @@ set('sensiolabs_gotenberg.traceable_client', TraceableGotenbergClient::class) + ->decorate('sensiolabs_gotenberg.client') + ->args([ + new Reference('.inner'), + ]) + ; + $services->set('sensiolabs_gotenberg.data_collector', GotenbergDataCollector::class) ->args([ service('sensiolabs_gotenberg.pdf'), service('sensiolabs_gotenberg.screenshot'), - tagged_locator('sensiolabs_gotenberg.pdf_builder'), + tagged_locator('sensiolabs_gotenberg.builder'), + service('sensiolabs_gotenberg.client'), abstract_arg('All default options will be set through the configuration.'), ]) ->tag('data_collector', ['template' => '@SensiolabsGotenberg/Collector/sensiolabs_gotenberg.html.twig', 'id' => 'sensiolabs_gotenberg']) diff --git a/docs/pdf/builders_api/ConvertPdfBuilder.md b/docs/pdf/builders_api/ConvertPdfBuilder.md index ef2021a8..390654b8 100644 --- a/docs/pdf/builders_api/ConvertPdfBuilder.md +++ b/docs/pdf/builders_api/ConvertPdfBuilder.md @@ -1,31 +1,24 @@ # ConvertPdfBuilder -### downloadFrom(array $downloadFrom) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) +> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) + +### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
### files(Stringable|string $paths) -### pdfFormat(Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +### getBodyBag() +### getHeadersBag() +### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. - -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. - -### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
- +Enable PDF for Universal Access for optimal accessibility. (default false). + +### type() +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) ### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - diff --git a/docs/pdf/builders_api/FlattenPdfBuilder.md b/docs/pdf/builders_api/FlattenPdfBuilder.md new file mode 100644 index 00000000..ea528bbc --- /dev/null +++ b/docs/pdf/builders_api/FlattenPdfBuilder.md @@ -0,0 +1,27 @@ +# FlattenPdfBuilder + + +* `files(string $paths)`: + +* `type()`: + +* `getBodyBag()`: + +* `getHeadersBag()`: + +* `downloadFrom(array $downloadFrom)`: +Sets download from to download each entry (file) in parallel (default None). +(URLs MUST return a Content-Disposition header with a filename parameter.). + +* `webhook(array $webhook)`: + +* `webhookUrl(string $url, ?string $method)`: + +* `webhookErrorUrl(string $url, ?string $method)`: + +* `webhookExtraHeaders(array $extraHttpHeaders)`: + +* `webhookRoute(string $route, array $parameters, ?string $method)`: + +* `webhookErrorRoute(string $route, array $parameters, ?string $method)`: + diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index 4789306b..584f0171 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -1,215 +1,179 @@ # HtmlPdfBuilder -### addMetadata(string $key, string $value) -The metadata to write. - -### downloadFrom(array $downloadFrom) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) - -### metadata(array $metadata) -Resets the metadata.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) -> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) - -### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) -Sets the PDF format of the resulting PDF. (default None).
- -### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false).
- -### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None).
- > [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) -### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None).
+### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) - -### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) - -### addAsset(string $path) -Adds a file, like an image, font, stylesheet, and so on.
- -### assets(string $paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files).
+> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. - -### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
- -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### addMetadata(string $key, string $value) +The metadata to write. -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+### assets(Stringable|string $paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. ### cookies(array $cookies) -Cookies to store in the Chromium cookie jar. (overrides any previous cookies).
+### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). -### forwardCookie(string $name) -### setCookie(string $key, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF. (Default false).
+### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### landscape(bool $bool) -Sets the paper orientation to landscape. (Default false).
+### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### marginBottom(float $bottom, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### marginLeft(float $left, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### marginRight(float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### marginTop(float $top, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### nativePageRanges(string $range) -Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages).
+### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### omitBackground(bool $bool) -Hides default white background and allows generating PDFs with
transparency. (Default false).
+### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### paperHeight(float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### paperSize(float $width, float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default paper size, in inches.

Examples of paper size (width x height):

Letter - 8.5 x 11 (default)
Legal - 8.5 x 14
Tabloid - 11 x 17
Ledger - 17 x 11
A0 - 33.1 x 46.8
A1 - 23.4 x 33.1
A2 - 16.54 x 23.4
A3 - 11.7 x 16.54
A4 - 8.27 x 11.7
A5 - 5.83 x 8.27
A6 - 4.13 x 5.83
+### footer(string $template, array $context) +### footerFile(string $path) +HTML file containing the footer. (default None). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### forwardCookie(string $name) +### generateDocumentOutline(bool $bool) +Define whether the document outline should be embedded into the PDF. -### paperStandardSize(Sensiolabs\GotenbergBundle\Enumeration\PaperSizeInterface $paperSize) -### paperWidth(float $width, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS. (Default false).
+### getBodyBag() +### getHeadersBag() +### header(string $template, array $context) +### headerFile(string $path) +HTML file containing the header. (default None). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### landscape(bool $bool) +Set the paper orientation to landscape. (Default false). -### printBackground(bool $bool) -Prints the background graphics. (Default false).
+### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### scale(float $scale) -The scale of the page rendering (e.g., 1.0). (Default 1.0).
+### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### singlePage(bool $bool) -Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields.
+### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Overrides the default margins (e.g., 0.39), in inches. -### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+### metadata(array $metadata) +Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) - -### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) +> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) +> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) +### nativePageRanges(string $ranges) +Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF.
+### omitBackground(bool $bool) +Hide the default white background and allow generating PDFs with transparency. -### footer(string $template, array $context) -### footerFile(string $path) -HTML file containing the footer. (default None).
+### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### header(string $template, array $context) -### headerFile(string $path) -HTML file containing the header. (default None).
+### paperSize(float $width, float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Overrides the default paper size, in inches.

Examples of paper size (width x height):

Letter - 8.5 x 11 (default)
Legal - 8.5 x 14
Tabloid - 11 x 17
Ledger - 17 x 11
A0 - 33.1 x 46.8
A1 - 23.4 x 33.1
A2 - 16.54 x 23.4
A3 - 11.7 x 16.54
A4 - 8.27 x 11.7
A5 - 5.83 x 8.27
A6 - 4.13 x 5.83 -### failOnConsoleExceptions(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
+### paperStandardSize(Sensiolabs\GotenbergBundle\Enumeration\PaperSizeInterface $paperSize) +### paperWidth(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions ](https://gotenberg.dev/docs/routes#console-exceptions ) +### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +Convert the resulting PDF into the given PDF/A format. -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
+### pdfUniversalAccess(bool $bool) +Enable PDF for Universal Access for optimal accessibility. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +### preferCssPageSize(bool $bool) +Define whether to prefer page size as defined by CSS. (Default false). -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+### printBackground(bool $bool) +Prints the background graphics. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +### scale(float $scale) +The scale of the page rendering (e.g., 1.0). (Default 1.0). -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).
+### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### singlePage(bool $bool) +Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium ](https://gotenberg.dev/docs/routes#network-errors-chromium ) +### skipNetworkIdleEvent(bool $bool) +### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) +Either intervals or pages. (default None). -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+### splitSpan(string $splitSpan) +Either the intervals or the page ranges to extract, depending on the selected mode. (default None). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers ](https://gotenberg.dev/docs/routes#custom-http-headers ) +### splitUnify(bool $bool) +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). -### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+### type() +### userAgent(string $userAgent) +Override the default User-Agent HTTP header. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) -### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+### waitDelay(string $delay) +Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print").
+### waitForExpression(string $expression) +Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions ](https://gotenberg.dev/docs/routes#console-exceptions ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### skipNetworkIdleEvent(bool $bool) +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) +### webhookUrl(string $url, ?string $method) diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index d9e7c7ac..9ae7749a 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -1,5 +1,8 @@ # LibreOfficePdfBuilder +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) + ### addMetadata(string $key, string $value) The metadata to write. @@ -16,11 +19,13 @@ Specify that the target documents with .od[tpgs] extension, will have that exten Specify if bookmarks are exported to PDF. ### doNotExportFormFields(bool $bool) -Set whether to export the form fields or to use the inputted/selected content of the fields. +Specify whether form fields are exported as widgets or only their fixed print representation is exported. + +### doNotUpdateIndexes(bool $bool) +Specify whether to update the indexes before conversion, keeping in mind that doing so might result in missing links in the final PDF. ### downloadFrom(array $downloadFrom) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
### exportBookmarksToPdfDestination(bool $bool) Specify that the bookmarks contained in the source LibreOffice file should be exported to the PDF file as Named Destination. @@ -49,13 +54,18 @@ Export the placeholders fields visual markings only. The exported placeholder is ### files(Stringable|string $paths) Adds office files to convert (overrides any previous files). +### flatten(bool $bool) +Flattening a PDF combines all its contents into a single layer. (default false). + +### getBodyBag() +### getHeadersBag() ### landscape(bool $bool) -Sets the paper orientation to landscape. +Set the paper orientation to landscape. ### losslessImageCompression(bool $bool) Specify if images are exported to PDF using a lossless compression format like PNG or compressed using the JPEG format. -### maxImageResolution(Sensiolabs\GotenbergBundle\Enumeration\ImageResolutionDPI $resolution) +### maxImageResolution(?Sensiolabs\GotenbergBundle\Enumeration\ImageResolutionDPI $resolution) If the form field reduceImageResolution is set to true, tell if all images will be reduced to the given value in DPI. Possible values are: 75, 150, 300, 600 and 1200. ### merge(bool $bool) @@ -66,19 +76,22 @@ Resets the metadata.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) +> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) +> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) > See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) -### nativePageRanges(string $range) -Page ranges to print, e.g., '1-4' - empty means all pages.

If multiple files are provided, the page ranges will be applied independently to each file. +### nativePageRanges(string $ranges) +Page ranges to print, e.g., '1-4' - empty means all pages. ### password(string $password) Set the password for opening the source file. -### pdfFormat(Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. +Enable PDF for Universal Access for optimal accessibility. (default false). ### quality(int $quality) Specify the quality of the JPG export. A higher value produces a higher-quality image and a larger file. Between 1 and 100.
@@ -87,44 +100,24 @@ Specify the quality of the JPG export. A higher value produces a higher-quality Specify if the resolution of each image is reduced to the resolution specified by the form field maxImageResolution. ### singlePageSheets(bool $bool) -Set whether to render the entire spreadsheet as a single page. +Ignore each sheet’s paper size, print ranges and shown/hidden status and puts every sheet (even hidden sheets) on exactly one page. ### skipEmptyPages(bool $bool) Specify that automatically inserted empty pages are suppressed. This option is active only if storing Writer documents. ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) +Either intervals or pages. (default None). ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) +Either the intervals or the page ranges to extract, depending on the selected mode. (default None). ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) - -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. - -### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
- +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). + +### type() +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) ### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 4458da55..88a2afe5 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -1,218 +1,189 @@ # MarkdownPdfBuilder -### addMetadata(string $key, string $value) -The metadata to write. - -### downloadFrom(array $downloadFrom) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) - -### files(Stringable|string $paths) -### metadata(array $metadata) -Resets the metadata.
- > [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) -> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) - -### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) -Sets the PDF format of the resulting PDF. (default None).
- -### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false).
- -### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None).
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. -### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None).
+### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) -### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) - -### wrapper(string $template, array $context) -The HTML file that wraps the markdown content, rendered from a Twig template.
- -### wrapperFile(string $path) -The HTML file that wraps the markdown content. - -### addAsset(string $path) -Adds a file, like an image, font, stylesheet, and so on.
+> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### assets(string $paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files).
+### addMetadata(string $key, string $value) +The metadata to write. -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### assets(Stringable|string $paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### cookies(array $cookies) +### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
-### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### cookies(array $cookies) -Cookies to store in the Chromium cookie jar. (overrides any previous cookies).
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### forwardCookie(string $name) -### setCookie(string $key, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF. (Default false).
+### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### landscape(bool $bool) -Sets the paper orientation to landscape. (Default false).
+### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### marginBottom(float $bottom, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### marginLeft(float $left, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### marginRight(float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### marginTop(float $top, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches.
+### files(Stringable|string $paths) +Add Markdown into a PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +> See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) -### nativePageRanges(string $range) -Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### footer(string $template, array $context) +### footerFile(string $path) +HTML file containing the footer. (default None). -### omitBackground(bool $bool) -Hides default white background and allows generating PDFs with
transparency. (Default false).
+### forwardCookie(string $name) +### generateDocumentOutline(bool $bool) +Define whether the document outline should be embedded into the PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### getBodyBag() +### getHeadersBag() +### header(string $template, array $context) +### headerFile(string $path) +HTML file containing the header. (default None). -### paperHeight(float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### paperSize(float $width, float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default paper size, in inches.

Examples of paper size (width x height):

Letter - 8.5 x 11 (default)
Legal - 8.5 x 14
Tabloid - 11 x 17
Ledger - 17 x 11
A0 - 33.1 x 46.8
A1 - 23.4 x 33.1
A2 - 16.54 x 23.4
A3 - 11.7 x 16.54
A4 - 8.27 x 11.7
A5 - 5.83 x 8.27
A6 - 4.13 x 5.83
+### landscape(bool $bool) +Set the paper orientation to landscape. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### paperStandardSize(Sensiolabs\GotenbergBundle\Enumeration\PaperSizeInterface $paperSize) -### paperWidth(float $width, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS. (Default false).
+### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### printBackground(bool $bool) -Prints the background graphics. (Default false).
+### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Overrides the default margins (e.g., 0.39), in inches. -### scale(float $scale) -The scale of the page rendering (e.g., 1.0). (Default 1.0).
+### metadata(array $metadata) +Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) - -### singlePage(bool $bool) -Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields.
+> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) +> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) +> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) -### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+### nativePageRanges(string $ranges) +Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) +### omitBackground(bool $bool) +Hide the default white background and allow generating PDFs with transparency. -### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) +### paperSize(float $width, float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Overrides the default paper size, in inches.

Examples of paper size (width x height):

Letter - 8.5 x 11 (default)
Legal - 8.5 x 14
Tabloid - 11 x 17
Ledger - 17 x 11
A0 - 33.1 x 46.8
A1 - 23.4 x 33.1
A2 - 16.54 x 23.4
A3 - 11.7 x 16.54
A4 - 8.27 x 11.7
A5 - 5.83 x 8.27
A6 - 4.13 x 5.83 -### footer(string $template, array $context) -### footerFile(string $path) -HTML file containing the footer. (default None).
+### paperStandardSize(Sensiolabs\GotenbergBundle\Enumeration\PaperSizeInterface $paperSize) +### paperWidth(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### header(string $template, array $context) -### headerFile(string $path) -HTML file containing the header. (default None).
+### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +Convert the resulting PDF into the given PDF/A format. -### failOnConsoleExceptions(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
+### pdfUniversalAccess(bool $bool) +Enable PDF for Universal Access for optimal accessibility. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions ](https://gotenberg.dev/docs/routes#console-exceptions ) +### preferCssPageSize(bool $bool) +Define whether to prefer page size as defined by CSS. (Default false). -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
+### printBackground(bool $bool) +Prints the background graphics. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +### scale(float $scale) +The scale of the page rendering (e.g., 1.0). (Default 1.0). -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### singlePage(bool $bool) +Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +### skipNetworkIdleEvent(bool $bool) +### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) +Either intervals or pages. (default None). -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).
+### splitSpan(string $splitSpan) +Either the intervals or the page ranges to extract, depending on the selected mode. (default None). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium ](https://gotenberg.dev/docs/routes#network-errors-chromium ) +### splitUnify(bool $bool) +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+### type() +### userAgent(string $userAgent) +Override the default User-Agent HTTP header. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers ](https://gotenberg.dev/docs/routes#custom-http-headers ) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) -### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+### waitDelay(string $delay) +Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) -### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+### waitForExpression(string $expression) +Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print").
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions ](https://gotenberg.dev/docs/routes#console-exceptions ) +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) +### webhookUrl(string $url, ?string $method) +### wrapper(string $template, array $context) +### wrapperFile(string $path) +The HTML file to convert into PDF. -### skipNetworkIdleEvent(bool $bool) diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index b9bb3b7f..cf891c6d 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -1,43 +1,45 @@ # MergePdfBuilder -Merge `n` pdf files into a single one. +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) ### addMetadata(string $key, string $value) The metadata to write. ### downloadFrom(array $downloadFrom) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
### files(Stringable|string $paths) +Add PDF files to merge.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) + +### flatten(bool $bool) +Flattening a PDF combines all its contents into a single layer. (default false). + +### getBodyBag() +### getHeadersBag() ### metadata(array $metadata) Resets the metadata.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) +> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) +> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) > See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) -### pdfFormat(Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. - -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. - -### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
- +Enable PDF for Universal Access for optimal accessibility. (default false). + +### type() +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) ### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index e9116c6b..9b691bb2 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -1,45 +1,49 @@ # SplitPdfBuilder -Split `n` pdf files. - -### downloadFrom(array $downloadFrom) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) - -### files(Stringable|string $paths) -### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None).
- > [!TIP] > See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) -### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +### addMetadata(string $key, string $value) +The metadata to write. -### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +### files(Stringable|string $paths) +### flatten(bool $bool) +Flattening a PDF combines all its contents into a single layer. (default false). -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### getBodyBag() +### getHeadersBag() +### metadata(array $metadata) +Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) +> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) +> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +Convert the resulting PDF into the given PDF/A format. -### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+### pdfUniversalAccess(bool $bool) +Enable PDF for Universal Access for optimal accessibility. (default false). -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) +Either intervals or pages. (default None). -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### splitSpan(string $splitSpan) +Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +### splitUnify(bool $bool) +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). + +### type() +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) +### webhookUrl(string $url, ?string $method) diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index 4f70f2f7..36790a61 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -1,216 +1,184 @@ # UrlPdfBuilder -### addMetadata(string $key, string $value) -The metadata to write. - -### downloadFrom(array $downloadFrom) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) - -### metadata(array $metadata) -Resets the metadata.
- > [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) -> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) -### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) -Sets the PDF format of the resulting PDF. (default None).
- -### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false).
+### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. -### route(string $name, array $parameters) -### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) -### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None).
+### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) -### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None).
+### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+### addMetadata(string $key, string $value) +The metadata to write. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +### assets(Stringable|string $paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -### url(string $url) -URL of the page you want to convert into PDF. +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. -### addAsset(string $path) -Adds a file, like an image, font, stylesheet, and so on.
+### cookies(array $cookies) +### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
-### assets(string $paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files).
+### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
-### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+> [!TIP] +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### cookies(array $cookies) -Cookies to store in the Chromium cookie jar. (overrides any previous cookies).
+### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) + +### footer(string $template, array $context) +### footerFile(string $path) +HTML file containing the footer. (default None). ### forwardCookie(string $name) -### setCookie(string $key, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF. (Default false).
+Define whether the document outline should be embedded into the PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### getBodyBag() +### getHeadersBag() +### header(string $template, array $context) +### headerFile(string $path) +HTML file containing the header. (default None). ### landscape(bool $bool) -Sets the paper orientation to landscape. (Default false).
+Set the paper orientation to landscape. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### marginBottom(float $bottom, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### marginLeft(float $left, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### marginRight(float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### marginTop(float $top, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches.
+### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + +### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + +### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Overrides the default margins (e.g., 0.39), in inches. -### nativePageRanges(string $range) -Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages).
+### metadata(array $metadata) +Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) +> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) +> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) + +### nativePageRanges(string $ranges) +Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). ### omitBackground(bool $bool) -Hides default white background and allows generating PDFs with
transparency. (Default false).
+Hide the default white background and allow generating PDFs with transparency. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### paperHeight(float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) ### paperSize(float $width, float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default paper size, in inches.

Examples of paper size (width x height):

Letter - 8.5 x 11 (default)
Legal - 8.5 x 14
Tabloid - 11 x 17
Ledger - 17 x 11
A0 - 33.1 x 46.8
A1 - 23.4 x 33.1
A2 - 16.54 x 23.4
A3 - 11.7 x 16.54
A4 - 8.27 x 11.7
A5 - 5.83 x 8.27
A6 - 4.13 x 5.83
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +Overrides the default paper size, in inches.

Examples of paper size (width x height):

Letter - 8.5 x 11 (default)
Legal - 8.5 x 14
Tabloid - 11 x 17
Ledger - 17 x 11
A0 - 33.1 x 46.8
A1 - 23.4 x 33.1
A2 - 16.54 x 23.4
A3 - 11.7 x 16.54
A4 - 8.27 x 11.7
A5 - 5.83 x 8.27
A6 - 4.13 x 5.83 ### paperStandardSize(Sensiolabs\GotenbergBundle\Enumeration\PaperSizeInterface $paperSize) -### paperWidth(float $width, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS. (Default false).
+### paperWidth(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) +Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +Convert the resulting PDF into the given PDF/A format. -### printBackground(bool $bool) -Prints the background graphics. (Default false).
+### pdfUniversalAccess(bool $bool) +Enable PDF for Universal Access for optimal accessibility. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### preferCssPageSize(bool $bool) +Define whether to prefer page size as defined by CSS. (Default false). -### scale(float $scale) -The scale of the page rendering (e.g., 1.0). (Default 1.0).
+### printBackground(bool $bool) +Prints the background graphics. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +### route(string $name, array $parameters) +### scale(float $scale) +The scale of the page rendering (e.g., 1.0). (Default 1.0). +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) ### singlePage(bool $bool) -Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields.
- -### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) - -### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) - -### footer(string $template, array $context) -### footerFile(string $path) -HTML file containing the footer. (default None).
- -### header(string $template, array $context) -### headerFile(string $path) -HTML file containing the header. (default None).
- -### failOnConsoleExceptions(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions ](https://gotenberg.dev/docs/routes#console-exceptions ) - -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) - -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).
+### skipNetworkIdleEvent(bool $bool) +### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) +Either intervals or pages. (default None). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium ](https://gotenberg.dev/docs/routes#network-errors-chromium ) +### splitSpan(string $splitSpan) +Either the intervals or the page ranges to extract, depending on the selected mode. (default None). -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+### splitUnify(bool $bool) +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers ](https://gotenberg.dev/docs/routes#custom-http-headers ) +### type() +### url(string $url) +URL of the page you want to convert into PDF. -### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+### userAgent(string $userAgent) +Override the default User-Agent HTTP header. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) -### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+### waitDelay(string $delay) +Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print").
+### waitForExpression(string $expression) +Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions ](https://gotenberg.dev/docs/routes#console-exceptions ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### skipNetworkIdleEvent(bool $bool) +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) +### webhookUrl(string $url, ?string $method) diff --git a/docs/pdf/flatten-builder.md b/docs/pdf/flatten-builder.md new file mode 100644 index 00000000..14c50098 --- /dev/null +++ b/docs/pdf/flatten-builder.md @@ -0,0 +1,36 @@ +# Flatten Builder + +You may have the possibility to flatten several PDF pages. +It combines all its contents into a single layer, making it non-editable and +ensuring that the document's integrity is maintained. + +## Basic usage + +> [!WARNING] +> As assets files, by default the PDF files are fetch in the assets folder of +> your application. +> For more information about path resolution go to [assets documentation](../assets.md). + +```php +namespace App\Controller; + +use Sensiolabs\GotenbergBundle\GotenbergPdfInterface; + +class YourController +{ + public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response + { + return $gotenberg->flatten() + ->files( + 'document_1.pdf', + 'document_2.pdf', + ) + ->generate() + ->stream() + ; + } +} +``` + +> [!TIP] +> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#flatten-pdfs-route). diff --git a/docs/pdf/merge-builder.md b/docs/pdf/merge-builder.md index 7047b63c..13345cd8 100644 --- a/docs/pdf/merge-builder.md +++ b/docs/pdf/merge-builder.md @@ -144,3 +144,32 @@ class YourController } } ``` + +### flatten + +Default: `false` + +You may have the possibility to flatten several PDF pages. +It combines all its contents into a single layer, making it non-editable and +ensuring that the document's integrity is maintained. + +```php +namespace App\Controller; + +use Sensiolabs\GotenbergBundle\GotenbergPdfInterface; + +class YourController +{ + public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response + { + return $gotenberg->office() + ->files('document.txt') + ->flatten() // is same as `->flatten(true)` + ->generate() + ; + } +} +``` + +> [!TIP] +> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#flatten-libreoffice). diff --git a/docs/pdf/office-builder.md b/docs/pdf/office-builder.md index b7a05070..c31c8f91 100644 --- a/docs/pdf/office-builder.md +++ b/docs/pdf/office-builder.md @@ -90,14 +90,16 @@ class YourController [exportLinksRelativeFsys](#exportLinksRelativeFsys) [exportHiddenSlides](#exportHiddenSlides) [addOriginalDocumentAsStream](#addOriginalDocumentAsStream) -[download from](#download-from) +[downloadFrom](#downloadFrom) +[doNotUpdateIndexes](#doNotUpdateIndexes) ### Formatting [metadata](#metadata) [addMetadata](#addMetadata) [pdfFormat](#pdfFormat) [pdfUniversalAccess](#pdfUniversalAccess) -[convertOooTargetToPdfTarget](#convertOooTargetToPdfTarget) +[convertOooTargetToPdfTarget](#convertOooTargetToPdfTarget) +[flatten](#flatten) ### Security [password](#password) @@ -766,7 +768,7 @@ class YourController > [!TIP] > For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#page-properties-libreoffice). -### download from +### downloadFrom > [!WARNING] > URL of the file. It MUST return a `Content-Disposition` header with a filename parameter. @@ -811,6 +813,35 @@ class YourController > [!TIP] > For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#download-from). +### doNotUpdateIndexes + +Default: `true` + +Specify whether to update the indexes before conversion, keeping in mind that +doing so might result in missing links in the final PDF. + +```php +namespace App\Controller; + +use Sensiolabs\GotenbergBundle\GotenbergPdfInterface; + +class YourController +{ + public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response + { + return $gotenberg + ->office() + ->doNotUpdateIndexes() // is same as `->doNotUpdateIndexes(false)` + ->generate() + ->stream() + ; + } +} +``` + +> [!TIP] +> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#page-properties-libreoffice). + ## Formatting ### metadata @@ -926,7 +957,9 @@ class YourController Default: `false` -Specify that the target documents with .od[tpgs] extension, will have that extension changed to .pdf when the link is exported to PDF. The source document remains untouched. +Specify that the target documents with .od[tpgs] extension, will have that +extension changed to .pdf when the link is exported to PDF. The source +document remains untouched. ```php namespace App\Controller; @@ -949,6 +982,35 @@ class YourController > [!TIP] > For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#page-properties-libreoffice). +### flatten + +Default: `false` + +You may have the possibility to flatten several PDF pages. +It combines all its contents into a single layer, making it non-editable and +ensuring that the document's integrity is maintained. + +```php +namespace App\Controller; + +use Sensiolabs\GotenbergBundle\GotenbergPdfInterface; + +class YourController +{ + public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response + { + return $gotenberg->office() + ->files('document.txt') + ->flatten() // is same as `->flatten(true)` + ->generate() + ; + } +} +``` + +> [!TIP] +> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#flatten-libreoffice). + ## Security ### password diff --git a/docs/pdf/split-builder.md b/docs/pdf/split-builder.md index aba8b31d..554b9bfe 100644 --- a/docs/pdf/split-builder.md +++ b/docs/pdf/split-builder.md @@ -1,6 +1,6 @@ # Split Builder -You may have the possibility to split several PDF pages or documents. +You may have the possibility to split several PDF pages. ## Basic usage @@ -123,3 +123,32 @@ class YourController } } ``` + +### flatten + +Default: `false` + +You may have the possibility to flatten several PDF pages. +It combines all its contents into a single layer, making it non-editable and +ensuring that the document's integrity is maintained. + +```php +namespace App\Controller; + +use Sensiolabs\GotenbergBundle\GotenbergPdfInterface; + +class YourController +{ + public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response + { + return $gotenberg->office() + ->files('document.txt') + ->flatten() // is same as `->flatten(true)` + ->generate() + ; + } +} +``` + +> [!TIP] +> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#flatten-libreoffice). diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index 6ce3bc7d..178e91cb 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -1,149 +1,123 @@ # HtmlScreenshotBuilder -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
- > [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers ](https://gotenberg.dev/docs/routes#custom-http-headers ) +> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) -### downloadFrom(array $downloadFrom) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) +### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print").
+### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) -### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+### assets(Stringable|string $paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) - -### addAsset(string $path) -Adds a file, like an image, font, stylesheet, and so on.
+### clip(bool $bool) +Define whether to clip the screenshot according to the device dimensions. (Default false). -### assets(string $paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files).
+### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### cookies(array $cookies) +### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
-### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+> [!TIP] +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) + +### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
-### cookies(array $cookies) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### forwardCookie(string $name) -### setCookie(string $key, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### clip(bool $bool) -Define whether to clip the screenshot according to the device dimensions. (Default false).
+### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) + +### footer(string $template, array $context) +### footerFile(string $path) +HTML file containing the footer. (default None). ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) -The image compression format, either "png", "jpeg" or "webp". (default png).
+The image compression format, either "png", "jpeg" or "webp". (default png). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +### forwardCookie(string $name) +### getBodyBag() +### getHeadersBag() +### header(string $template, array $context) +### headerFile(string $path) +HTML file containing the header. (default None). ### height(int $height) -The device screen width in pixels. (Default 600).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with
transparency. (Default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +Hides default white background and allows generating screenshot with
transparency. (Default false). ### optimizeForSpeed(bool $bool) -Define whether to optimize image encoding for speed, not for resulting size. (Default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +Define whether to optimize image encoding for speed, not for resulting size. (Default false). ### quality(int $quality) The compression quality from range 0 to 100 (jpeg only). (default 100).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) - -### width(int $width) -The device screen width in pixels. (Default 800).
+### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### skipNetworkIdleEvent(bool $bool) +### type() +### userAgent(string $userAgent) +Override the default User-Agent HTTP header. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to screenshot. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to screenshot until it returns true. (default None).

For instance: "window.status === 'ready'".
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) - -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into Screenshot.
- -### failOnConsoleExceptions(bool $bool) -Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions ](https://gotenberg.dev/docs/routes#console-exceptions ) - -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) - -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium ](https://gotenberg.dev/docs/routes#network-errors-chromium ) +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) +### webhookUrl(string $url, ?string $method) +### width(int $width) +The device screen width in pixels. (Default 800). -### skipNetworkIdleEvent(bool $bool) diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index 2b8989e3..ae9d0bc2 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -1,152 +1,133 @@ # MarkdownScreenshotBuilder -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
- > [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers ](https://gotenberg.dev/docs/routes#custom-http-headers ) +> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) -### downloadFrom(array $downloadFrom) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) +### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print").
+### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) -### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### files(Stringable|string $paths) -### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+### assets(Stringable|string $paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) - -### wrapper(string $template, array $context) -The HTML file that wraps the markdown content, rendered from a Twig template.
+### clip(bool $bool) +Define whether to clip the screenshot according to the device dimensions. (Default false). -### wrapperFile(string $path) -The HTML file that wraps the markdown content. +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. -### addAsset(string $path) -Adds a file, like an image, font, stylesheet, and so on.
+### cookies(array $cookies) +### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
-### assets(string $paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files).
+### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
-### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+> [!TIP] +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) + +### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
-### cookies(array $cookies) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### forwardCookie(string $name) -### setCookie(string $key, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### clip(bool $bool) -Define whether to clip the screenshot according to the device dimensions. (Default false).
+### files(Stringable|string $paths) +Add Markdown into a PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +> See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) + +### footer(string $template, array $context) +### footerFile(string $path) +HTML file containing the footer. (default None). ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) -The image compression format, either "png", "jpeg" or "webp". (default png).
+The image compression format, either "png", "jpeg" or "webp". (default png). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +### forwardCookie(string $name) +### getBodyBag() +### getHeadersBag() +### header(string $template, array $context) +### headerFile(string $path) +HTML file containing the header. (default None). ### height(int $height) -The device screen width in pixels. (Default 600).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with
transparency. (Default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +Hides default white background and allows generating screenshot with
transparency. (Default false). ### optimizeForSpeed(bool $bool) -Define whether to optimize image encoding for speed, not for resulting size. (Default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +Define whether to optimize image encoding for speed, not for resulting size. (Default false). ### quality(int $quality) The compression quality from range 0 to 100 (jpeg only). (default 100).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) - -### width(int $width) -The device screen width in pixels. (Default 800).
+### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### skipNetworkIdleEvent(bool $bool) +### type() +### userAgent(string $userAgent) +Override the default User-Agent HTTP header. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to screenshot. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to screenshot until it returns true. (default None).

For instance: "window.status === 'ready'".
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) - -### failOnConsoleExceptions(bool $bool) -Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions ](https://gotenberg.dev/docs/routes#console-exceptions ) - -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) - -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).
+### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) +### webhookUrl(string $url, ?string $method) +### width(int $width) +The device screen width in pixels. (Default 800). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium ](https://gotenberg.dev/docs/routes#network-errors-chromium ) +### wrapper(string $template, array $context) +### wrapperFile(string $path) +The HTML file to convert into PDF. -### skipNetworkIdleEvent(bool $bool) diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index 995facc8..11cd46c4 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -1,150 +1,128 @@ # UrlScreenshotBuilder -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
- > [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers ](https://gotenberg.dev/docs/routes#custom-http-headers ) +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) -### downloadFrom(array $downloadFrom) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from ](https://gotenberg.dev/docs/routes#download-from ) +### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print").
+### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) -### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### route(string $name, array $parameters) -### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) -### url(string $url) -URL of the page you want to screenshot. +### assets(Stringable|string $paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+### clip(bool $bool) +Define whether to clip the screenshot according to the device dimensions. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. -### addAsset(string $path) -Adds a file, like an image, font, stylesheet, and so on.
+### cookies(array $cookies) +### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
-### assets(string $paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files).
+### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). -### errorWebhookUrl(?string $url, ?string $method) -Sets the webhook for cases of error.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. - -### webhookExtraHeaders(array $extraHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) + +### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
-### cookies(array $cookies) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### forwardCookie(string $name) -### setCookie(string $key, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### clip(bool $bool) -Define whether to clip the screenshot according to the device dimensions. (Default false).
+### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) + +### footer(string $template, array $context) +### footerFile(string $path) +HTML file containing the footer. (default None). ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) -The image compression format, either "png", "jpeg" or "webp". (default png).
+The image compression format, either "png", "jpeg" or "webp". (default png). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +### forwardCookie(string $name) +### getBodyBag() +### getHeadersBag() +### header(string $template, array $context) +### headerFile(string $path) +HTML file containing the header. (default None). ### height(int $height) -The device screen width in pixels. (Default 600).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with
transparency. (Default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium ](https://gotenberg.dev/docs/routes#page-properties-chromium ) +Hides default white background and allows generating screenshot with
transparency. (Default false). ### optimizeForSpeed(bool $bool) -Define whether to optimize image encoding for speed, not for resulting size. (Default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +Define whether to optimize image encoding for speed, not for resulting size. (Default false). ### quality(int $quality) The compression quality from range 0 to 100 (jpeg only). (default 100).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +### route(string $name, array $parameters) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) +### skipNetworkIdleEvent(bool $bool) +### type() +### url(string $url) +URL of the page you want to convert into PDF. -### width(int $width) -The device screen width in pixels. (Default 800).
+### userAgent(string $userAgent) +Override the default User-Agent HTTP header. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route ](https://gotenberg.dev/docs/routes#screenshots-route ) +> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to screenshot. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to screenshot until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering ](https://gotenberg.dev/docs/routes#wait-before-rendering ) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### failOnConsoleExceptions(bool $bool) -Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions ](https://gotenberg.dev/docs/routes#console-exceptions ) - -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) - -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) - -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium ](https://gotenberg.dev/docs/routes#network-errors-chromium ) +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +### webhookErrorUrl(string $url, ?string $method) +### webhookExtraHeaders(array $extraHttpHeaders) +### webhookRoute(string $route, array $parameters, ?string $method) +### webhookUrl(string $url, ?string $method) +### width(int $width) +The device screen width in pixels. (Default 800). -### skipNetworkIdleEvent(bool $bool) diff --git a/phpstan.dist.neon b/phpstan.dist.neon index d8c860ef..fca86399 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,3 +1,8 @@ +services: + - + class: Sensiolabs\GotenbergBundle\Tests\PHPStanRules\AlwaysUsedMethodRule + tags: + - phpstan.methods.alwaysUsedMethodExtension parameters: phpVersion: 80100 level: 8 @@ -5,33 +10,7 @@ parameters: - 'config' - 'src' - 'tests' - excludePaths: - - tests/Builder/DefaultBuilderTraitTest.php ignoreErrors: - - - message: "#^Cannot call method generate\\(\\) on Symfony\\\\Component\\\\Routing\\\\Generator\\\\UrlGeneratorInterface\\|null\\.$#" - count: 1 - path: src/Builder/Pdf/UrlPdfBuilder.php - - - message: "#^Cannot call method getContext\\(\\) on Symfony\\\\Component\\\\Routing\\\\Generator\\\\UrlGeneratorInterface\\|null\\.$#" - count: 1 - path: src/Builder/Pdf/UrlPdfBuilder.php - - - message: "#^Cannot call method setContext\\(\\) on Symfony\\\\Component\\\\Routing\\\\Generator\\\\UrlGeneratorInterface\\|null\\.$#" - count: 2 - path: src/Builder/Pdf/UrlPdfBuilder.php - - - message: "#^Cannot call method generate\\(\\) on Symfony\\\\Component\\\\Routing\\\\Generator\\\\UrlGeneratorInterface\\|null\\.$#" - count: 1 - path: src/Builder/Screenshot/UrlScreenshotBuilder.php - - - message: "#^Cannot call method getContext\\(\\) on Symfony\\\\Component\\\\Routing\\\\Generator\\\\UrlGeneratorInterface\\|null\\.$#" - count: 1 - path: src/Builder/Screenshot/UrlScreenshotBuilder.php - - - message: "#^Cannot call method setContext\\(\\) on Symfony\\\\Component\\\\Routing\\\\Generator\\\\UrlGeneratorInterface\\|null\\.$#" - count: 2 - path: src/Builder/Screenshot/UrlScreenshotBuilder.php - message: "#^Cannot use array destructuring on array\\\\|null\\.$#" count: 1 @@ -43,33 +22,12 @@ parameters: - # Fixed when requiring 8.2 message: "#^Parameter \\#1 \\$iterator of function iterator_to_array expects Traversable, iterable given\\.$#" count: 1 - path: tests/Builder/AbstractBuilderTestCase.php - - - message: "#^Parameter \\#2 \\$cookie of method Sensiolabs\\\\GotenbergBundle\\\\Builder\\\\Pdf\\\\AbstractChromiumPdfBuilder\\:\\:setCookie\\(\\) expects array\\{name\\: string, value\\: string, domain\\: string, path\\?\\: string\\|null, secure\\?\\: bool\\|null, httpOnly\\?\\: bool\\|null, sameSite\\?\\: 'Lax'\\|'Strict'\\|null\\}\\|Symfony\\\\Component\\\\HttpFoundation\\\\Cookie, array\\{name\\: string, value\\: string\\|null, domain\\: string\\} given\\.$#" - count: 1 - path: src/Builder/Pdf/AbstractChromiumPdfBuilder.php - - - - message: "#^Parameter \\#2 \\$cookie of method Sensiolabs\\\\GotenbergBundle\\\\Builder\\\\Screenshot\\\\AbstractChromiumScreenshotBuilder\\:\\:setCookie\\(\\) expects array\\{name\\: string, value\\: string, domain\\: string, path\\?\\: string\\|null, secure\\?\\: bool\\|null, httpOnly\\?\\: bool\\|null, sameSite\\?\\: 'Lax'\\|'Strict'\\|null\\}\\|Symfony\\\\Component\\\\HttpFoundation\\\\Cookie, array\\{name\\: string, value\\: string\\|null, domain\\: string\\} given\\.$#" - count: 1 - path: src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php - - - - message: "#^Call to an undefined method Sensiolabs\\\\GotenbergBundle\\\\Builder\\\\AsyncBuilderInterface\\:\\:errorWebhookUrl\\(\\)\\.$#" - count: 2 - path: tests/Builder/AsyncBuilderTraitTest.php - - - - message: "#^Call to an undefined method Sensiolabs\\\\GotenbergBundle\\\\Builder\\\\AsyncBuilderInterface\\:\\:webhookConfiguration\\(\\)\\.$#" - count: 1 - path: tests/Builder/AsyncBuilderTraitTest.php - + path: tests/Builder/GotenbergBuilderTestCase.php - - message: "#^Call to an undefined method Sensiolabs\\\\GotenbergBundle\\\\Builder\\\\AsyncBuilderInterface\\:\\:webhookExtraHeaders\\(\\)\\.$#" + message: "#^ Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\ArrayNodeDefinition|Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\VariableNodeDefinition::append\\(\\)\\.$#" count: 1 - path: tests/Builder/AsyncBuilderTraitTest.php - + path: src/NodeBuilder/ArrayNodeBuilder.php - - message: "#^Call to an undefined method Sensiolabs\\\\GotenbergBundle\\\\Builder\\\\AsyncBuilderInterface\\:\\:webhookUrl\\(\\)\\.$#" - count: 4 - path: tests/Builder/AsyncBuilderTraitTest.php + message: '#Class Sensiolabs\\GotenbergBundle\\Builder\\Pdf|Screenshot\\.* has an uninitialized readonly property \$dependencies#' + count: 11 + path: src/Builder diff --git a/phpunit.xml b/phpunit.xml index db970995..79615ce3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -4,8 +4,8 @@ bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache" executionOrder="depends,defects" - requireCoverageMetadata="true" - beStrictAboutCoverageMetadata="true" + requireCoverageMetadata="false" + beStrictAboutCoverageMetadata="false" beStrictAboutOutputDuringTests="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerErrors="true" diff --git a/src/Builder/AbstractBuilder.php b/src/Builder/AbstractBuilder.php new file mode 100644 index 00000000..18dadb1e --- /dev/null +++ b/src/Builder/AbstractBuilder.php @@ -0,0 +1,156 @@ + */ + private readonly \ReflectionClass $reflection; + + private string $headerDisposition = HeaderUtils::DISPOSITION_INLINE; + + /** @var ProcessorInterface|null */ + private ProcessorInterface|null $processor; + + public function __construct( + protected readonly GotenbergClientInterface $client, + protected readonly ContainerInterface $dependencies, + ) { + $this->bodyBag = new BodyBag(); + $this->headersBag = new HeadersBag(); + + $this->reflection = new \ReflectionClass(static::class); + } + + abstract protected function getEndpoint(): string; + + /** + * @see https://gotenberg.dev/docs/routes#output-filename. + * + * @param HeaderUtils::DISPOSITION_* $headerDisposition + */ + public function fileName(string $fileName, string $headerDisposition = HeaderUtils::DISPOSITION_INLINE): static + { + $this->headerDisposition = $headerDisposition; + + $this->headersBag->set('Gotenberg-Output-Filename', $fileName); + + return $this; + } + + /** + * @param ProcessorInterface $processor + */ + public function processor(ProcessorInterface $processor): static + { + $this->processor = $processor; + + return $this; + } + + public function generate(): GotenbergFileResult + { + $this->validatePayloadBody(); + $payloadBody = iterator_to_array($this->normalizePayloadBody()); + + $response = $this->client->call( + $this->getEndpoint(), + new Payload( + $payloadBody, + $this->getHeadersBag()->all(), + ), + ); + + return new GotenbergFileResult( + $response, + $this->client->stream($response), + $this->processor ?? new NullProcessor(), + $this->headerDisposition, + ); + } + + public function generateAsync(): GotenbergAsyncResult + { + $this->validatePayloadBody(); + $payloadBody = iterator_to_array($this->normalizePayloadBody()); + + $response = $this->client->call( + $this->getEndpoint(), + new Payload( + $payloadBody, + $this->getHeadersBag()->all(), + ), + ); + + return new GotenbergAsyncResult( + $response, + ); + } + + public function getBodyBag(): BodyBag + { + return $this->bodyBag; + } + + public function getHeadersBag(): HeadersBag + { + return $this->headersBag; + } + + protected function validatePayloadBody(): void + { + } + + private function normalizePayloadBody(): \Generator + { + foreach (array_reverse($this->reflection->getMethods()) as $method) { + $attributes = $method->getAttributes(NormalizeGotenbergPayload::class); + + if (\count($attributes) === 0) { + continue; + } + + foreach ($method->invoke($this) as $key => $normalizer) { + if ($this->getBodyBag()->get($key) === null) { + continue; + } + + if (!\is_callable($normalizer)) { + throw new \RuntimeException(\sprintf('Normalizer "%s" is not a valid callable function.', $key)); + } + + if (('assets' === $key || 'files' === $key) && \count($this->getBodyBag()->get($key)) > 1) { + $multipleFiles = $normalizer($key, $this->getBodyBag()->get($key)); + foreach ($multipleFiles as $file) { + yield $file; + } + + $this->getBodyBag()->unset($key); + continue; + } + + yield $normalizer($key, $this->getBodyBag()->get($key)); + $this->getBodyBag()->unset($key); + } + } + + foreach ($this->getBodyBag()->all() as $key => $value) { + yield [$key => $value]; + } + } +} diff --git a/src/Builder/AsyncBuilderInterface.php b/src/Builder/AsyncBuilderInterface.php deleted file mode 100644 index 3daedb50..00000000 --- a/src/Builder/AsyncBuilderInterface.php +++ /dev/null @@ -1,15 +0,0 @@ - - */ - private array $webhookExtraHeaders = []; - - private WebhookConfigurationRegistryInterface $webhookConfigurationRegistry; - - public function generateAsync(): void - { - if (null === $this->successWebhookUrl) { - throw new MissingRequiredFieldException('->webhookUrl() was never called.'); - } - - $errorWebhookUrl = $this->errorWebhookUrl ?? $this->successWebhookUrl; - - $headers = [ - 'Gotenberg-Webhook-Url' => $this->successWebhookUrl, - 'Gotenberg-Webhook-Error-Url' => $errorWebhookUrl, - ]; - - if (null !== $this->successWebhookMethod) { - $headers['Gotenberg-Webhook-Method'] = $this->successWebhookMethod; - } - - if (null !== $this->errorWebhookMethod) { - $headers['Gotenberg-Webhook-Error-Method'] = $this->errorWebhookMethod; - } - - if ([] !== $this->webhookExtraHeaders) { - $headers['Gotenberg-Webhook-Extra-Http-Headers'] = json_encode($this->webhookExtraHeaders, \JSON_THROW_ON_ERROR); - } - - if (null !== $this->fileName) { - // 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); - } - - /** - * Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. - */ - public function webhookConfiguration(string $name): static - { - $webhookConfiguration = $this->webhookConfigurationRegistry->get($name); - - $result = $this - ->webhookUrl( - $webhookConfiguration['success']['url'], - $webhookConfiguration['success']['method'], - ) - ->errorWebhookUrl( - $webhookConfiguration['error']['url'], - $webhookConfiguration['error']['method'], - ) - ; - - if (\array_key_exists('extra_http_headers', $webhookConfiguration)) { - $result = $result->webhookExtraHeaders($webhookConfiguration['extra_http_headers']); - } - - return $result; - } - - /** - * Sets the webhook for cases of success. - * Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. - * - * @param 'POST'|'PATCH'|'PUT'|null $method - * - * @see https://gotenberg.dev/docs/webhook - */ - public function webhookUrl(string $url, string|null $method = null): static - { - $this->successWebhookUrl = $url; - $this->successWebhookMethod = $method; - - return $this; - } - - /** - * Sets the webhook for cases of error. - * Optionaly sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. - * - * @param 'POST'|'PATCH'|'PUT'|null $method - * - * @see https://gotenberg.dev/docs/webhook - */ - public function errorWebhookUrl(string|null $url = null, string|null $method = null): static - { - $this->errorWebhookUrl = $url; - $this->errorWebhookMethod = $method; - - return $this; - } - - /** - * Extra headers that will be provided to the webhook endpoint. May it either be Success or Error. - * - * @param array $extraHeaders - */ - public function webhookExtraHeaders(array $extraHeaders): static - { - $this->webhookExtraHeaders = array_merge($this->webhookExtraHeaders, $extraHeaders); - - return $this; - } -} diff --git a/src/Builder/Attributes/ExposeSemantic.php b/src/Builder/Attributes/ExposeSemantic.php new file mode 100644 index 00000000..2de7097c --- /dev/null +++ b/src/Builder/Attributes/ExposeSemantic.php @@ -0,0 +1,14 @@ +getBodyBag()->unset('assets'); + + foreach ($paths as $path) { + $this->addAsset($path); + } + + return $this; + } + + /** + * Adds a file, like an image, font, stylesheet, and so on. + */ + public function addAsset(string|\Stringable $path): static + { + $path = (string) $path; + $assets = $this->getBodyBag()->get('assets', []); + + if (\array_key_exists($path, $assets)) { + return $this; + } + + $assets[$path] = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); + + $this->getBodyBag()->set('assets', $assets); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizeAsset(): \Generator + { + yield 'assets' => NormalizerFactory::asset(); + } +} diff --git a/src/Builder/Behaviors/Chromium/ContentTrait.php b/src/Builder/Behaviors/Chromium/ContentTrait.php new file mode 100644 index 00000000..ab3cbefa --- /dev/null +++ b/src/Builder/Behaviors/Chromium/ContentTrait.php @@ -0,0 +1,130 @@ + $context + * + * @throws PdfPartRenderingException if the template could not be rendered + */ + public function content(string $template, array $context = []): self + { + return $this->withRenderedPart(Part::Body, $template, $context); + } + + /** + * The HTML file to convert into PDF. + */ + public function contentFile(string $path): self + { + return $this->withFilePart(Part::Body, $path); + } + + /** + * @param string $template #Template + * @param array $context + * + * @throws PdfPartRenderingException if the template could not be rendered + * + * See https://gotenberg.dev/docs/routes#header-footer-chromium. + */ + #[ExposeSemantic(new ArrayNodeBuilder('header', children: [ + new ScalarNodeBuilder('template', required: true, restrictTo: 'string'), + new ArrayNodeBuilder('context', normalizeKeys: false, prototype: 'variable'), + ]))] + public function header(string $template, array $context = []): static + { + return $this->withRenderedPart(Part::Header, $template, $context); + } + + /** + * @param string $template #Template + * @param array $context + * + * @throws PdfPartRenderingException if the template could not be rendered + * + * See https://gotenberg.dev/docs/routes#header-footer-chromium. + */ + #[ExposeSemantic(new ArrayNodeBuilder('footer', children: [ + new ScalarNodeBuilder('template', required: true, restrictTo: 'string'), + new ArrayNodeBuilder('context', normalizeKeys: false, prototype: 'variable'), + ]))] + public function footer(string $template, array $context = []): static + { + return $this->withRenderedPart(Part::Footer, $template, $context); + } + + /** + * HTML file containing the header. (default None). + */ + public function headerFile(string $path): static + { + return $this->withFilePart(Part::Header, $path); + } + + /** + * HTML file containing the footer. (default None). + */ + public function footerFile(string $path): static + { + return $this->withFilePart(Part::Footer, $path); + } + + /** + * @param string $template #Template + * @param array $context + * + * @throws PdfPartRenderingException if the template could not be rendered + */ + protected function withRenderedPart(Part $part, string $template, array $context = []): static + { + $this->getTwig()->getRuntime(GotenbergRuntime::class)->setBuilder($this); + try { + $renderedPart = new RenderedPart($part, $this->getTwig()->render($template, array_merge($context, ['_builder' => $this]))); + } catch (\Throwable $t) { + throw new PdfPartRenderingException(\sprintf('Could not render template "%s" into PDF part "%s". %s', $template, $part->value, $t->getMessage()), previous: $t); + } finally { + $this->getTwig()->getRuntime(GotenbergRuntime::class)->setBuilder(null); + } + + $this->getBodyBag()->set($part->value, $renderedPart); + + return $this; + } + + protected function withFilePart(Part $part, string $path): static + { + $this->getBodyBag()->set($part->value, new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path))); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizeContent(): \Generator + { + yield 'header.html' => NormalizerFactory::content(); + yield 'index.html' => NormalizerFactory::content(); + yield 'footer.html' => NormalizerFactory::content(); + } +} diff --git a/src/Builder/Behaviors/Chromium/CookieTrait.php b/src/Builder/Behaviors/Chromium/CookieTrait.php new file mode 100644 index 00000000..487d169d --- /dev/null +++ b/src/Builder/Behaviors/Chromium/CookieTrait.php @@ -0,0 +1,125 @@ + $cookies + */ + #[ExposeSemantic(new ArrayNodeBuilder('cookies', prototype: 'array', children: [ + new ScalarNodeBuilder('name', required: true, restrictTo: 'string'), + new ScalarNodeBuilder('value', required: true), + new ScalarNodeBuilder('domain', required: true, restrictTo: 'string'), + new ScalarNodeBuilder('path', restrictTo: 'string'), + new BooleanNodeBuilder('secure'), + new BooleanNodeBuilder('httpOnly'), + new EnumNodeBuilder('sameSite', values: ['Strict', 'Lax', 'None']), + ]))] + public function cookies(array $cookies): static + { + if ([] === $cookies) { + $this->getBodyBag()->unset('cookies'); + + return $this; + } + + $this->addCookies($cookies); + + return $this; + } + + /** + * Add cookies to store in the Chromium cookie jar. + * + * @see https://gotenberg.dev/docs/routes#cookies-chromium + * + * @param list $cookies + */ + public function addCookies(array $cookies): static + { + ValidatorFactory::cookies($cookies); + $c = $this->getBodyBag()->get('cookies', []); + + foreach ($cookies as $cookie) { + if ($cookie instanceof Cookie) { + $c[$cookie->getName()] = $cookie; + + continue; + } + + $c[$cookie['name']] = $cookie; + } + + $this->getBodyBag()->set('cookies', $c); + + return $this; + } + + /** + * @param Cookie|array{name: string, value: string, domain: string, path?: string|null, secure?: bool|null, httpOnly?: bool|null, sameSite?: 'Strict'|'Lax'|null} $cookie + */ + public function setCookie(string $name, Cookie|array $cookie): static + { + $current = $this->getBodyBag()->get('cookies', []); + $current[$name] = $cookie; + + $this->getBodyBag()->set('cookies', $current); + + return $this; + } + + public function forwardCookie(string $name): static + { + $request = $this->getCurrentRequest(); + + if (null === $request) { + $this->getLogger()?->debug('Cookie {sensiolabs_gotenberg.cookie_name} cannot be forwarded because there is no Request.', [ + 'sensiolabs_gotenberg.cookie_name' => $name, + ]); + + return $this; + } + + if (false === $request->cookies->has($name)) { + $this->getLogger()?->debug('Cookie {sensiolabs_gotenberg.cookie_name} does not exists.', [ + 'sensiolabs_gotenberg.cookie_name' => $name, + ]); + + return $this; + } + + return $this->setCookie($name, [ + 'name' => $name, + 'value' => (string) $request->cookies->get($name), + 'domain' => $request->getHost(), + ]); + } + + #[NormalizeGotenbergPayload] + private function normalizeCookies(): \Generator + { + yield 'cookies' => NormalizerFactory::cookie(); + } +} diff --git a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php new file mode 100644 index 00000000..f35853d1 --- /dev/null +++ b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php @@ -0,0 +1,80 @@ +getBodyBag()->set('userAgent', $userAgent); + + return $this; + } + + /** + * Sets extra HTTP headers that Chromium will send when loading the HTML + * document. (default None). (overrides any previous headers). + * + * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium + * + * @param array $headers + */ + #[ExposeSemantic(new ArrayNodeBuilder('extra_http_headers', normalizeKeys: false, useAttributeAsKey: 'name', prototype: 'variable'))] + public function extraHttpHeaders(array $headers): static + { + if ([] === $headers) { + $this->getBodyBag()->unset('extraHttpHeaders'); + + return $this; + } + + $this->getBodyBag()->set('extraHttpHeaders', $headers); + + return $this; + } + + /** + * Adds extra HTTP headers that Chromium will send when loading the HTML + * document. (default None). + * + * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium + * + * @param array $headers + */ + public function addExtraHttpHeaders(array $headers): static + { + if ([] === $headers) { + return $this; + } + + $current = $this->getBodyBag()->get('extraHttpHeaders', []); + + $this->getBodyBag()->set('extraHttpHeaders', array_merge($current, $headers)); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizeCustomHttpHeader(): \Generator + { + yield 'extraHttpHeaders' => NormalizerFactory::json(); + } +} diff --git a/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php b/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php new file mode 100644 index 00000000..382e9fcf --- /dev/null +++ b/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php @@ -0,0 +1,35 @@ +getBodyBag()->set('emulatedMediaType', $mediaType); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizeEmulatedMediaType(): \Generator + { + yield 'emulatedMediaType' => NormalizerFactory::enum(); + } +} diff --git a/src/Builder/Behaviors/Chromium/FailOnTrait.php b/src/Builder/Behaviors/Chromium/FailOnTrait.php new file mode 100644 index 00000000..35a5b753 --- /dev/null +++ b/src/Builder/Behaviors/Chromium/FailOnTrait.php @@ -0,0 +1,84 @@ + $statusCodes + */ + #[ExposeSemantic(new ArrayNodeBuilder('fail_on_http_status_codes', prototype: 'integer'))] + public function failOnHttpStatusCodes(array $statusCodes): static + { + $this->getBodyBag()->set('failOnHttpStatusCodes', $statusCodes); + + return $this; + } + + /** + * Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. + * (default None). (overrides any previous configuration). + * + * @see https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium + * + * @param list> $statusCodes + */ + #[ExposeSemantic(new ArrayNodeBuilder('fail_on_resource_http_status_codes', prototype: 'integer'))] + public function failOnResourceHttpStatusCodes(array $statusCodes): static + { + $this->getBodyBag()->set('failOnResourceHttpStatusCodes', $statusCodes); + + return $this; + } + + /** + * Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource. + * (default false). + * + * @see https://gotenberg.dev/docs/routes#network-errors-chromium + */ + #[ExposeSemantic(new BooleanNodeBuilder('fail_on_resource_loading_failed'))] + public function failOnResourceLoadingFailed(bool $bool = true): static + { + $this->getBodyBag()->set('failOnResourceLoadingFailed', $bool); + + return $this; + } + + /** + * Forces GotenbergPdf to return a 409 Conflict response if there are + * exceptions in the Chromium console. (default false). + * + * @see https://gotenberg.dev/docs/routes#console-exceptions + */ + #[ExposeSemantic(new BooleanNodeBuilder('fail_on_console_exceptions'))] + public function failOnConsoleExceptions(bool $bool = true): static + { + $this->getBodyBag()->set('failOnConsoleExceptions', $bool); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizeFailOn(): \Generator + { + yield 'failOnHttpStatusCodes' => NormalizerFactory::json(false); + yield 'failOnResourceHttpStatusCodes' => NormalizerFactory::json(false); + yield 'failOnResourceLoadingFailed' => NormalizerFactory::bool(); + yield 'failOnConsoleExceptions' => NormalizerFactory::bool(); + } +} diff --git a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php new file mode 100644 index 00000000..96f6cc17 --- /dev/null +++ b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php @@ -0,0 +1,247 @@ +getBodyBag()->set('singlePage', $bool); + + return $this; + } + + /** + * Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + */ + #[ExposeSemantic(new UnitNodeBuilder('paper_width'))] + public function paperWidth(float $value, Unit $unit = Unit::Inches): static + { + $this->getBodyBag()->set('paperWidth', $value.$unit->value); + + return $this; + } + + /** + * Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + */ + #[ExposeSemantic(new UnitNodeBuilder('paper_height'))] + public function paperHeight(float $value, Unit $unit = Unit::Inches): static + { + $this->getBodyBag()->set('paperHeight', $value.$unit->value); + + return $this; + } + + /** + * Overrides the default paper size, in inches. + * + * Examples of paper size (width x height): + * + * Letter - 8.5 x 11 (default) + * Legal - 8.5 x 14 + * Tabloid - 11 x 17 + * Ledger - 17 x 11 + * A0 - 33.1 x 46.8 + * A1 - 23.4 x 33.1 + * A2 - 16.54 x 23.4 + * A3 - 11.7 x 16.54 + * A4 - 8.27 x 11.7 + * A5 - 5.83 x 8.27 + * A6 - 4.13 x 5.83 + */ + public function paperSize(float $width, float $height, Unit $unit = Unit::Inches): static + { + $this->paperWidth($width, $unit); + $this->paperHeight($height, $unit); + + return $this; + } + + #[ExposeSemantic(new NativeEnumNodeBuilder('paper_standard_size', enumClass: PaperSize::class))] + public function paperStandardSize(PaperSizeInterface $paperSize): static + { + $this->paperWidth($paperSize->width(), $paperSize->unit()); + $this->paperHeight($paperSize->height(), $paperSize->unit()); + + return $this; + } + + /** + * Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + */ + #[ExposeSemantic(new UnitNodeBuilder('margin_top'))] + public function marginTop(float $value, Unit $unit = Unit::Inches): static + { + $this->getBodyBag()->set('marginTop', $value.$unit->value); + + return $this; + } + + /** + * Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + */ + #[ExposeSemantic(new UnitNodeBuilder('margin_bottom'))] + public function marginBottom(float $value, Unit $unit = Unit::Inches): static + { + $this->getBodyBag()->set('marginBottom', $value.$unit->value); + + return $this; + } + + /** + * Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + */ + #[ExposeSemantic(new UnitNodeBuilder('margin_left'))] + public function marginLeft(float $value, Unit $unit = Unit::Inches): static + { + $this->getBodyBag()->set('marginLeft', $value.$unit->value); + + return $this; + } + + /** + * Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + */ + #[ExposeSemantic(new UnitNodeBuilder('margin_right'))] + public function marginRight(float $value, Unit $unit = Unit::Inches): static + { + $this->getBodyBag()->set('marginRight', $value.$unit->value); + + return $this; + } + + /** + * Overrides the default margins (e.g., 0.39), in inches. + */ + public function margins(float $top, float $bottom, float $left, float $right, Unit $unit = Unit::Inches): static + { + $this->marginTop($top, $unit); + $this->marginBottom($bottom, $unit); + $this->marginLeft($left, $unit); + $this->marginRight($right, $unit); + + return $this; + } + + /** + * Define whether to prefer page size as defined by CSS. (Default false). + */ + #[ExposeSemantic(new BooleanNodeBuilder('prefer_css_page_size'))] + public function preferCssPageSize(bool $bool): static + { + $this->getBodyBag()->set('preferCssPageSize', $bool); + + return $this; + } + + /** + * Define whether the document outline should be embedded into the PDF. + */ + #[ExposeSemantic(new BooleanNodeBuilder('generate_document_outline'))] + public function generateDocumentOutline(bool $bool): static + { + $this->getBodyBag()->set('generateDocumentOutline', $bool); + + return $this; + } + + /** + * Prints the background graphics. (Default false). + */ + #[ExposeSemantic(new BooleanNodeBuilder('print_background'))] + public function printBackground(bool $bool): static + { + $this->getBodyBag()->set('printBackground', $bool); + + return $this; + } + + /** + * Hide the default white background and allow generating PDFs with transparency. + */ + #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] + public function omitBackground(bool $bool): static + { + $this->getBodyBag()->set('omitBackground', $bool); + + return $this; + } + + /** + * Set the paper orientation to landscape. (Default false). + */ + #[ExposeSemantic(new BooleanNodeBuilder('landscape'))] + public function landscape(bool $bool = true): static + { + $this->getBodyBag()->set('landscape', $bool); + + return $this; + } + + /** + * The scale of the page rendering (e.g., 1.0). (Default 1.0). + */ + #[ExposeSemantic(new FloatNodeBuilder('scale'))] + public function scale(float $scale): static + { + $this->getBodyBag()->set('scale', $scale); + + return $this; + } + + /** + * Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). + */ + #[ExposeSemantic(new ScalarNodeBuilder('native_page_ranges'))] + public function nativePageRanges(string $ranges): static + { + ValidatorFactory::range($ranges); + $this->getBodyBag()->set('nativePageRanges', $ranges); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizePageProperties(): \Generator + { + yield 'singlePage' => NormalizerFactory::bool(); + yield 'paperWidth' => NormalizerFactory::unit(); + yield 'paperHeight' => NormalizerFactory::unit(); + yield 'marginTop' => NormalizerFactory::unit(); + yield 'marginBottom' => NormalizerFactory::unit(); + yield 'marginLeft' => NormalizerFactory::unit(); + yield 'marginRight' => NormalizerFactory::unit(); + yield 'preferCssPageSize' => NormalizerFactory::bool(); + yield 'generateDocumentOutline' => NormalizerFactory::bool(); + yield 'printBackground' => NormalizerFactory::bool(); + yield 'omitBackground' => NormalizerFactory::bool(); + yield 'landscape' => NormalizerFactory::bool(); + yield 'scale' => NormalizerFactory::float(); + } +} diff --git a/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php b/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php new file mode 100644 index 00000000..741546b7 --- /dev/null +++ b/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php @@ -0,0 +1,31 @@ +getBodyBag()->set('skipNetworkIdleEvent', $bool); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizePerformanceMode(): \Generator + { + yield 'skipNetworkIdleEvent' => NormalizerFactory::bool(); + } +} diff --git a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php new file mode 100644 index 00000000..36d92950 --- /dev/null +++ b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php @@ -0,0 +1,112 @@ +getBodyBag()->set('width', $width); + + return $this; + } + + /** + * The device screen width in pixels. (Default 600). + */ + #[ExposeSemantic(new IntegerNodeBuilder('height'))] + public function height(int $height): static + { + $this->getBodyBag()->set('height', $height); + + return $this; + } + + /** + * Define whether to clip the screenshot according to the device dimensions. (Default false). + */ + #[ExposeSemantic(new BooleanNodeBuilder('clip'))] + public function clip(bool $bool = true): static + { + $this->getBodyBag()->set('clip', $bool); + + return $this; + } + + /** + * The image compression format, either "png", "jpeg" or "webp". (default png). + */ + #[ExposeSemantic(new NativeEnumNodeBuilder('format', enumClass: ScreenshotFormat::class))] + public function format(ScreenshotFormat $format): static + { + $this->getBodyBag()->set('format', $format); + + return $this; + } + + /** + * The compression quality from range 0 to 100 (jpeg only). (default 100). + * + * @param int<0, 100> $quality + */ + #[ExposeSemantic(new IntegerNodeBuilder('quality', min: 0, max: 100))] + public function quality(int $quality): static + { + $this->getBodyBag()->set('quality', $quality); + + return $this; + } + + /** + * Hides default white background and allows generating screenshot with + * transparency. (Default false). + */ + #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] + public function omitBackground(bool $bool = true): static + { + $this->getBodyBag()->set('omitBackground', $bool); + + return $this; + } + + /** + * Define whether to optimize image encoding for speed, not for resulting size. (Default false). + */ + #[ExposeSemantic(new BooleanNodeBuilder('optimize_for_speed'))] + public function optimizeForSpeed(bool $bool = true): static + { + $this->getBodyBag()->set('optimizeForSpeed', $bool); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizePageProperties(): \Generator + { + yield 'width' => NormalizerFactory::int(); + yield 'height' => NormalizerFactory::int(); + yield 'clip' => NormalizerFactory::bool(); + yield 'format' => NormalizerFactory::enum(); + yield 'quality' => NormalizerFactory::int(); + yield 'omitBackground' => NormalizerFactory::bool(); + yield 'optimizeForSpeed' => NormalizerFactory::bool(); + } +} diff --git a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php new file mode 100644 index 00000000..0da0c363 --- /dev/null +++ b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php @@ -0,0 +1,47 @@ +getBodyBag()->set('waitDelay', $delay); + + return $this; + } + + /** + * Sets the JavaScript expression to wait before converting an HTML + * document to PDF until it returns true. (default None). + * + * For instance: "window.status === 'ready'". + * + * @see https://gotenberg.dev/docs/routes#wait-before-rendering + */ + #[ExposeSemantic(new ScalarNodeBuilder('wait_for_expression'))] + public function waitForExpression(string $expression): static + { + $this->getBodyBag()->set('waitForExpression', $expression); + + return $this; + } +} diff --git a/src/Builder/Behaviors/ChromiumPdfTrait.php b/src/Builder/Behaviors/ChromiumPdfTrait.php new file mode 100644 index 00000000..6825585a --- /dev/null +++ b/src/Builder/Behaviors/ChromiumPdfTrait.php @@ -0,0 +1,21 @@ +dependencies->get('asset_base_dir_formatter'); + } +} diff --git a/src/Builder/Behaviors/Dependencies/DependencyAwareTrait.php b/src/Builder/Behaviors/Dependencies/DependencyAwareTrait.php new file mode 100644 index 00000000..6a37e696 --- /dev/null +++ b/src/Builder/Behaviors/Dependencies/DependencyAwareTrait.php @@ -0,0 +1,10 @@ +dependencies->has('logger') + || !($logger = $this->dependencies->get('logger')) instanceof LoggerInterface) { + return null; + } + + return $logger; + } +} diff --git a/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php b/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php new file mode 100644 index 00000000..55187456 --- /dev/null +++ b/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php @@ -0,0 +1,23 @@ +dependencies->has('request_stack') + || !($requestStack = $this->dependencies->get('request_stack')) instanceof RequestStack + ) { + throw new \LogicException(\sprintf('RequestStack is required to use "%s" method. Try to run "composer require symfony/http-foundation".', __METHOD__)); + } + + return $requestStack->getCurrentRequest(); + } +} diff --git a/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php b/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php new file mode 100644 index 00000000..ef3e6b6d --- /dev/null +++ b/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php @@ -0,0 +1,22 @@ +dependencies->has('twig') + || !($environment = $this->dependencies->get('twig')) instanceof Environment + ) { + throw new \LogicException(\sprintf('Twig is required to use "%s" method. Try to run "composer require symfony/twig-bundle".', __METHOD__)); + } + + return $environment; + } +} diff --git a/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php b/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php new file mode 100644 index 00000000..6fa09d9e --- /dev/null +++ b/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php @@ -0,0 +1,22 @@ +dependencies->has('router') + || !($urlGenerator = $this->dependencies->get('router')) instanceof UrlGeneratorInterface + ) { + throw new \LogicException(\sprintf('UrlGenerator is required to use "%s" method. Try to run "composer require symfony/routing".', __METHOD__)); + } + + return $urlGenerator; + } +} diff --git a/src/Builder/Behaviors/DownloadFromTrait.php b/src/Builder/Behaviors/DownloadFromTrait.php new file mode 100644 index 00000000..e6b398f7 --- /dev/null +++ b/src/Builder/Behaviors/DownloadFromTrait.php @@ -0,0 +1,58 @@ +}> $downloadFrom + */ + #[ExposeSemantic(new ArrayNodeBuilder('download_from', prototype: 'array', children: [ + new ScalarNodeBuilder('url', required: true, restrictTo: 'string'), + new ArrayNodeBuilder('extraHttpHeaders', useAttributeAsKey: 'name', prototype: 'array', children: [ + new ScalarNodeBuilder('name', required: true), + new ScalarNodeBuilder('value', required: true), + ]), + ]))] + public function downloadFrom(array $downloadFrom): static + { + ValidatorFactory::download($downloadFrom); + if ([] === $downloadFrom) { + $this->getBodyBag()->unset('downloadFrom'); + + return $this; + } + + $value = $this->getBodyBag()->get('downloadFrom', []); + + foreach ($downloadFrom as $file) { + $value[$file['url']] = $file; + } + + $this->getBodyBag()->set('downloadFrom', $value); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizeDownloadFrom(): \Generator + { + yield 'downloadFrom' => NormalizerFactory::json(false); + } +} diff --git a/src/Builder/Behaviors/FlattenTrait.php b/src/Builder/Behaviors/FlattenTrait.php new file mode 100644 index 00000000..2e558d90 --- /dev/null +++ b/src/Builder/Behaviors/FlattenTrait.php @@ -0,0 +1,34 @@ +getBodyBag()->set('flatten', $bool); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizeFlatten(): \Generator + { + yield 'flatten' => NormalizerFactory::bool(); + } +} diff --git a/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php b/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php new file mode 100644 index 00000000..1f4861a8 --- /dev/null +++ b/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php @@ -0,0 +1,318 @@ +getBodyBag()->set('password', $password); + + return $this; + } + + /** + * Set the paper orientation to landscape. + */ + #[ExposeSemantic(new BooleanNodeBuilder('landscape'))] + public function landscape(bool $bool = true): static + { + $this->getBodyBag()->set('landscape', $bool); + + return $this; + } + + /** + * Page ranges to print, e.g., '1-4' - empty means all pages. + */ + #[ExposeSemantic(new ScalarNodeBuilder('native_page_ranges'))] + public function nativePageRanges(string $ranges): static + { + ValidatorFactory::range($ranges); + $this->getBodyBag()->set('nativePageRanges', $ranges); + + return $this; + } + + /** + * Specify whether form fields are exported as widgets or only their fixed print representation is exported. + */ + #[ExposeSemantic(new BooleanNodeBuilder('do_not_export_form_fields'))] + public function doNotExportFormFields(bool $bool = false): static + { + $this->getBodyBag()->set('exportFormFields', $bool); + + return $this; + } + + /** + * Specify whether multiple form fields exported are allowed to have the same field name. + */ + #[ExposeSemantic(new BooleanNodeBuilder('allow_duplicate_field_names'))] + public function allowDuplicateFieldNames(bool $bool = true): static + { + $this->getBodyBag()->set('allowDuplicateFieldNames', $bool); + + return $this; + } + + /** + * Specify if bookmarks are exported to PDF. + */ + #[ExposeSemantic(new BooleanNodeBuilder('do_not_export_bookmarks'))] + public function doNotExportBookmarks(bool $bool = false): static + { + $this->getBodyBag()->set('exportBookmarks', $bool); + + return $this; + } + + /** + * Specify that the bookmarks contained in the source LibreOffice file should be exported to the PDF file as Named Destination. + */ + #[ExposeSemantic(new BooleanNodeBuilder('export_bookmarks_to_pdf_destination'))] + public function exportBookmarksToPdfDestination(bool $bool = true): static + { + $this->getBodyBag()->set('exportBookmarksToPdfDestination', $bool); + + return $this; + } + + /** + * Export the placeholders fields visual markings only. The exported placeholder is ineffective. + */ + #[ExposeSemantic(new BooleanNodeBuilder('export_placeholders'))] + public function exportPlaceholders(bool $bool = true): static + { + $this->getBodyBag()->set('exportPlaceholders', $bool); + + return $this; + } + + /** + * Specify if notes are exported to PDF. + */ + #[ExposeSemantic(new BooleanNodeBuilder('export_notes'))] + public function exportNotes(bool $bool = true): static + { + $this->getBodyBag()->set('exportNotes', $bool); + + return $this; + } + + /** + * Specify if notes pages are exported to PDF. Notes pages are available in Impress documents only. + */ + #[ExposeSemantic(new BooleanNodeBuilder('export_notes_pages'))] + public function exportNotesPages(bool $bool = true): static + { + $this->getBodyBag()->set('exportNotesPages', $bool); + + return $this; + } + + /** + * Specify, if the form field exportNotesPages is set to true, if only notes pages are exported to PDF. + */ + #[ExposeSemantic(new BooleanNodeBuilder('export_only_notes_pages'))] + public function exportOnlyNotesPages(bool $bool = true): static + { + $this->getBodyBag()->set('exportOnlyNotesPages', $bool); + + return $this; + } + + /** + * Specify if notes in margin are exported to PDF. + */ + #[ExposeSemantic(new BooleanNodeBuilder('export_notes_in_margin'))] + public function exportNotesInMargin(bool $bool = true): static + { + $this->getBodyBag()->set('exportNotesInMargin', $bool); + + return $this; + } + + /** + * Specify that the target documents with .od[tpgs] extension, will have that extension changed to .pdf when the link is exported to PDF. The source document remains untouched. + */ + #[ExposeSemantic(new BooleanNodeBuilder('convert_ooo_target_to_pdf_target'))] + public function convertOooTargetToPdfTarget(bool $bool = true): static + { + $this->getBodyBag()->set('convertOooTargetToPdfTarget', $bool); + + return $this; + } + + /** + * Specify that the file system related hyperlinks (file:// protocol) present in the document will be exported as relative to the source document location. + */ + #[ExposeSemantic(new BooleanNodeBuilder('export_links_relative_fsys'))] + public function exportLinksRelativeFsys(bool $bool = true): static + { + $this->getBodyBag()->set('exportLinksRelativeFsys', $bool); + + return $this; + } + + /** + * Export, for LibreOffice Impress, slides that are not included in slide shows. + */ + #[ExposeSemantic(new BooleanNodeBuilder('export_hidden_slides'))] + public function exportHiddenSlides(bool $bool = true): static + { + $this->getBodyBag()->set('exportHiddenSlides', $bool); + + return $this; + } + + /** + * Specify that automatically inserted empty pages are suppressed. This option is active only if storing Writer documents. + */ + #[ExposeSemantic(new BooleanNodeBuilder('skip_empty_pages'))] + public function skipEmptyPages(bool $bool = true): static + { + $this->getBodyBag()->set('skipEmptyPages', $bool); + + return $this; + } + + /** + * Specify that a stream is inserted to the PDF file which contains the original document for archiving purposes. + */ + #[ExposeSemantic(new BooleanNodeBuilder('add_original_document_as_stream'))] + public function addOriginalDocumentAsStream(bool $bool = true): static + { + $this->getBodyBag()->set('addOriginalDocumentAsStream', $bool); + + return $this; + } + + /** + * Ignore each sheet’s paper size, print ranges and shown/hidden status and puts every sheet (even hidden sheets) on exactly one page. + */ + #[ExposeSemantic(new BooleanNodeBuilder('single_page_sheets'))] + public function singlePageSheets(bool $bool = true): static + { + $this->getBodyBag()->set('singlePageSheets', $bool); + + return $this; + } + + /** + * Merge alphanumerically the resulting PDFs. + */ + #[ExposeSemantic(new BooleanNodeBuilder('merge'))] + public function merge(bool $bool = true): self + { + $this->getBodyBag()->set('merge', $bool); + + return $this; + } + + /** + * Specify if images are exported to PDF using a lossless compression format like PNG or compressed using the JPEG format. + */ + #[ExposeSemantic(new BooleanNodeBuilder('lossless_image_compression'))] + public function losslessImageCompression(bool $bool = true): self + { + $this->getBodyBag()->set('losslessImageCompression', $bool); + + return $this; + } + + /** + * Specify the quality of the JPG export. A higher value produces a higher-quality image and a larger file. Between 1 and 100. + * + * @param int<0, 100> $quality + */ + #[ExposeSemantic(new IntegerNodeBuilder('quality', min: 0, max: 100))] + public function quality(int $quality): self + { + ValidatorFactory::quality($quality); + $this->getBodyBag()->set('quality', $quality); + + return $this; + } + + /** + * Specify if the resolution of each image is reduced to the resolution specified by the form field maxImageResolution. + */ + #[ExposeSemantic(new BooleanNodeBuilder('reduce_image_resolution'))] + public function reduceImageResolution(bool $bool = true): self + { + $this->getBodyBag()->set('reduceImageResolution', $bool); + + return $this; + } + + /** + * If the form field reduceImageResolution is set to true, tell if all images will be reduced to the given value in DPI. Possible values are: 75, 150, 300, 600 and 1200. + */ + #[ExposeSemantic(new NativeEnumNodeBuilder('max_image_resolution', enumClass: ImageResolutionDPI::class))] + public function maxImageResolution(ImageResolutionDPI|null $resolution): self + { + if (!$resolution) { + $this->getBodyBag()->unset('maxImageResolution'); + } else { + $this->getBodyBag()->set('maxImageResolution', $resolution); + } + + return $this; + } + + /** + * Specify whether to update the indexes before conversion, keeping in mind that doing so might result in missing links in the final PDF. + */ + #[ExposeSemantic(new BooleanNodeBuilder('update_indexes'))] + public function doNotUpdateIndexes(bool $bool = false): self + { + $this->getBodyBag()->set('updateIndexes', $bool); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizePageProperties(): \Generator + { + yield 'landscape' => NormalizerFactory::bool(); + yield 'exportFormFields' => NormalizerFactory::bool(); + yield 'allowDuplicateFieldNames' => NormalizerFactory::bool(); + yield 'exportBookmarks' => NormalizerFactory::bool(); + yield 'exportBookmarksToPdfDestination' => NormalizerFactory::bool(); + yield 'exportPlaceholders' => NormalizerFactory::bool(); + yield 'exportNotes' => NormalizerFactory::bool(); + yield 'exportNotesPages' => NormalizerFactory::bool(); + yield 'exportOnlyNotesPages' => NormalizerFactory::bool(); + yield 'exportNotesInMargin' => NormalizerFactory::bool(); + yield 'convertOooTargetToPdfTarget' => NormalizerFactory::bool(); + yield 'exportLinksRelativeFsys' => NormalizerFactory::bool(); + yield 'exportHiddenSlides' => NormalizerFactory::bool(); + yield 'skipEmptyPages' => NormalizerFactory::bool(); + yield 'addOriginalDocumentAsStream' => NormalizerFactory::bool(); + yield 'singlePageSheets' => NormalizerFactory::bool(); + yield 'merge' => NormalizerFactory::bool(); + yield 'losslessImageCompression' => NormalizerFactory::bool(); + yield 'quality' => NormalizerFactory::int(); + yield 'reduceImageResolution' => NormalizerFactory::bool(); + yield 'maxImageResolution' => NormalizerFactory::enum(); + yield 'updateIndexes' => NormalizerFactory::bool(); + } +} diff --git a/src/Builder/Behaviors/LibreOfficeTrait.php b/src/Builder/Behaviors/LibreOfficeTrait.php new file mode 100644 index 00000000..9d49437d --- /dev/null +++ b/src/Builder/Behaviors/LibreOfficeTrait.php @@ -0,0 +1,14 @@ +getBodyBag()->set('metadata', $metadata); + + return $this; + } + + /** + * The metadata to write. + */ + public function addMetadata(string $key, string $value): static + { + $this->getBodyBag()->set('metadata', [$key => $value] + $this->getBodyBag()->get('metadata', [])); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizeMetadata(): \Generator + { + yield 'metadata' => NormalizerFactory::json(); + } +} diff --git a/src/Builder/Behaviors/PdfFormatTrait.php b/src/Builder/Behaviors/PdfFormatTrait.php new file mode 100644 index 00000000..041b55a2 --- /dev/null +++ b/src/Builder/Behaviors/PdfFormatTrait.php @@ -0,0 +1,52 @@ +getBodyBag()->unset('pdfa'); + } else { + $this->getBodyBag()->set('pdfa', $format); + } + + return $this; + } + + /** + * Enable PDF for Universal Access for optimal accessibility. (default false). + */ + #[ExposeSemantic(new BooleanNodeBuilder('pdf_universal_access'))] + public function pdfUniversalAccess(bool $bool = true): self + { + $this->getBodyBag()->set('pdfua', $bool); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizePdfFormat(): \Generator + { + yield 'pdfa' => NormalizerFactory::enum(); + yield 'pdfua' => NormalizerFactory::bool(); + } +} diff --git a/src/Builder/Behaviors/SplitTrait.php b/src/Builder/Behaviors/SplitTrait.php new file mode 100644 index 00000000..d5deb8bf --- /dev/null +++ b/src/Builder/Behaviors/SplitTrait.php @@ -0,0 +1,66 @@ +getBodyBag()->unset('splitMode'); + } else { + $this->getBodyBag()->set('splitMode', $splitMode); + } + + return $this; + } + + /** + * Either the intervals or the page ranges to extract, depending on the selected mode. (default None). + */ + #[ExposeSemantic(new ScalarNodeBuilder('split_span'))] + public function splitSpan(string $splitSpan): self + { + ValidatorFactory::splitSpan($splitSpan); + $this->getBodyBag()->set('splitSpan', $splitSpan); + + return $this; + } + + /** + * Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). + */ + #[ExposeSemantic(new BooleanNodeBuilder('split_unify'))] + public function splitUnify(bool $bool = true): self + { + $this->getBodyBag()->set('splitUnify', $bool); + + return $this; + } + + #[NormalizeGotenbergPayload] + private function normalizeSplit(): \Generator + { + yield 'splitMode' => NormalizerFactory::enum(); + yield 'splitUnify' => NormalizerFactory::bool(); + } +} diff --git a/src/Builder/Behaviors/WebhookTrait.php b/src/Builder/Behaviors/WebhookTrait.php new file mode 100644 index 00000000..20f1db42 --- /dev/null +++ b/src/Builder/Behaviors/WebhookTrait.php @@ -0,0 +1,193 @@ +}, + * method: 'PUT'|'PATCH'|'POST'|null + * }, + * error?: array{ + * url?: string, + * route?: string|array{0: string, 1?: array}, + * method: 'PUT'|'PATCH'|'POST'|null + * }, + * extra_http_headers?: array + * } + */ +trait WebhookTrait +{ + use UrlGeneratorAwareTrait; + + abstract protected function getHeadersBag(): HeadersBag; + + /** + * @param WebhookConfiguration $webhook + */ + #[ExposeSemantic(new WebhookNodeBuilder('webhook', children: [ + new ScalarNodeBuilder('config_name', restrictTo: 'string'), + new ArrayNodeBuilder('success', children: [ + new ScalarNodeBuilder('url', restrictTo: 'string'), + new VariableNodeBuilder('route'), + new EnumNodeBuilder('method', values: ['POST', 'PUT', 'PATCH']), + ]), + new ArrayNodeBuilder('error', children: [ + new ScalarNodeBuilder('url', restrictTo: 'string'), + new VariableNodeBuilder('route'), + new EnumNodeBuilder('method', values: ['POST', 'PUT', 'PATCH']), + ]), + new ArrayNodeBuilder('extra_http_headers', normalizeKeys: false, useAttributeAsKey: 'name', prototype: 'variable'), + ]))] + public function webhook(array $webhook): static + { + if ([] === $webhook) { + $this->getHeadersBag()->unset('Gotenberg-Webhook-Url'); + $this->getHeadersBag()->unset('Gotenberg-Webhook-Method'); + $this->getHeadersBag()->unset('Gotenberg-Webhook-Error-Url'); + $this->getHeadersBag()->unset('Gotenberg-Webhook-Error-Method'); + $this->getHeadersBag()->unset('Gotenberg-Webhook-Extra-Http-Headers'); + + return $this; + } + + $this->webhookConfigurationValidator($webhook); + + if (isset($webhook['success']['route'])) { + if (\is_string($webhook['success']['route'])) { + $this->webhookRoute($webhook['success']['route'], method: $webhook['success']['method'] ?? null); + } + + if (\is_array($webhook['success']['route'])) { + $route = $webhook['success']['route']; + $this->webhookRoute($route[0], $route[1] ?? [], $webhook['success']['method'] ?? null); + } + } + + if (isset($webhook['error']['route'])) { + if (\is_string($webhook['error']['route'])) { + $this->webhookErrorRoute($webhook['error']['route'], method: $webhook['error']['method'] ?? null); + } + + if (\is_array($webhook['error']['route'])) { + $route = $webhook['error']['route']; + $this->webhookErrorRoute($route[0], $route[1] ?? [], $webhook['error']['method'] ?? null); + } + } + + if (isset($webhook['success']['url'])) { + $this->webhookUrl($webhook['success']['url'], $webhook['success']['method'] ?? null); + } + + if (isset($webhook['error']['url'])) { + $this->webhookErrorUrl($webhook['error']['url'], $webhook['error']['method'] ?? null); + } + + if (isset($webhook['extra_http_headers'])) { + $this->webhookExtraHeaders($webhook['extra_http_headers']); + } + + return $this; + } + + /** + * @param 'POST'|'PUT'|'PATCH'|null $method + */ + public function webhookUrl(string $url, string|null $method = null): static + { + $this->getHeadersBag()->set('Gotenberg-Webhook-Url', $url); + if ($method) { + $this->getHeadersBag()->set('Gotenberg-Webhook-Method', $method); + } + + return $this; + } + + /** + * @param 'POST'|'PUT'|'PATCH'|null $method + */ + public function webhookErrorUrl(string $url, string|null $method = null): static + { + $this->getHeadersBag()->set('Gotenberg-Webhook-Error-Url', $url); + if ($method) { + $this->getHeadersBag()->set('Gotenberg-Webhook-Error-Method', $method); + } + + return $this; + } + + /** + * @param array $extraHttpHeaders + */ + public function webhookExtraHeaders(array $extraHttpHeaders): static + { + $this->getHeadersBag()->set('Gotenberg-Webhook-Extra-Http-Headers', json_encode($extraHttpHeaders)); + + return $this; + } + + /** + * @param array $parameters + * @param 'PATCH'|'POST'|'PUT'|null $method + */ + public function webhookRoute(string $route, array $parameters = [], string|null $method = null): static + { + return $this->webhookUrl($this->getUrlGenerator()->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL), $method); + } + + /** + * @param array $parameters + * @param 'PATCH'|'POST'|'PUT'|null $method + */ + public function webhookErrorRoute(string $route, array $parameters = [], string|null $method = null): static + { + return $this->webhookErrorUrl($this->getUrlGenerator()->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL), $method); + } + + /** + * @param WebhookConfiguration $webhook + */ + private function webhookConfigurationValidator(array $webhook): void + { + if (!isset($webhook['success'])) { + throw new InvalidBuilderConfiguration('Invalid webhook configuration : At least a "success" key is required.'); + } + + foreach (['success', 'error'] as $type) { + if (isset($webhook[$type]['url'], $webhook[$type]['route'])) { + throw new InvalidBuilderConfiguration(\sprintf('Invalid webhook configuration : You must provide "url" or "route" keys for "%s" configuration.', $type)); + } + + if (isset($webhook[$type]['method']) && !\in_array($webhook[$type]['method'], ['POST', 'PUT', 'PATCH'], true)) { + throw new InvalidBuilderConfiguration(\sprintf('Invalid webhook configuration : "POST" "PUT", "PATCH" are the only available methods for "%s" configuration.', $type)); + } + + if (isset($webhook[$type]['route']) && \is_array($webhook[$type]['route'])) { + $route = $webhook[$type]['route']; + + if (!\is_string($route[0])) { + throw new InvalidBuilderConfiguration(\sprintf('Invalid webhook configuration : You must provide a valid route name for "%s" configuration.', $type)); + } + + if (!\is_array($route[1] ?? [])) { + throw new InvalidBuilderConfiguration(\sprintf('Invalid webhook configuration : You must provide valid route parameters for "%s" configuration.', $type)); + } + } + } + } +} diff --git a/src/Builder/BodyBag.php b/src/Builder/BodyBag.php new file mode 100644 index 00000000..54eaacba --- /dev/null +++ b/src/Builder/BodyBag.php @@ -0,0 +1,41 @@ + $data + */ + public function __construct( + private array $data = [], + ) { + } + + public function get(string $name, mixed $default = null): mixed + { + return $this->data[$name] ?? $default; + } + + public function set(string $name, mixed $value): static + { + $this->data[$name] = $value; + + return $this; + } + + public function unset(string $name): static + { + unset($this->data[$name]); + + return $this; + } + + /** + * @return array + */ + public function all(): array + { + return $this->data; + } +} diff --git a/src/Builder/BuilderAssetInterface.php b/src/Builder/BuilderAssetInterface.php new file mode 100644 index 00000000..68940319 --- /dev/null +++ b/src/Builder/BuilderAssetInterface.php @@ -0,0 +1,8 @@ + $cookies - */ - abstract public function cookies(array $cookies): static; - - /** - * @param array{cookies?: array} $formFields - * @param list $cookies - */ - private function withCookies(array &$formFields, array $cookies): static - { - if ([] === $cookies) { - unset($formFields['cookies']); - - return $this; - } - - $formFields['cookies'] = []; - - foreach ($cookies as $cookie) { - if ($cookie instanceof Cookie) { - $this->setCookie($cookie->getName(), $cookie); - - continue; - } - - $this->setCookie($cookie['name'], $cookie); - } - - return $this; - } - - /** - * @param Cookie|array{name: string, value: string, domain: string, path?: string|null, secure?: bool|null, httpOnly?: bool|null, sameSite?: 'Strict'|'Lax'|null} $cookie - */ - abstract public function setCookie(string $key, Cookie|array $cookie): static; - - /** - * @param array{cookies?: array} $formFields - * @param Cookie|array{name: string, value: string, domain: string, path?: string|null, secure?: bool|null, httpOnly?: bool|null, sameSite?: 'Strict'|'Lax'|null} $cookie - */ - private function withCookie(array &$formFields, string $key, Cookie|array $cookie): static - { - $formFields['cookies'] ??= []; - $formFields['cookies'][$key] = $cookie; - - return $this; - } - - /** - * Add cookies to store in the Chromium cookie jar. - * - * @see https://gotenberg.dev/docs/routes#cookies-chromium - * - * @param list $cookies - */ - public function addCookies(array $cookies): static - { - foreach ($cookies as $cookie) { - if ($cookie instanceof Cookie) { - $this->setCookie($cookie->getName(), $cookie); - - continue; - } - - $this->setCookie($cookie['name'], $cookie); - } - - return $this; - } - - private function forwardCookieFromRequest(Request|null $request, string $key, LoggerInterface|null $logger = null): static - { - if (null === $request) { - $logger?->debug('Cookie {sensiolabs_gotenberg.cookie_name} cannot be forwarded because there is no Request.', [ - 'sensiolabs_gotenberg.cookie_name' => $key, - ]); - - return $this; - } - - if (false === $request->cookies->has($key)) { - $logger?->debug('Cookie {sensiolabs_gotenberg.cookie_name} does not exists.', [ - 'sensiolabs_gotenberg.cookie_name' => $key, - ]); - - return $this; - } - - $value = $request->cookies->get($key); - $domain = $request->getHost(); - - return $this->setCookie($key, [ - 'name' => $key, - 'value' => $value, - 'domain' => $domain, - ]); - } - - abstract public function forwardCookie(string $name): static; - - /** - * @param (\Closure(string, mixed): array) $encoder - * - * @return array|string|\Stringable|int|float|bool|\BackedEnum|DataPart> - */ - private function cookieNormalizer(mixed $value, callable $encoder): array - { - $cookies = array_values($value); - $data = []; - - foreach ($cookies as $cookie) { - if ($cookie instanceof Cookie) { - $data[] = [ - 'name' => $cookie->getName(), - 'value' => $cookie->getValue(), - 'domain' => $cookie->getDomain(), - 'path' => $cookie->getPath(), - 'secure' => $cookie->isSecure(), - 'httpOnly' => $cookie->isHttpOnly(), - 'sameSite' => null !== ($sameSite = $cookie->getSameSite()) ? ucfirst(strtolower($sameSite)) : null, - ]; - - continue; - } - - $data[] = $cookie; - } - - return $encoder('cookies', $data); - } -} diff --git a/src/Builder/DefaultBuilderTrait.php b/src/Builder/DefaultBuilderTrait.php deleted file mode 100644 index d125a2b4..00000000 --- a/src/Builder/DefaultBuilderTrait.php +++ /dev/null @@ -1,226 +0,0 @@ - - */ - protected array $formFields = []; - - /** - * @var array|string|\Stringable|int|float|bool|\BackedEnum|DataPart>)> - */ - private array $normalizers = []; - - private string|null $fileName = null; - - private string $headerDisposition = HeaderUtils::DISPOSITION_INLINE; - - protected LoggerInterface|null $logger = null; - - /** @var ProcessorInterface|null */ - private ProcessorInterface|null $processor; - - public function setLogger(LoggerInterface|null $logger): void - { - $this->logger = $logger; - } - - /** - * @param (\Closure(mixed): array|string|\Stringable|int|float|bool|\BackedEnum|DataPart>) $normalizer - */ - protected function addNormalizer(string $key, \Closure $normalizer): void - { - $this->normalizers[$key] = $normalizer; - } - - /** - * @return array - */ - protected function encodeData(string $key, mixed $value): array - { - try { - $encodedValue = json_encode($value, \JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new JsonEncodingException(\sprintf('Could not encode property "%s" into JSON', $key), previous: $exception); - } - - return [$key => $encodedValue]; - } - - /** - * @param HeaderUtils::DISPOSITION_* $headerDisposition - */ - public function fileName(string $fileName, string $headerDisposition = HeaderUtils::DISPOSITION_INLINE): static - { - $this->fileName = $fileName; - $this->headerDisposition = $headerDisposition; - - return $this; - } - - /** - * @param ProcessorInterface $processor - */ - public function processor(ProcessorInterface $processor): static - { - $this->processor = $processor; - - return $this; - } - - /** - * The Gotenberg API endpoint path. - */ - abstract protected function getEndpoint(): string; - - /** - * @param array $configurations - */ - abstract public function setConfigurations(array $configurations): static; - - /** - * @param non-empty-list $validExtensions eg: ['png', 'jpeg'] - */ - protected function assertFileExtension(string $path, array $validExtensions): void - { - $file = new File($this->asset->resolve($path)); - $extension = $file->getExtension(); - - if (!\in_array($extension, $validExtensions, true)) { - throw new \InvalidArgumentException(\sprintf('The file extension "%s" is not valid in this context.', $extension)); - } - } - - /** - * Compiles the form values into a multipart form data array to send to the HTTP client. - * - * @return array> - */ - public function getMultipartFormData(): array - { - $multipartFormData = []; - - foreach ($this->formFields as $key => $value) { - if (null === $value) { - $this->logger?->debug('Key {sensiolabs_gotenberg.key} is null, skipping.', [ - 'sensiolabs_gotenberg.key' => $key, - ]); - - continue; - } - - $preCallback = null; - - if (\array_key_exists($key, $this->normalizers)) { - $this->logger?->debug('Normalizer found for key {sensiolabs_gotenberg.key}.', [ - 'sensiolabs_gotenberg.key' => $key, - ]); - $preCallback = $this->normalizers[$key](...); - } - - foreach ($this->convertToMultipartItems($key, $value, $preCallback) as $multiPart) { - $multipartFormData[] = $multiPart; - } - } - - return $multipartFormData; - } - - /** - * @param array|string|\Stringable|int|float|bool|\BackedEnum|DataPart $value - * - * @return list> - */ - private function convertToMultipartItems(string $key, array|string|\Stringable|int|float|bool|\BackedEnum|DataPart $value, \Closure|null $preCallback = null): array - { - if (null !== $preCallback) { - $result = []; - - foreach ($preCallback($value) as $innerKey => $innerValue) { - $result[] = $this->convertToMultipartItems($innerKey, $innerValue); - } - - return array_merge(...$result); - } - - if (\is_bool($value)) { - return [[ - $key => $value ? 'true' : 'false', - ]]; - } - - if (\is_int($value)) { - return [[ - $key => (string) $value, - ]]; - } - - if (\is_float($value)) { - [$left, $right] = sscanf((string) $value, '%d.%s') ?? [$value, '']; - - $right ??= '0'; - - return [[ - $key => "{$left}.{$right}", - ]]; - } - - if ($value instanceof \BackedEnum) { - return [[ - $key => (string) $value->value, - ]]; - } - - if ($value instanceof \Stringable) { - return [[ - $key => (string) $value, - ]]; - } - - if (\is_array($value)) { - $result = []; - foreach ($value as $nestedValue) { - $result[] = $this->convertToMultipartItems($key, $nestedValue); - } - - return array_merge(...$result); - } - - return [[ - $key => $value, - ]]; - } - - public function generate(): GotenbergFileResult - { - $this->logger?->debug('Processing file using {sensiolabs_gotenberg.builder} builder.', [ - 'sensiolabs_gotenberg.builder' => $this::class, - ]); - - $processor = $this->processor ?? new NullProcessor(); - - return new GotenbergFileResult( - $this->client->call($this->getEndpoint(), $this->getMultipartFormData()), - $processor($this->fileName), - $this->headerDisposition, - $this->fileName, - ); - } -} diff --git a/src/Builder/DownloadFromTrait.php b/src/Builder/DownloadFromTrait.php deleted file mode 100644 index e77909fc..00000000 --- a/src/Builder/DownloadFromTrait.php +++ /dev/null @@ -1,54 +0,0 @@ -}> $downloadFrom - */ - abstract public function downloadFrom(array $downloadFrom): static; - - /** - * @param array{downloadFrom?: array}>} $formFields - * @param list}> $downloadFrom - */ - private function withDownloadFrom(array &$formFields, array $downloadFrom): static - { - if ([] === $downloadFrom) { - unset($formFields['downloadFrom']); - - return $this; - } - - $formFields['downloadFrom'] = []; - - foreach ($downloadFrom as $file) { - if (!\array_key_exists('url', $file)) { - throw new MissingRequiredFieldException('Missing field "url"'); - } - - $formFields['downloadFrom'][$file['url']] = $file; - } - - return $this; - } - - /** - * @param array}> $value - * - * @return array|string|\Stringable|int|float|bool|\BackedEnum|DataPart> - */ - private function downloadFromNormalizer(array $value, callable $encoder): array - { - return $encoder('downloadFrom', array_values($value)); - } -} diff --git a/src/Builder/GotenbergFileResult.php b/src/Builder/GotenbergFileResult.php deleted file mode 100644 index d80094de..00000000 --- a/src/Builder/GotenbergFileResult.php +++ /dev/null @@ -1,85 +0,0 @@ - $processorGenerator - */ - public function __construct( - protected readonly GotenbergResponse $response, - protected readonly \Generator $processorGenerator, - protected readonly string $disposition, - protected readonly string|null $fileName = null, - ) { - } - - public function getStatusCode(): int - { - return $this->response->getStatusCode(); - } - - public function getHeaders(): ResponseHeaderBag - { - return $this->response->getHeaders(); - } - - public function getFileName(): string|null - { - return $this->response->getFileName(); - } - - /** - * @return non-negative-int|null - */ - public function getContentLength(): int|null - { - return $this->response->getContentLength(); - } - - public function process(): mixed - { - if (!$this->response->getStream()->valid()) { - throw new ProcessorException('Already processed query.'); - } - - foreach ($this->response->getStream() as $chunk) { - $this->processorGenerator->send($chunk); - } - - return $this->processorGenerator->getReturn(); - } - - public function stream(): StreamedResponse - { - $headers = $this->getHeaders(); - $headers->set('X-Accel-Buffering', 'no'); // See https://symfony.com/doc/current/components/http_foundation.html#streaming-a-json-response - if (null !== $this->fileName) { - $headers->set('Content-Disposition', HeaderUtils::makeDisposition($this->disposition, $this->fileName)); - } - - return new StreamedResponse( - function (): void { - if (!$this->response->getStream()->valid()) { - throw new ProcessorException('Already processed query.'); - } - - foreach ($this->response->getStream() as $chunk) { - $this->processorGenerator->send($chunk); - echo $chunk->getContent(); - flush(); - } - }, - $this->response->getStatusCode(), - $headers->all(), - ); - } -} diff --git a/src/Builder/HeadersBag.php b/src/Builder/HeadersBag.php new file mode 100644 index 00000000..e6e06811 --- /dev/null +++ b/src/Builder/HeadersBag.php @@ -0,0 +1,41 @@ + $data + */ + public function __construct( + private array $data = [], + ) { + } + + public function get(string $name, mixed $default = null): mixed + { + return $this->data[$name] ?? $default; + } + + public function set(string $name, mixed $value): static + { + $this->data[$name] = $value; + + return $this; + } + + public function unset(string $name): static + { + unset($this->data[$name]); + + return $this; + } + + /** + * @return array + */ + public function all(): array + { + return $this->data; + } +} diff --git a/src/Builder/Payload.php b/src/Builder/Payload.php new file mode 100644 index 00000000..3c2aaec8 --- /dev/null +++ b/src/Builder/Payload.php @@ -0,0 +1,59 @@ +> $bodyOptions + * @param array $headersOptions + */ + public function __construct( + private readonly array $bodyOptions, + private readonly array $headersOptions, + ) { + } + + /** + * Compiles the values into a FormDataPart to send to the HTTP client. + */ + public function getFormData(): FormDataPart + { + return new FormDataPart($this->bodyOptions); + } + + /** + * Compiles the values into Headers to send to the HTTP client. + */ + public function getHeaders(): Headers + { + $headers = new Headers(); + foreach ($this->headersOptions as $name => $value) { + if (null === $value) { + continue; + } + $headers->addHeader($name, $value); + } + + return $headers; + } + + /** + * @return list> + */ + public function getBodyOptions(): array + { + return $this->bodyOptions; + } + + /** + * @return array + */ + public function getHeadersOptions(): array + { + return $this->headersOptions; + } +} diff --git a/src/Builder/Pdf/AbstractChromiumPdfBuilder.php b/src/Builder/Pdf/AbstractChromiumPdfBuilder.php deleted file mode 100644 index 20666749..00000000 --- a/src/Builder/Pdf/AbstractChromiumPdfBuilder.php +++ /dev/null @@ -1,764 +0,0 @@ - function (mixed $value): array { - return $this->encodeData('extraHttpHeaders', $value); - }, - 'assets' => static function (array $value): array { - return ['files' => $value]; - }, - Part::Header->value => static function (DataPart $value): array { - return ['files' => $value]; - }, - Part::Body->value => static function (DataPart $value): array { - return ['files' => $value]; - }, - Part::Footer->value => static function (DataPart $value): array { - return ['files' => $value]; - }, - 'failOnHttpStatusCodes' => function (mixed $value): array { - return $this->encodeData('failOnHttpStatusCodes', $value); - }, - 'failOnResourceHttpStatusCodes' => function (mixed $value): array { - return $this->encodeData('failOnResourceHttpStatusCodes', $value); - }, - 'cookies' => fn (mixed $value): array => $this->cookieNormalizer($value, $this->encodeData(...)), - ]; - - foreach ($normalizers as $key => $normalizer) { - $this->addNormalizer($key, $normalizer); - } - } - - /** - * To set configurations by an array of configurations. - * - * @param array $configurations - */ - public function setConfigurations(array $configurations): static - { - foreach ($configurations as $property => $value) { - $this->addConfiguration($property, $value); - } - - return $this; - } - - public function cookies(array $cookies): static - { - return $this->withCookies($this->formFields, $cookies); - } - - public function setCookie(string $key, Cookie|array $cookie): static - { - return $this->withCookie($this->formFields, $key, $cookie); - } - - public function forwardCookie(string $name): static - { - return $this->forwardCookieFromRequest($this->requestStack->getCurrentRequest(), $name, $this->logger); - } - - /** - * Define whether to print the entire content in one single page. - * - * If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. - * - * @package Behavior\\Chromium\\PageProperties - */ - public function singlePage(bool $bool = true): static - { - $this->formFields['singlePage'] = $bool; - - return $this; - } - - /** - * Overrides the default paper size, in inches. - * - * Examples of paper size (width x height): - * - * Letter - 8.5 x 11 (default) - * Legal - 8.5 x 14 - * Tabloid - 11 x 17 - * Ledger - 17 x 11 - * A0 - 33.1 x 46.8 - * A1 - 23.4 x 33.1 - * A2 - 16.54 x 23.4 - * A3 - 11.7 x 16.54 - * A4 - 8.27 x 11.7 - * A5 - 5.83 x 8.27 - * A6 - 4.13 x 5.83 - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function paperSize(float $width, float $height, Unit $unit = Unit::Inches): static - { - $this->paperWidth($width, $unit); - $this->paperHeight($height, $unit); - - return $this; - } - - /** - * @package Behavior\\Chromium\\PageProperties - */ - public function paperStandardSize(PaperSizeInterface $paperSize): static - { - $this->paperWidth($paperSize->width(), $paperSize->unit()); - $this->paperHeight($paperSize->height(), $paperSize->unit()); - - return $this; - } - - /** - * @package Behavior\\Chromium\\PageProperties - */ - public function paperWidth(float $width, Unit $unit = Unit::Inches): static - { - $this->formFields['paperWidth'] = $width.$unit->value; - - return $this; - } - - /** - * @package Behavior\\Chromium\\PageProperties - */ - public function paperHeight(float $height, Unit $unit = Unit::Inches): static - { - $this->formFields['paperHeight'] = $height.$unit->value; - - return $this; - } - - /** - * Overrides the default margins (e.g., 0.39), in inches. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function margins(float $top, float $bottom, float $left, float $right, Unit $unit = Unit::Inches): static - { - $this->marginTop($top, $unit); - $this->marginBottom($bottom, $unit); - $this->marginLeft($left, $unit); - $this->marginRight($right, $unit); - - return $this; - } - - /** - * @package Behavior\\Chromium\\PageProperties - */ - public function marginTop(float $top, Unit $unit = Unit::Inches): static - { - $this->formFields['marginTop'] = $top.$unit->value; - - return $this; - } - - /** - * @package Behavior\\Chromium\\PageProperties - */ - public function marginBottom(float $bottom, Unit $unit = Unit::Inches): static - { - $this->formFields['marginBottom'] = $bottom.$unit->value; - - return $this; - } - - /** - * @package Behavior\\Chromium\\PageProperties - */ - public function marginLeft(float $left, Unit $unit = Unit::Inches): static - { - $this->formFields['marginLeft'] = $left.$unit->value; - - return $this; - } - - /** - * @package Behavior\\Chromium\\PageProperties - */ - public function marginRight(float $right, Unit $unit = Unit::Inches): static - { - $this->formFields['marginRight'] = $right.$unit->value; - - return $this; - } - - /** - * Define whether to prefer page size as defined by CSS. (Default false). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function preferCssPageSize(bool $bool = true): static - { - $this->formFields['preferCssPageSize'] = $bool; - - return $this; - } - - /** - * Define whether the document outline should be embedded into the PDF. (Default false). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function generateDocumentOutline(bool $bool = true): static - { - $this->formFields['generateDocumentOutline'] = $bool; - - return $this; - } - - /** - * Prints the background graphics. (Default false). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function printBackground(bool $bool = true): static - { - $this->formFields['printBackground'] = $bool; - - return $this; - } - - /** - * Hides default white background and allows generating PDFs with - * transparency. (Default false). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function omitBackground(bool $bool = true): static - { - $this->formFields['omitBackground'] = $bool; - - return $this; - } - - /** - * Sets the paper orientation to landscape. (Default false). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function landscape(bool $bool = true): static - { - $this->formFields['landscape'] = $bool; - - return $this; - } - - /** - * The scale of the page rendering (e.g., 1.0). (Default 1.0). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function scale(float $scale): static - { - $this->formFields['scale'] = $scale; - - return $this; - } - - /** - * Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function nativePageRanges(string $range): static - { - $this->formFields['nativePageRanges'] = $range; - - return $this; - } - - /** - * @param string $template #Template - * @param array $context - * - * @package Behavior\\Content - * - * @throws PdfPartRenderingException if the template could not be rendered - */ - public function header(string $template, array $context = []): static - { - return $this->withRenderedPart(Part::Header, $template, $context); - } - - /** - * @param string $template #Template - * @param array $context - * - * @package Behavior\\Content - * - * @throws PdfPartRenderingException if the template could not be rendered - */ - public function footer(string $template, array $context = []): static - { - return $this->withRenderedPart(Part::Footer, $template, $context); - } - - /** - * HTML file containing the header. (default None). - * - * @package Behavior\\Content - */ - public function headerFile(string $path): static - { - return $this->withPdfPartFile(Part::Header, $path); - } - - /** - * HTML file containing the footer. (default None). - * - * @package Behavior\\Content - */ - public function footerFile(string $path): static - { - return $this->withPdfPartFile(Part::Footer, $path); - } - - /** - * Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). - * - * @package Behavior\\Assets - */ - public function assets(string ...$paths): static - { - $this->formFields['assets'] = []; - - foreach ($paths as $path) { - $this->addAsset($path); - } - - return $this; - } - - /** - * Adds a file, like an image, font, stylesheet, and so on. - * - * @package Behavior\\Assets - */ - public function addAsset(string $path): static - { - $resolvedPath = $this->asset->resolve($path); - - $dataPart = new DataPart(new DataPartFile($resolvedPath)); - - $this->formFields['assets'][$resolvedPath] = $dataPart; - - return $this; - } - - /** - * Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML - * document before converting it to PDF. (default None). - * - * @see https://gotenberg.dev/docs/routes#wait-before-rendering - * - * @package Behavior\\Chromium\\WaitFor - */ - public function waitDelay(string $delay): static - { - $this->formFields['waitDelay'] = $delay; - - return $this; - } - - /** - * Sets the JavaScript expression to wait before converting an HTML - * document to PDF until it returns true. (default None). - * - * For instance: "window.status === 'ready'". - * - * @see https://gotenberg.dev/docs/routes#wait-before-rendering - * - * @package Behavior\\Chromium\\WaitFor - */ - public function waitForExpression(string $expression): static - { - $this->formFields['waitForExpression'] = $expression; - - return $this; - } - - /** - * Forces Chromium to emulate, either "screen" or "print". (default "print"). - * - * @see https://gotenberg.dev/docs/routes#console-exceptions - * - * @package Behavior\\MediaType - */ - public function emulatedMediaType(EmulatedMediaType $mediaType): static - { - $this->formFields['emulatedMediaType'] = $mediaType; - - return $this; - } - - /** - * Override the default User-Agent HTTP header. (default None). - * - * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium - * - * @param UserAgent::*|string $userAgent - * - * @package Behavior\\Http\\CustomHeaders - */ - public function userAgent(string $userAgent): static - { - $this->formFields['userAgent'] = $userAgent; - - return $this; - } - - /** - * Sets extra HTTP headers that Chromium will send when loading the HTML - * document. (default None). (overrides any previous headers). - * - * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium - * - * @param array $headers - * - * @package Behavior\\Http\\CustomHeaders - */ - public function extraHttpHeaders(array $headers): static - { - if ([] === $headers) { - unset($this->formFields['extraHttpHeaders']); - - return $this; - } - - $this->formFields['extraHttpHeaders'] = $headers; - - return $this; - } - - /** - * Adds extra HTTP headers that Chromium will send when loading the HTML - * document. (default None). - * - * @see https://gotenberg.dev/docs/routes#custom-http-headers - * - * @param array $headers - * - * @package Behavior\\Http\\CustomHeaders - */ - public function addExtraHttpHeaders(array $headers): static - { - if ([] === $headers) { - return $this; - } - - $this->formFields['extraHttpHeaders'] = array_merge($this->formFields['extraHttpHeaders'] ?? [], $headers); - - return $this; - } - - /** - * Return a 409 Conflict response if the HTTP status code from - * the main page is not acceptable. (default [499,599]). (overrides any previous configuration). - * - * @see https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium - * - * @param array $statusCodes - * - * @package Behavior\\FailOn - */ - public function failOnHttpStatusCodes(array $statusCodes): static - { - $this->formFields['failOnHttpStatusCodes'] = $statusCodes; - - return $this; - } - - /** - * Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. - * (default None). (overrides any previous configuration). - * - * @see https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium - * - * @param list> $statusCodes - * - * @package Behavior\\FailOn - */ - public function failOnResourceHttpStatusCodes(array $statusCodes): static - { - $this->formFields['failOnResourceHttpStatusCodes'] = $statusCodes; - - return $this; - } - - /** - * Forces GotenbergScreenshot to return a 409 Conflict response if there are - * exceptions load at least one resource. (default false). - * - * @see https://gotenberg.dev/docs/routes#network-errors-chromium - * - * @package Behavior\\FailOn - */ - public function failOnResourceLoadingFailed(bool $bool = true): static - { - $this->formFields['failOnResourceLoadingFailed'] = $bool; - - return $this; - } - - /** - * Forces GotenbergPdf to return a 409 Conflict response if there are - * exceptions in the Chromium console. (default false). - * - * @see https://gotenberg.dev/docs/routes#console-exceptions - * - * @package Behavior\\FailOn - */ - public function failOnConsoleExceptions(bool $bool = true): static - { - $this->formFields['failOnConsoleExceptions'] = $bool; - - return $this; - } - - /** - * @package Behavior\\Performance - */ - public function skipNetworkIdleEvent(bool $bool = true): static - { - $this->formFields['skipNetworkIdleEvent'] = $bool; - - return $this; - } - - /** - * Sets the PDF format of the resulting PDF. (default None). - * - * @See https://gotenberg.dev/docs/routes#pdfa-chromium. - */ - public function pdfFormat(PdfFormat|null $format = null): static - { - if (null === $format) { - unset($this->formFields['pdfa']); - - return $this; - } - - $this->formFields['pdfa'] = $format; - - return $this; - } - - /** - * Enable PDF for Universal Access for optimal accessibility. (default false). - * - * @See https://gotenberg.dev/docs/routes#pdfa-chromium. - */ - public function pdfUniversalAccess(bool $bool = true): static - { - $this->formFields['pdfua'] = $bool; - - return $this; - } - - /** - * Resets the metadata. - * - * @see https://gotenberg.dev/docs/routes#metadata-chromium - * @see https://exiftool.org/TagNames/XMP.html#pdf - * - * @param array $metadata - */ - public function metadata(array $metadata): static - { - $this->formFields['metadata'] = $metadata; - - return $this; - } - - /** - * The metadata to write. - */ - public function addMetadata(string $key, string $value): static - { - $this->formFields['metadata'] ??= []; - $this->formFields['metadata'][$key] = $value; - - return $this; - } - - /** - * Either intervals or pages. (default None). - * - * @see https://gotenberg.dev/docs/routes#split-chromium - */ - public function splitMode(SplitMode|null $splitMode = null): static - { - if (null === $splitMode) { - unset($this->formFields['splitMode']); - - return $this; - } - - $this->formFields['splitMode'] = $splitMode; - - return $this; - } - - /** - * Either the intervals or the page ranges to extract, depending on the selected mode. (default None). - * - * @see https://gotenberg.dev/docs/routes#split-chromium - */ - public function splitSpan(string $splitSpan): static - { - $this->formFields['splitSpan'] = $splitSpan; - - return $this; - } - - /** - * Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). - * - * @see https://gotenberg.dev/docs/routes#split-chromium - */ - public function splitUnify(bool $bool = true): static - { - $this->formFields['splitUnify'] = $bool; - - return $this; - } - - protected function withPdfPartFile(Part $pdfPart, string $path): static - { - $dataPart = new DataPart( - new DataPartFile($this->asset->resolve($path)), - $pdfPart->value, - ); - - $this->formFields[$pdfPart->value] = $dataPart; - - return $this; - } - - /** - * @param string $template #Template - * @param array $context - * - * @throws PdfPartRenderingException if the template could not be rendered - */ - protected function withRenderedPart(Part $pdfPart, string $template, array $context = []): static - { - if (!$this->twig instanceof Environment) { - throw new \LogicException(\sprintf('Twig is required to use "%s" method. Try to run "composer require symfony/twig-bundle".', __METHOD__)); - } - - $this->twig->getRuntime(GotenbergRuntime::class)->setBuilder($this); - - try { - $html = $this->twig->render($template, $context); - } catch (\Throwable $error) { - throw new PdfPartRenderingException(\sprintf('Could not render template "%s" into PDF part "%s". %s', $template, $pdfPart->value, $error->getMessage()), previous: $error); - } finally { - $this->twig->getRuntime(GotenbergRuntime::class)->setBuilder(null); - } - - $this->formFields[$pdfPart->value] = new DataPart($html, $pdfPart->value, 'text/html'); - - return $this; - } - - protected function addConfiguration(string $configurationName, mixed $value): void - { - match ($configurationName) { - 'header' => $this->header(...$value), - 'footer' => $this->footer(...$value), - 'single_page' => $this->singlePage($value), - 'pdf_format' => $this->pdfFormat(PdfFormat::from($value)), - 'pdf_universal_access' => $this->pdfUniversalAccess($value), - 'paper_standard_size' => $this->paperStandardSize(PaperSize::from($value)), - 'paper_width' => $this->paperWidth(...Unit::parse($value)), - 'paper_height' => $this->paperHeight(...Unit::parse($value)), - 'margin_top' => $this->marginTop(...Unit::parse($value)), - 'margin_bottom' => $this->marginBottom(...Unit::parse($value)), - 'margin_left' => $this->marginLeft(...Unit::parse($value)), - 'margin_right' => $this->marginRight(...Unit::parse($value)), - 'prefer_css_page_size' => $this->preferCssPageSize($value), - 'generate_document_outline' => $this->generateDocumentOutline($value), - 'print_background' => $this->printBackground($value), - 'omit_background' => $this->omitBackground($value), - 'landscape' => $this->landscape($value), - 'scale' => $this->scale($value), - 'native_page_ranges' => $this->nativePageRanges($value), - 'wait_delay' => $this->waitDelay($value), - 'wait_for_expression' => $this->waitForExpression($value), - 'emulated_media_type' => $this->emulatedMediaType(EmulatedMediaType::from($value)), - 'cookies' => $this->cookies($value), - 'user_agent' => $this->userAgent($value), - 'extra_http_headers' => $this->extraHttpHeaders($value), - 'fail_on_http_status_codes' => $this->failOnHttpStatusCodes($value), - 'fail_on_resource_http_status_codes' => $this->failOnResourceHttpStatusCodes($value), - 'fail_on_resource_loading_failed' => $this->failOnResourceLoadingFailed($value), - 'fail_on_console_exceptions' => $this->failOnConsoleExceptions($value), - 'skip_network_idle_event' => $this->skipNetworkIdleEvent($value), - 'metadata' => $this->metadata($value), - 'download_from' => $this->downloadFrom($value), - 'split_mode' => $this->splitMode(SplitMode::from($value)), - 'split_span' => $this->splitSpan($value), - 'split_unify' => $this->splitUnify($value), - 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/Builder/Pdf/AbstractPdfBuilder.php b/src/Builder/Pdf/AbstractPdfBuilder.php deleted file mode 100644 index 7215dfe8..00000000 --- a/src/Builder/Pdf/AbstractPdfBuilder.php +++ /dev/null @@ -1,43 +0,0 @@ -client = $gotenbergClient; - $this->asset = $asset; - $this->webhookConfigurationRegistry = $webhookConfigurationRegistry; - - $this->normalizers = [ - 'metadata' => function (mixed $value): array { - return $this->encodeData('metadata', $value); - }, - 'downloadFrom' => fn (array $value): array => $this->downloadFromNormalizer($value, $this->encodeData(...)), - ]; - } - - /** - * @param list}> $downloadFrom - */ - public function downloadFrom(array $downloadFrom): static - { - return $this->withDownloadFrom($this->formFields, $downloadFrom); - } -} diff --git a/src/Builder/Pdf/ConvertPdfBuilder.php b/src/Builder/Pdf/ConvertPdfBuilder.php index ab14219d..dc878ae6 100644 --- a/src/Builder/Pdf/ConvertPdfBuilder.php +++ b/src/Builder/Pdf/ConvertPdfBuilder.php @@ -2,91 +2,69 @@ namespace Sensiolabs\GotenbergBundle\Builder\Pdf; -use Sensiolabs\GotenbergBundle\Enumeration\PdfFormat; -use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; +use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; +use Sensiolabs\GotenbergBundle\Builder\Attributes\NormalizeGotenbergPayload; +use Sensiolabs\GotenbergBundle\Builder\Attributes\SemanticNode; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies\AssetBaseDirFormatterAwareTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\DownloadFromTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\PdfFormatTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\WebhookTrait; +use Sensiolabs\GotenbergBundle\Builder\Util\NormalizerFactory; +use Sensiolabs\GotenbergBundle\Builder\Util\ValidatorFactory; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Symfony\Component\Mime\Part\DataPart; -use Symfony\Component\Mime\Part\File as DataPartFile; -final class ConvertPdfBuilder extends AbstractPdfBuilder +/** + * @see https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route + */ +#[SemanticNode('convert')] +final class ConvertPdfBuilder extends AbstractBuilder { - private const ENDPOINT = '/forms/pdfengines/convert'; + use AssetBaseDirFormatterAwareTrait; + use DownloadFromTrait; + use PdfFormatTrait; + use WebhookTrait; - /** - * To set configurations by an array of configurations. - * - * @param array $configurations - */ - public function setConfigurations(array $configurations): static - { - foreach ($configurations as $property => $value) { - $this->addConfiguration($property, $value); - } - - return $this; - } - - /** - * Convert the resulting PDF into the given PDF/A format. - */ - public function pdfFormat(PdfFormat $format): self - { - $this->formFields['pdfa'] = $format->value; - - return $this; - } - - /** - * Enable PDF for Universal Access for optimal accessibility. - */ - public function pdfUniversalAccess(bool $bool = true): self - { - $this->formFields['pdfua'] = $bool; - - return $this; - } + public const ENDPOINT = '/forms/pdfengines/convert'; public function files(string|\Stringable ...$paths): self { - $this->formFields['files'] = []; - foreach ($paths as $path) { $path = (string) $path; - $this->assertFileExtension($path, ['pdf']); - - $dataPart = new DataPart(new DataPartFile($this->asset->resolve($path))); + $info = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); + ValidatorFactory::filesExtension([$info], ['pdf']); - $this->formFields['files'][$path] = $dataPart; + $files[$path] = $info; } + $this->getBodyBag()->set('files', $files ?? null); + return $this; } - public function getMultipartFormData(): array + protected function getEndpoint(): string { - if (!\array_key_exists('pdfa', $this->formFields) && !\array_key_exists('pdfua', $this->formFields)) { + return self::ENDPOINT; + } + + protected function validatePayloadBody(): void + { + if ($this->getBodyBag()->get('pdfa') === null && $this->getBodyBag()->get('pdfua') === null) { throw new MissingRequiredFieldException('At least "pdfa" or "pdfua" must be provided.'); } - if ([] === ($this->formFields['files'] ?? []) && [] === ($this->formFields['downloadFrom'] ?? [])) { - throw new MissingRequiredFieldException('At least one PDF file is required'); + if ($this->getBodyBag()->get('files') === null && $this->getBodyBag()->get('downloadFrom') === null) { + throw new MissingRequiredFieldException('At least one PDF file is required.'); } - - return parent::getMultipartFormData(); } - protected function getEndpoint(): string + #[NormalizeGotenbergPayload] + private function normalizeFiles(): \Generator { - return self::ENDPOINT; + yield 'files' => NormalizerFactory::asset(); } - private function addConfiguration(string $configurationName, mixed $value): void + public static function type(): string { - match ($configurationName) { - 'pdf_format' => $this->pdfFormat(PdfFormat::from($value)), - 'pdf_universal_access' => $this->pdfUniversalAccess($value), - 'download_from' => $this->downloadFrom($value), - default => throw new InvalidBuilderConfiguration(\sprintf('Invalid option "%s": no method does not exist in class "%s" to configured it.', $configurationName, static::class)), - }; + return 'pdf'; } } diff --git a/src/Builder/Pdf/FlattenPdfBuilder.php b/src/Builder/Pdf/FlattenPdfBuilder.php new file mode 100644 index 00000000..4dd02b7e --- /dev/null +++ b/src/Builder/Pdf/FlattenPdfBuilder.php @@ -0,0 +1,64 @@ +getAssetBaseDirFormatter()->resolve($path)); + ValidatorFactory::filesExtension([$info], ['pdf']); + + $files[$path] = $info; + } + + $this->getBodyBag()->set('files', $files ?? null); + + return $this; + } + + protected function getEndpoint(): string + { + return self::ENDPOINT; + } + + protected function validatePayloadBody(): void + { + if ($this->getBodyBag()->get('files') === null) { + throw new MissingRequiredFieldException('At least one PDF file is required.'); + } + } + + #[NormalizeGotenbergPayload] + private function normalizeFiles(): \Generator + { + yield 'files' => NormalizerFactory::asset(); + } + + public static function type(): string + { + return 'pdf'; + } +} diff --git a/src/Builder/Pdf/HtmlPdfBuilder.php b/src/Builder/Pdf/HtmlPdfBuilder.php index 31dc5240..78853a76 100644 --- a/src/Builder/Pdf/HtmlPdfBuilder.php +++ b/src/Builder/Pdf/HtmlPdfBuilder.php @@ -2,48 +2,37 @@ namespace Sensiolabs\GotenbergBundle\Builder\Pdf; +use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; +use Sensiolabs\GotenbergBundle\Builder\Attributes\SemanticNode; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\ChromiumPdfTrait; +use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; use Sensiolabs\GotenbergBundle\Enumeration\Part; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Exception\PdfPartRenderingException; -final class HtmlPdfBuilder extends AbstractChromiumPdfBuilder +/** + * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route + */ +#[SemanticNode('html')] +final class HtmlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { - private const ENDPOINT = '/forms/chromium/convert/html'; + use ChromiumPdfTrait; - /** - * @param string $template #Template - * @param array $context - * - * @package Behavior\\Content - * - * @throws PdfPartRenderingException if the template could not be rendered - */ - public function content(string $template, array $context = []): self - { - return $this->withRenderedPart(Part::Body, $template, $context); - } + public const ENDPOINT = '/forms/chromium/convert/html'; - /** - * The HTML file to convert into PDF. - * - * @package Behavior\\Content - */ - public function contentFile(string $path): self + protected function getEndpoint(): string { - return $this->withPdfPartFile(Part::Body, $path); + return self::ENDPOINT; } - public function getMultipartFormData(): array + protected function validatePayloadBody(): void { - if (!\array_key_exists(Part::Body->value, $this->formFields) && [] === ($this->formFields['downloadFrom'] ?? [])) { + if ($this->getBodyBag()->get(Part::Body->value) === null && $this->getBodyBag()->get('downloadFrom') === null) { throw new MissingRequiredFieldException('Content is required'); } - - return parent::getMultipartFormData(); } - protected function getEndpoint(): string + public static function type(): string { - return self::ENDPOINT; + return 'pdf'; } } diff --git a/src/Builder/Pdf/LibreOfficePdfBuilder.php b/src/Builder/Pdf/LibreOfficePdfBuilder.php index fb848976..975c05bf 100644 --- a/src/Builder/Pdf/LibreOfficePdfBuilder.php +++ b/src/Builder/Pdf/LibreOfficePdfBuilder.php @@ -2,17 +2,27 @@ namespace Sensiolabs\GotenbergBundle\Builder\Pdf; -use Sensiolabs\GotenbergBundle\Enumeration\ImageResolutionDPI; -use Sensiolabs\GotenbergBundle\Enumeration\PdfFormat; +use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; +use Sensiolabs\GotenbergBundle\Builder\Attributes\NormalizeGotenbergPayload; +use Sensiolabs\GotenbergBundle\Builder\Attributes\SemanticNode; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies\AssetBaseDirFormatterAwareTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\LibreOfficeTrait; +use Sensiolabs\GotenbergBundle\Builder\Util\NormalizerFactory; +use Sensiolabs\GotenbergBundle\Builder\Util\ValidatorFactory; use Sensiolabs\GotenbergBundle\Enumeration\SplitMode; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Symfony\Component\Mime\Part\DataPart; -use Symfony\Component\Mime\Part\File as DataPartFile; -final class LibreOfficePdfBuilder extends AbstractPdfBuilder +/** + * @see https://gotenberg.dev/docs/routes#convert-with-libreoffice + */ +#[SemanticNode('office')] +final class LibreOfficePdfBuilder extends AbstractBuilder { - private const ENDPOINT = '/forms/libreoffice/convert'; + use AssetBaseDirFormatterAwareTrait; + use LibreOfficeTrait; + + public const ENDPOINT = '/forms/libreoffice/convert'; private const AVAILABLE_EXTENSIONS = [ '123', '602', 'abw', 'bib', 'bmp', 'cdr', 'cgm', 'cmx', 'csv', 'cwk', 'dbf', 'dif', 'doc', 'docm', @@ -27,409 +37,48 @@ final class LibreOfficePdfBuilder extends AbstractPdfBuilder 'xltx', 'xlw', 'xml', 'xpm', 'zabw', ]; - /** - * To set configurations by an array of configurations. - * - * @param array $configurations - */ - public function setConfigurations(array $configurations): static - { - foreach ($configurations as $property => $value) { - $this->addConfiguration($property, $value); - } - - return $this; - } - - /** - * Set the password for opening the source file. - */ - public function password(#[\SensitiveParameter] string $password): self - { - $this->formFields['password'] = $password; - - return $this; - } - - /** - * Sets the paper orientation to landscape. - */ - public function landscape(bool $bool = true): self - { - $this->formFields['landscape'] = $bool; - - return $this; - } - - /** - * Page ranges to print, e.g., '1-4' - empty means all pages. - * - * If multiple files are provided, the page ranges will be applied independently to each file. - */ - public function nativePageRanges(string $range): self - { - $this->formFields['nativePageRanges'] = $range; - - return $this; - } - - /** - * Set whether to export the form fields or to use the inputted/selected content of the fields. - */ - public function doNotExportFormFields(bool $bool = false): self - { - $this->formFields['exportFormFields'] = $bool; - - return $this; - } - - /** - * Set whether to render the entire spreadsheet as a single page. - */ - public function singlePageSheets(bool $bool = true): self - { - $this->formFields['singlePageSheets'] = $bool; - - return $this; - } - - /** - * Convert the resulting PDF into the given PDF/A format. - */ - public function pdfFormat(PdfFormat $format): self - { - $this->formFields['pdfa'] = $format; - - return $this; - } - - /** - * Enable PDF for Universal Access for optimal accessibility. - */ - public function pdfUniversalAccess(bool $bool = true): self - { - $this->formFields['pdfua'] = $bool; - - return $this; - } - - /** - * Merge alphanumerically the resulting PDFs. - */ - public function merge(bool $bool = true): self - { - $this->formFields['merge'] = $bool; - - return $this; - } - /** * Adds office files to convert (overrides any previous files). */ public function files(string|\Stringable ...$paths): self { - $this->formFields['files'] = []; - foreach ($paths as $path) { $path = (string) $path; - $this->assertFileExtension($path, self::AVAILABLE_EXTENSIONS); - - $dataPart = new DataPart(new DataPartFile($this->asset->resolve($path))); + $info = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); + ValidatorFactory::filesExtension([$info], self::AVAILABLE_EXTENSIONS); - $this->formFields['files'][$path] = $dataPart; + $files[$path] = $info; } - return $this; - } - - /** - * Resets the metadata. - * - * @see https://gotenberg.dev/docs/routes#metadata-chromium - * @see https://exiftool.org/TagNames/XMP.html#pdf - * - * @param array $metadata - */ - public function metadata(array $metadata): self - { - $this->formFields['metadata'] = $metadata; - - return $this; - } - - /** - * The metadata to write. - */ - public function addMetadata(string $key, string $value): self - { - $this->formFields['metadata'] ??= []; - $this->formFields['metadata'][$key] = $value; - - return $this; - } - - /** - * Specify whether multiple form fields exported are allowed to have the same field name. - */ - public function allowDuplicateFieldNames(bool $bool = true): self - { - $this->formFields['allowDuplicateFieldNames'] = $bool; - - return $this; - } - - /** - * Specify if bookmarks are exported to PDF. - */ - public function doNotExportBookmarks(bool $bool = false): self - { - $this->formFields['exportBookmarks'] = $bool; - - return $this; - } - - /** - * Specify that the bookmarks contained in the source LibreOffice file should be exported to the PDF file as Named Destination. - */ - public function exportBookmarksToPdfDestination(bool $bool = true): self - { - $this->formFields['exportBookmarksToPdfDestination'] = $bool; - - return $this; - } - - /** - * Export the placeholders fields visual markings only. The exported placeholder is ineffective. - */ - public function exportPlaceholders(bool $bool = true): self - { - $this->formFields['exportPlaceholders'] = $bool; + $this->getBodyBag()->set('files', $files ?? null); return $this; } - /** - * Specify if notes are exported to PDF. - */ - public function exportNotes(bool $bool = true): self - { - $this->formFields['exportNotes'] = $bool; - - return $this; - } - - /** - * Specify if notes pages are exported to PDF. Notes pages are available in Impress documents only. - */ - public function exportNotesPages(bool $bool = true): self - { - $this->formFields['exportNotesPages'] = $bool; - - return $this; - } - - /** - * Specify, if the form field exportNotesPages is set to true, if only notes pages are exported to PDF. - */ - public function exportOnlyNotesPages(bool $bool = true): self - { - $this->formFields['exportOnlyNotesPages'] = $bool; - - return $this; - } - - /** - * Specify if notes in margin are exported to PDF. - */ - public function exportNotesInMargin(bool $bool = true): self - { - $this->formFields['exportNotesInMargin'] = $bool; - - return $this; - } - - /** - * Specify that the target documents with .od[tpgs] extension, will have that extension changed to .pdf when the link is exported to PDF. The source document remains untouched. - */ - public function convertOooTargetToPdfTarget(bool $bool = true): self - { - $this->formFields['convertOooTargetToPdfTarget'] = $bool; - - return $this; - } - - /** - * Specify that the file system related hyperlinks (file:// protocol) present in the document will be exported as relative to the source document location. - */ - public function exportLinksRelativeFsys(bool $bool = true): self - { - $this->formFields['exportLinksRelativeFsys'] = $bool; - - return $this; - } - - /** - * Export, for LibreOffice Impress, slides that are not included in slide shows. - */ - public function exportHiddenSlides(bool $bool = true): self - { - $this->formFields['exportHiddenSlides'] = $bool; - - return $this; - } - - /** - * Specify that automatically inserted empty pages are suppressed. This option is active only if storing Writer documents. - */ - public function skipEmptyPages(bool $bool = true): self - { - $this->formFields['skipEmptyPages'] = $bool; - - return $this; - } - - /** - * Specify that a stream is inserted to the PDF file which contains the original document for archiving purposes. - */ - public function addOriginalDocumentAsStream(bool $bool = true): self - { - $this->formFields['addOriginalDocumentAsStream'] = $bool; - - return $this; - } - - /** - * Specify if images are exported to PDF using a lossless compression format like PNG or compressed using the JPEG format. - */ - public function losslessImageCompression(bool $bool = true): self - { - $this->formFields['losslessImageCompression'] = $bool; - - return $this; - } - - /** - * Specify the quality of the JPG export. A higher value produces a higher-quality image and a larger file. Between 1 and 100. - * - * @param int<0, 100> $quality - */ - public function quality(int $quality): self - { - $this->formFields['quality'] = $quality; - - return $this; - } - - /** - * Specify if the resolution of each image is reduced to the resolution specified by the form field maxImageResolution. - */ - public function reduceImageResolution(bool $bool = true): self - { - $this->formFields['reduceImageResolution'] = $bool; - - return $this; - } - - /** - * If the form field reduceImageResolution is set to true, tell if all images will be reduced to the given value in DPI. Possible values are: 75, 150, 300, 600 and 1200. - */ - public function maxImageResolution(ImageResolutionDPI $resolution): self + protected function getEndpoint(): string { - $this->formFields['maxImageResolution'] = $resolution; - - return $this; + return self::ENDPOINT; } - /** - * Either intervals or pages. (default None). - * - * @see https://gotenberg.dev/docs/routes#split-libreoffice - */ - public function splitMode(SplitMode|null $splitMode = null): static + protected function validatePayloadBody(): void { - if (null === $splitMode) { - unset($this->formFields['splitMode']); - - return $this; + if ($this->getBodyBag()->get('files') === null && $this->getBodyBag()->get('downloadFrom') === null) { + throw new MissingRequiredFieldException('At least one office file is required.'); } - $this->formFields['splitMode'] = $splitMode; - - return $this; - } - - /** - * Either the intervals or the page ranges to extract, depending on the selected mode. (default None). - * - * @see https://gotenberg.dev/docs/routes#split-libreoffice - */ - public function splitSpan(string $splitSpan): static - { - $this->formFields['splitSpan'] = $splitSpan; - - return $this; - } - - /** - * Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). - * - * @see https://gotenberg.dev/docs/routes#split-libreoffice - */ - public function splitUnify(bool $bool = true): static - { - $this->formFields['splitUnify'] = $bool; - - return $this; - } - - public function getMultipartFormData(): array - { - if ([] === ($this->formFields['files'] ?? []) && [] === ($this->formFields['downloadFrom'] ?? [])) { - throw new MissingRequiredFieldException('At least one office file is required'); + if ($this->getBodyBag()->get('splitUnify') === true && $this->getBodyBag()->get('splitMode') === SplitMode::Intervals) { + throw new InvalidBuilderConfiguration('"splitUnify" can only be at "true" with "pages" mode for "splitMode".'); } - - return parent::getMultipartFormData(); } - protected function getEndpoint(): string + #[NormalizeGotenbergPayload] + private function normalizeFiles(): \Generator { - return self::ENDPOINT; + yield 'files' => NormalizerFactory::asset(); } - private function addConfiguration(string $configurationName, mixed $value): void + public static function type(): string { - match ($configurationName) { - 'password' => $this->password($value), - 'pdf_format' => $this->pdfFormat(PdfFormat::from($value)), - 'pdf_universal_access' => $this->pdfUniversalAccess($value), - 'landscape' => $this->landscape($value), - 'native_page_ranges' => $this->nativePageRanges($value), - 'do_not_export_form_fields' => $this->doNotExportFormFields($value), - 'single_page_sheets' => $this->singlePageSheets($value), - 'merge' => $this->merge($value), - 'metadata' => $this->metadata($value), - 'allow_duplicate_field_names' => $this->allowDuplicateFieldNames($value), - 'do_not_export_bookmarks' => $this->doNotExportBookmarks($value), - 'export_bookmarks_to_pdf_destination' => $this->exportBookmarksToPdfDestination($value), - 'export_placeholders' => $this->exportPlaceholders($value), - 'export_notes' => $this->exportNotes($value), - 'export_notes_pages' => $this->exportNotesPages($value), - 'export_only_notes_pages' => $this->exportOnlyNotesPages($value), - 'export_notes_in_margin' => $this->exportNotesInMargin($value), - 'convert_ooo_target_to_pdf_target' => $this->convertOooTargetToPdfTarget($value), - 'export_links_relative_fsys' => $this->exportLinksRelativeFsys($value), - 'export_hidden_slides' => $this->exportHiddenSlides($value), - 'skip_empty_pages' => $this->skipEmptyPages($value), - 'add_original_document_as_stream' => $this->addOriginalDocumentAsStream($value), - 'lossless_image_compression' => $this->losslessImageCompression($value), - 'quality' => $this->quality($value), - 'reduce_image_resolution' => $this->reduceImageResolution($value), - 'max_image_resolution' => $this->maxImageResolution(ImageResolutionDPI::from($value)), - 'download_from' => $this->downloadFrom($value), - 'split_mode' => $this->splitMode(SplitMode::from($value)), - 'split_span' => $this->splitSpan($value), - 'split_unify' => $this->splitUnify($value), - default => throw new InvalidBuilderConfiguration(\sprintf('Invalid option "%s": no method does not exist in class "%s" to configured it.', $configurationName, static::class)), - }; + return 'pdf'; } } diff --git a/src/Builder/Pdf/MarkdownPdfBuilder.php b/src/Builder/Pdf/MarkdownPdfBuilder.php index f2c63717..a8f0c070 100644 --- a/src/Builder/Pdf/MarkdownPdfBuilder.php +++ b/src/Builder/Pdf/MarkdownPdfBuilder.php @@ -2,68 +2,86 @@ namespace Sensiolabs\GotenbergBundle\Builder\Pdf; +use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; +use Sensiolabs\GotenbergBundle\Builder\Attributes\NormalizeGotenbergPayload; +use Sensiolabs\GotenbergBundle\Builder\Attributes\SemanticNode; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\ChromiumPdfTrait; +use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; +use Sensiolabs\GotenbergBundle\Builder\Util\NormalizerFactory; +use Sensiolabs\GotenbergBundle\Builder\Util\ValidatorFactory; use Sensiolabs\GotenbergBundle\Enumeration\Part; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Exception\PdfPartRenderingException; -use Symfony\Component\Mime\Part\DataPart; -use Symfony\Component\Mime\Part\File as DataPartFile; -final class MarkdownPdfBuilder extends AbstractChromiumPdfBuilder +/** + * @see https://gotenberg.dev/docs/routes#merge-pdfs-route + */ +#[SemanticNode('markdown')] +final class MarkdownPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { - private const ENDPOINT = '/forms/chromium/convert/markdown'; + use ChromiumPdfTrait { + content as wrapper; + contentFile as wrapperFile; + } + + public const ENDPOINT = '/forms/chromium/convert/markdown'; /** - * The HTML file that wraps the markdown content, rendered from a Twig template. - * - * @param string $template #Template - * @param array $context + * Add Markdown into a PDF. * - * @throws PdfPartRenderingException if the template could not be rendered + * @see https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route */ - public function wrapper(string $template, array $context = []): self + public function files(string|\Stringable ...$paths): self { - return $this->withRenderedPart(Part::Body, $template, $context); + foreach ($paths as $path) { + $path = (string) $path; + $info = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); + ValidatorFactory::filesExtension([$info], ['md']); + + $files[$path] = $info; + } + + $this->getBodyBag()->set('files', $files ?? null); + + return $this; } /** - * The HTML file that wraps the markdown content. + * @param array $context */ - public function wrapperFile(string $path): self + public function content(string $template, array $context = []): void { - return $this->withPdfPartFile(Part::Body, $path); + throw new \BadMethodCallException('Use wrapper() instead of content().'); } - public function files(string|\Stringable ...$paths): self + public function contentFile(string $path): void { - $this->formFields['files'] = []; - - foreach ($paths as $path) { - $path = (string) $path; - $this->assertFileExtension($path, ['md']); - - $dataPart = new DataPart(new DataPartFile($this->asset->resolve($path))); - - $this->formFields['files'][$path] = $dataPart; - } + throw new \BadMethodCallException('Use wrapperFile() instead of contentFile().'); + } - return $this; + protected function getEndpoint(): string + { + return self::ENDPOINT; } - public function getMultipartFormData(): array + protected function validatePayloadBody(): void { - if (!\array_key_exists(Part::Body->value, $this->formFields)) { + if ($this->getBodyBag()->get(Part::Body->value) === null) { throw new MissingRequiredFieldException('HTML template is required'); } - if ([] === ($this->formFields['files'] ?? []) && [] === ($this->formFields['downloadFrom'] ?? [])) { - throw new MissingRequiredFieldException('At least one markdown file is required'); + if ($this->getBodyBag()->get('files') === null && $this->getBodyBag()->get('downloadFrom') === null) { + throw new MissingRequiredFieldException('At least one markdown file is required.'); } + } - return parent::getMultipartFormData(); + #[NormalizeGotenbergPayload] + private function normalizeFiles(): \Generator + { + yield 'files' => NormalizerFactory::asset(); } - protected function getEndpoint(): string + public static function type(): string { - return self::ENDPOINT; + return 'pdf'; } } diff --git a/src/Builder/Pdf/MergePdfBuilder.php b/src/Builder/Pdf/MergePdfBuilder.php index 1f0a3259..962ddeac 100644 --- a/src/Builder/Pdf/MergePdfBuilder.php +++ b/src/Builder/Pdf/MergePdfBuilder.php @@ -2,117 +2,74 @@ namespace Sensiolabs\GotenbergBundle\Builder\Pdf; -use Sensiolabs\GotenbergBundle\Enumeration\PdfFormat; -use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; +use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; +use Sensiolabs\GotenbergBundle\Builder\Attributes\NormalizeGotenbergPayload; +use Sensiolabs\GotenbergBundle\Builder\Attributes\SemanticNode; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies\AssetBaseDirFormatterAwareTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\DownloadFromTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\FlattenTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\MetadataTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\PdfFormatTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\WebhookTrait; +use Sensiolabs\GotenbergBundle\Builder\Util\NormalizerFactory; +use Sensiolabs\GotenbergBundle\Builder\Util\ValidatorFactory; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Symfony\Component\Mime\Part\DataPart; -use Symfony\Component\Mime\Part\File as DataPartFile; /** - * Merge `n` pdf files into a single one. + * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ -final class MergePdfBuilder extends AbstractPdfBuilder +#[SemanticNode('merge')] +final class MergePdfBuilder extends AbstractBuilder { - private const ENDPOINT = '/forms/pdfengines/merge'; + use AssetBaseDirFormatterAwareTrait; + use DownloadFromTrait; + use FlattenTrait; + use MetadataTrait; + use PdfFormatTrait; + use WebhookTrait; - /** - * To set configurations by an array of configurations. - * - * @param array $configurations - */ - public function setConfigurations(array $configurations): static - { - foreach ($configurations as $property => $value) { - $this->addConfiguration($property, $value); - } - - return $this; - } - - /** - * Convert the resulting PDF into the given PDF/A format. - */ - public function pdfFormat(PdfFormat $format): self - { - $this->formFields['pdfa'] = $format->value; - - return $this; - } + public const ENDPOINT = '/forms/pdfengines/merge'; /** - * Enable PDF for Universal Access for optimal accessibility. + * Add PDF files to merge. + * + * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ - public function pdfUniversalAccess(bool $bool = true): self - { - $this->formFields['pdfua'] = $bool; - - return $this; - } - public function files(string|\Stringable ...$paths): self { - $this->formFields['files'] = []; - foreach ($paths as $path) { $path = (string) $path; - $this->assertFileExtension($path, ['pdf']); - - $dataPart = new DataPart(new DataPartFile($this->asset->resolve($path))); + $info = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); + ValidatorFactory::filesExtension([$info], ['pdf']); - $this->formFields['files'][$path] = $dataPart; + $files[$path] = $info; } - return $this; - } - - /** - * Resets the metadata. - * - * @see https://gotenberg.dev/docs/routes#metadata-chromium - * @see https://exiftool.org/TagNames/XMP.html#pdf - * - * @param array $metadata - */ - public function metadata(array $metadata): static - { - $this->formFields['metadata'] = $metadata; + $this->getBodyBag()->set('files', $files ?? null); return $this; } - /** - * The metadata to write. - */ - public function addMetadata(string $key, string $value): static + protected function getEndpoint(): string { - $this->formFields['metadata'] ??= []; - $this->formFields['metadata'][$key] = $value; - - return $this; + return self::ENDPOINT; } - public function getMultipartFormData(): array + protected function validatePayloadBody(): void { - if ([] === ($this->formFields['files'] ?? []) && [] === ($this->formFields['downloadFrom'] ?? [])) { - throw new MissingRequiredFieldException('At least one PDF file is required'); + if ($this->getBodyBag()->get('files') === null && $this->getBodyBag()->get('downloadFrom') === null) { + throw new MissingRequiredFieldException('At least one PDF file is required.'); } - - return parent::getMultipartFormData(); } - protected function getEndpoint(): string + #[NormalizeGotenbergPayload] + private function normalizeFiles(): \Generator { - return self::ENDPOINT; + yield 'files' => NormalizerFactory::asset(); } - private function addConfiguration(string $configurationName, mixed $value): void + public static function type(): string { - match ($configurationName) { - 'pdf_format' => $this->pdfFormat(PdfFormat::from($value)), - 'pdf_universal_access' => $this->pdfUniversalAccess($value), - 'metadata' => $this->metadata($value), - 'download_from' => $this->downloadFrom($value), - default => throw new InvalidBuilderConfiguration(\sprintf('Invalid option "%s": no method does not exist in class "%s" to configured it.', $configurationName, self::class)), - }; + return 'pdf'; } } diff --git a/src/Builder/Pdf/PdfBuilderInterface.php b/src/Builder/Pdf/PdfBuilderInterface.php deleted file mode 100644 index b889eb6d..00000000 --- a/src/Builder/Pdf/PdfBuilderInterface.php +++ /dev/null @@ -1,13 +0,0 @@ - $configurations - */ - public function setConfigurations(array $configurations): static - { - foreach ($configurations as $property => $value) { - $this->addConfiguration($property, $value); - } - - return $this; - } + public const ENDPOINT = '/forms/pdfengines/split'; - /** - * Either intervals or pages. (default None). - * - * @see https://gotenberg.dev/docs/routes#split-pdfs-route - */ - public function splitMode(SplitMode|null $splitMode = null): self + public function files(string|\Stringable ...$paths): self { - if (null === $splitMode) { - unset($this->formFields['splitMode']); + foreach ($paths as $path) { + $path = (string) $path; + $info = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); + ValidatorFactory::filesExtension([$info], ['pdf']); - return $this; + $files[$path] = $info; } - $this->formFields['splitMode'] = $splitMode; + $this->getBodyBag()->set('files', $files ?? null); return $this; } - /** - * Either the intervals or the page ranges to extract, depending on the selected mode. (default None). - * - * @see https://gotenberg.dev/docs/routes#split-pdfs-route - */ - public function splitSpan(string $splitSpan): self - { - $this->formFields['splitSpan'] = $splitSpan; - - return $this; - } - - /** - * Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). - * - * @see https://gotenberg.dev/docs/routes#split-pdfs-route - */ - public function splitUnify(bool $bool = true): self + protected function getEndpoint(): string { - $this->formFields['splitUnify'] = $bool; - - return $this; + return self::ENDPOINT; } - public function files(string|\Stringable ...$paths): self + protected function validatePayloadBody(): void { - $this->formFields['files'] = []; - - foreach ($paths as $path) { - $path = (string) $path; - $this->assertFileExtension($path, ['pdf']); - - $dataPart = new DataPart(new DataPartFile($this->asset->resolve($path))); - - $this->formFields['files'][$path] = $dataPart; + if ($this->getBodyBag()->get('files') === null && $this->getBodyBag()->get('downloadFrom') === null) { + throw new MissingRequiredFieldException('At least one PDF file is required.'); } - return $this; - } - - public function getMultipartFormData(): array - { - if (!\array_key_exists('splitMode', $this->formFields) || !\array_key_exists('splitSpan', $this->formFields)) { - throw new MissingRequiredFieldException('"splitMode" and "splitSpan" must be provided.'); + if ($this->getBodyBag()->get('splitMode') === null) { + throw new MissingRequiredFieldException('Field "splitMode" must be provided.'); } - if ([] === ($this->formFields['files'] ?? [])) { - throw new MissingRequiredFieldException('At least one PDF file is required'); + if ($this->getBodyBag()->get('splitSpan') === null) { + throw new MissingRequiredFieldException('Field "splitSpan" must be provided.'); } - - return parent::getMultipartFormData(); } - protected function getEndpoint(): string + #[NormalizeGotenbergPayload] + private function normalizeFiles(): \Generator { - return self::ENDPOINT; + yield 'files' => NormalizerFactory::asset(); } - private function addConfiguration(string $configurationName, mixed $value): void + public static function type(): string { - match ($configurationName) { - 'split_mode' => $this->splitMode(SplitMode::from($value)), - 'split_span' => $this->splitSpan($value), - 'split_unify' => $this->splitUnify($value), - default => throw new InvalidBuilderConfiguration(\sprintf('Invalid option "%s": no method does not exist in class "%s" to configured it.', $configurationName, static::class)), - }; + return 'pdf'; } } diff --git a/src/Builder/Pdf/UrlPdfBuilder.php b/src/Builder/Pdf/UrlPdfBuilder.php index e72cc8e3..d1aef4ea 100644 --- a/src/Builder/Pdf/UrlPdfBuilder.php +++ b/src/Builder/Pdf/UrlPdfBuilder.php @@ -2,47 +2,33 @@ namespace Sensiolabs\GotenbergBundle\Builder\Pdf; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; +use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; +use Sensiolabs\GotenbergBundle\Builder\Attributes\NormalizeGotenbergPayload; +use Sensiolabs\GotenbergBundle\Builder\Attributes\SemanticNode; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\ChromiumPdfTrait; +use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; +use Sensiolabs\GotenbergBundle\Builder\Util\NormalizerFactory; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistryInterface; -use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RequestContext; -use Twig\Environment; -final class UrlPdfBuilder extends AbstractChromiumPdfBuilder +/** + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route + */ +#[SemanticNode('url')] +final class UrlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { - private const ENDPOINT = '/forms/chromium/convert/url'; + use ChromiumPdfTrait; - private RequestContext|null $requestContext = null; - - public function __construct( - GotenbergClientInterface $gotenbergClient, - AssetBaseDirFormatter $asset, - WebhookConfigurationRegistryInterface $webhookConfigurationRegistry, - RequestStack $requestStack, - Environment|null $twig = null, - private readonly UrlGeneratorInterface|null $urlGenerator = null, - ) { - parent::__construct($gotenbergClient, $asset, $webhookConfigurationRegistry, $requestStack, $twig); - - $this->addNormalizer('route', $this->generateUrlFromRoute(...)); - } - - public function setRequestContext(RequestContext|null $requestContext = null): self - { - $this->requestContext = $requestContext; + public const ENDPOINT = '/forms/chromium/convert/url'; - return $this; - } + private RequestContext|null $requestContext = null; /** * URL of the page you want to convert into PDF. */ public function url(string $url): self { - $this->formFields['url'] = $url; + $this->getBodyBag()->set('url', $url); return $this; } @@ -50,57 +36,48 @@ public function url(string $url): self /** * @param string $name #Route * @param array $parameters - * - * @phpstan-assert !null $this->urlGenerator */ public function route(string $name, array $parameters = []): self { - if (null === $this->urlGenerator) { - throw new \LogicException(\sprintf('Router is required to use "%s" method. Try to run "composer require symfony/routing".', __METHOD__)); - } - - $this->formFields['route'] = [$name, $parameters]; + $this->getBodyBag()->set('route', [$name, $parameters]); return $this; } - /** - * @param array{string, array} $value - * - * @return array{url: string} - */ - private function generateUrlFromRoute(array $value): array + public function setRequestContext(RequestContext|null $requestContext = null): self { - [$route, $parameters] = $value; - - $requestContext = $this->urlGenerator->getContext(); + $this->requestContext = $requestContext; - if (null !== $this->requestContext) { - $this->urlGenerator->setContext($this->requestContext); - } + return $this; + } - try { - return ['url' => $this->urlGenerator->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL)]; - } finally { - $this->urlGenerator->setContext($requestContext); - } + protected function getEndpoint(): string + { + return self::ENDPOINT; } - public function getMultipartFormData(): array + protected function validatePayloadBody(): void { - if (!\array_key_exists('url', $this->formFields) && !\array_key_exists('route', $this->formFields)) { - throw new MissingRequiredFieldException('URL (or route) is required'); + if ($this->getBodyBag()->get('url') === null && $this->getBodyBag()->get('route') === null) { + throw new MissingRequiredFieldException('"url" (or "route") is required'); } - if (\array_key_exists('url', $this->formFields) && \array_key_exists('route', $this->formFields)) { + if ($this->getBodyBag()->get('url') !== null && $this->getBodyBag()->get('route') !== null) { throw new MissingRequiredFieldException('Provide only one of ["route", "url"] parameter. Not both.'); } + } - return parent::getMultipartFormData(); + /** + * @internal + */ + #[NormalizeGotenbergPayload] + private function normalizeRoute(): \Generator + { + yield 'route' => NormalizerFactory::route($this->requestContext, $this->getUrlGenerator()); } - protected function getEndpoint(): string + public static function type(): string { - return self::ENDPOINT; + return 'pdf'; } } diff --git a/src/Builder/Result/AbstractGotenbergResult.php b/src/Builder/Result/AbstractGotenbergResult.php new file mode 100644 index 00000000..6ef284dc --- /dev/null +++ b/src/Builder/Result/AbstractGotenbergResult.php @@ -0,0 +1,34 @@ +executed) { + return; + } + + try { + if (!\in_array($this->response->getStatusCode(), [200, 204], true)) { + throw new ClientException($this->response->getContent(false), $this->response->getStatusCode()); + } + } catch (ExceptionInterface $e) { + throw new ClientException($e->getMessage(), $e->getCode(), $e); + } finally { + $this->executed = true; + } + } +} diff --git a/src/Builder/Result/GotenbergAsyncResult.php b/src/Builder/Result/GotenbergAsyncResult.php new file mode 100644 index 00000000..709b0f24 --- /dev/null +++ b/src/Builder/Result/GotenbergAsyncResult.php @@ -0,0 +1,23 @@ +ensureExecution(); + + return $this->response->getStatusCode(); + } + + /** + * @return array> + */ + public function getHeaders(): array + { + $this->ensureExecution(); + + return $this->response->getHeaders(); + } +} diff --git a/src/Builder/Result/GotenbergFileResult.php b/src/Builder/Result/GotenbergFileResult.php new file mode 100644 index 00000000..f552bf00 --- /dev/null +++ b/src/Builder/Result/GotenbergFileResult.php @@ -0,0 +1,113 @@ + $processor + */ + public function __construct( + ResponseInterface $response, + private readonly ResponseStreamInterface $stream, + private readonly ProcessorInterface $processor, + private readonly string $disposition, + ) { + parent::__construct($response); + } + + public function getStatusCode(): int + { + $this->ensureExecution(); + + return $this->response->getStatusCode(); + } + + /** + * @return array> + */ + public function getHeaders(): array + { + $this->ensureExecution(); + + return $this->response->getHeaders(); + } + + /** + * @return non-negative-int|null + */ + public function getContentLength(): int|null + { + $length = $this->getHeaders()['content-length'][0] ?? null; + if (null !== $length) { + return abs((int) $length); + } + + return null; + } + + public function getFileName(): string|null + { + $disposition = $this->getHeaders()['content-disposition'][0] ?? ''; + /* @see https://onlinephp.io/c/c2606 */ + if (1 === preg_match('#[^;]*;\sfilename="?(?P[^"]*)"?#', $disposition, $matches)) { + return $matches['fileName']; + } + + return null; + } + + public function process(): mixed + { + $this->ensureExecution(); + + if (!$this->stream->valid()) { + throw new ProcessorException('Already processed query.'); + } + + $generator = ($this->processor)($this->getFileName()); + foreach ($this->stream as $chunk) { + $generator->send($chunk); + } + + return $generator->getReturn(); + } + + public function stream(): StreamedResponse + { + $this->ensureExecution(); + + $filename = $this->getFileName(); + + $headers = $this->getHeaders(); + $headers['X-Accel-Buffering'] = ['no']; // See https://symfony.com/doc/current/components/http_foundation.html#streaming-a-json-response + if ($filename) { + $headers['Content-Disposition'] = [HeaderUtils::makeDisposition($this->disposition, $filename)]; + } + + return new StreamedResponse( + function () use ($filename): void { + if (!$this->stream->valid()) { + throw new ProcessorException('Already processed query.'); + } + + $generator = ($this->processor)($filename); + + foreach ($this->stream as $chunk) { + $generator->send($chunk); + echo $chunk->getContent(); + flush(); + } + }, + $this->getStatusCode(), + $headers, + ); + } +} diff --git a/src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php b/src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php deleted file mode 100644 index cf61e56e..00000000 --- a/src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php +++ /dev/null @@ -1,463 +0,0 @@ - function (mixed $value): array { - return $this->encodeData('extraHttpHeaders', $value); - }, - 'assets' => static function (array $value): array { - return ['files' => $value]; - }, - Part::Body->value => static function (DataPart $value): array { - return ['files' => $value]; - }, - 'failOnHttpStatusCodes' => function (mixed $value): array { - return $this->encodeData('failOnHttpStatusCodes', $value); - }, - 'failOnResourceHttpStatusCodes' => function (mixed $value): array { - return $this->encodeData('failOnResourceHttpStatusCodes', $value); - }, - 'cookies' => fn (mixed $value): array => $this->cookieNormalizer($value, $this->encodeData(...)), - ]; - - foreach ($normalizers as $key => $normalizer) { - $this->addNormalizer($key, $normalizer); - } - } - - /** - * To set configurations by an array of configurations. - * - * @param array $configurations - */ - public function setConfigurations(array $configurations): static - { - foreach ($configurations as $property => $value) { - $this->addConfiguration($property, $value); - } - - return $this; - } - - /** - * @param list $cookies - */ - public function cookies(array $cookies): static - { - return $this->withCookies($this->formFields, $cookies); - } - - /** - * @param Cookie|array{name: string, value: string, domain: string, path?: string|null, secure?: bool|null, httpOnly?: bool|null, sameSite?: 'Strict'|'Lax'|null} $cookie - */ - public function setCookie(string $key, Cookie|array $cookie): static - { - return $this->withCookie($this->formFields, $key, $cookie); - } - - public function forwardCookie(string $name): static - { - return $this->forwardCookieFromRequest($this->requestStack->getCurrentRequest(), $name, $this->logger); - } - - /** - * The device screen width in pixels. (Default 800). - * - * @see https://gotenberg.dev/docs/routes#screenshots-route - * - * @package Behavior\\Chromium\\PageProperties - */ - public function width(int $width): static - { - $this->formFields['width'] = $width; - - return $this; - } - - /** - * The device screen width in pixels. (Default 600). - * - * @see https://gotenberg.dev/docs/routes#screenshots-route - * - * @package Behavior\\Chromium\\PageProperties - */ - public function height(int $height): static - { - $this->formFields['height'] = $height; - - return $this; - } - - /** - * Define whether to clip the screenshot according to the device dimensions. (Default false). - * - * @see https://gotenberg.dev/docs/routes#screenshots-route - * - * @package Behavior\\Chromium\\PageProperties - */ - public function clip(bool $bool = true): static - { - $this->formFields['clip'] = $bool; - - return $this; - } - - /** - * The image compression format, either "png", "jpeg" or "webp". (default png). - * - * @see https://gotenberg.dev/docs/routes#screenshots-route - * - * @package Behavior\\Chromium\\PageProperties - */ - public function format(ScreenshotFormat $format): static - { - $this->formFields['format'] = $format; - - return $this; - } - - /** - * The compression quality from range 0 to 100 (jpeg only). (default 100). - * - * @param int<0, 100> $quality - * - * @see https://gotenberg.dev/docs/routes#screenshots-route - * - * @package Behavior\\Chromium\\PageProperties - */ - public function quality(int $quality): static - { - $this->formFields['quality'] = $quality; - - return $this; - } - - /** - * Hides default white background and allows generating screenshot with - * transparency. (Default false). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium - * - * @package Behavior\\Chromium\\PageProperties - */ - public function omitBackground(bool $bool = true): static - { - $this->formFields['omitBackground'] = $bool; - - return $this; - } - - /** - * Define whether to optimize image encoding for speed, not for resulting size. (Default false). - * - * @see https://gotenberg.dev/docs/routes#screenshots-route - * - * @package Behavior\\Chromium\\PageProperties - */ - public function optimizeForSpeed(bool $bool = true): static - { - $this->formFields['optimizeForSpeed'] = $bool; - - return $this; - } - - /** - * Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML - * document before converting it to screenshot. (default None). - * - * @see https://gotenberg.dev/docs/routes#wait-before-rendering - * - * @package Behavior\\Chromium\\WaitFor - */ - public function waitDelay(string $delay): static - { - $this->formFields['waitDelay'] = $delay; - - return $this; - } - - /** - * Sets the JavaScript expression to wait before converting an HTML - * document to screenshot until it returns true. (default None). - * - * For instance: "window.status === 'ready'". - * - * @see https://gotenberg.dev/docs/routes#wait-before-rendering - * - * @package Behavior\\Chromium\\WaitFor - */ - public function waitForExpression(string $expression): static - { - $this->formFields['waitForExpression'] = $expression; - - return $this; - } - - /** - * Forces Chromium to emulate, either "screen" or "print". (default "print"). - * - * @see https://gotenberg.dev/docs/routes#console-exceptions - */ - public function emulatedMediaType(EmulatedMediaType $mediaType): static - { - $this->formFields['emulatedMediaType'] = $mediaType; - - return $this; - } - - /** - * Override the default User-Agent HTTP header. (default None). - * - * @param UserAgent::*|string $userAgent - * - * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium - */ - public function userAgent(string $userAgent): static - { - $this->formFields['userAgent'] = $userAgent; - - return $this; - } - - /** - * Sets extra HTTP headers that Chromium will send when loading the HTML - * document. (default None). (overrides any previous headers). - * - * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium - * - * @param array $headers - */ - public function extraHttpHeaders(array $headers): static - { - if ([] === $headers) { - unset($this->formFields['extraHttpHeaders']); - - return $this; - } - - $this->formFields['extraHttpHeaders'] = $headers; - - return $this; - } - - /** - * Adds extra HTTP headers that Chromium will send when loading the HTML - * document. (default None). - * - * @see https://gotenberg.dev/docs/routes#custom-http-headers - * - * @param array $headers - */ - public function addExtraHttpHeaders(array $headers): static - { - if ([] === $headers) { - return $this; - } - - $this->formFields['extraHttpHeaders'] = array_merge($this->formFields['extraHttpHeaders'] ?? [], $headers); - - return $this; - } - - /** - * Return a 409 Conflict response if the HTTP status code from - * the main page is not acceptable. (default [499,599]). (overrides any previous configuration). - * - * @see https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium - * - * @param array $statusCodes - * - * @package Behavior\\FailOn - */ - public function failOnHttpStatusCodes(array $statusCodes): static - { - $this->formFields['failOnHttpStatusCodes'] = $statusCodes; - - return $this; - } - - /** - * Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. - * (default None). (overrides any previous configuration). - * - * @see https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium - * - * @param list> $statusCodes - * - * @package Behavior\\FailOn - */ - public function failOnResourceHttpStatusCodes(array $statusCodes): static - { - $this->formFields['failOnResourceHttpStatusCodes'] = $statusCodes; - - return $this; - } - - /** - * Forces GotenbergScreenshot to return a 409 Conflict response if there are - * exceptions load at least one resource. (default false). - * - * @see https://gotenberg.dev/docs/routes#network-errors-chromium - * - * @package Behavior\\FailOn - */ - public function failOnResourceLoadingFailed(bool $bool = true): static - { - $this->formFields['failOnResourceLoadingFailed'] = $bool; - - return $this; - } - - /** - * Forces GotenbergScreenshot to return a 409 Conflict response if there are - * exceptions in the Chromium console. (default false). - * - * @see https://gotenberg.dev/docs/routes#console-exceptions - * - * @package Behavior\\FailOn - */ - public function failOnConsoleExceptions(bool $bool = true): static - { - $this->formFields['failOnConsoleExceptions'] = $bool; - - return $this; - } - - /** - * @package Behavior\\Performance - */ - public function skipNetworkIdleEvent(bool $bool = true): static - { - $this->formFields['skipNetworkIdleEvent'] = $bool; - - return $this; - } - - /** - * Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). - * - * @package Behavior\\Assets - */ - public function assets(string ...$paths): static - { - $this->formFields['assets'] = []; - - foreach ($paths as $path) { - $this->addAsset($path); - } - - return $this; - } - - /** - * Adds a file, like an image, font, stylesheet, and so on. - * - * @package Behavior\\Assets - */ - public function addAsset(string $path): static - { - $resolvedPath = $this->asset->resolve($path); - - $dataPart = new DataPart(new DataPartFile($resolvedPath)); - - $this->formFields['assets'][$resolvedPath] = $dataPart; - - return $this; - } - - protected function withScreenshotPartFile(Part $screenshotPart, string $path): static - { - $dataPart = new DataPart( - new DataPartFile($this->asset->resolve($path)), - $screenshotPart->value, - ); - - $this->formFields[$screenshotPart->value] = $dataPart; - - return $this; - } - - /** - * @param string $template #Template - * @param array $context - * - * @throws ScreenshotPartRenderingException if the template could not be rendered - */ - protected function withRenderedPart(Part $screenshotPart, string $template, array $context = []): static - { - if (!$this->twig instanceof Environment) { - throw new \LogicException(\sprintf('Twig is required to use "%s" method. Try to run "composer require symfony/twig-bundle".', __METHOD__)); - } - - $this->twig->getRuntime(GotenbergRuntime::class)->setBuilder($this); - - try { - $html = $this->twig->render($template, $context); - } catch (\Throwable $error) { - throw new ScreenshotPartRenderingException(\sprintf('Could not render template "%s" into Screenshot part "%s". %s', $template, $screenshotPart->value, $error->getMessage()), previous: $error); - } finally { - $this->twig->getRuntime(GotenbergRuntime::class)->setBuilder(null); - } - - $this->formFields[$screenshotPart->value] = new DataPart($html, $screenshotPart->value, 'text/html'); - - return $this; - } - - private function addConfiguration(string $configurationName, mixed $value): void - { - match ($configurationName) { - 'width' => $this->width($value), - 'height' => $this->height($value), - 'clip' => $this->clip($value), - 'format' => $this->format(ScreenshotFormat::from($value)), - 'quality' => $this->quality($value), - 'omit_background' => $this->omitBackground($value), - 'optimize_for_speed' => $this->optimizeForSpeed($value), - 'wait_delay' => $this->waitDelay($value), - 'wait_for_expression' => $this->waitForExpression($value), - 'emulated_media_type' => $this->emulatedMediaType($value), - 'cookies' => $this->cookies($value), - 'user_agent' => $this->userAgent($value), - 'extra_http_headers' => $this->extraHttpHeaders($value), - 'fail_on_http_status_codes' => $this->failOnHttpStatusCodes($value), - 'fail_on_resource_http_status_codes' => $this->failOnResourceHttpStatusCodes($value), - 'fail_on_resource_loading_failed' => $this->failOnResourceLoadingFailed($value), - 'fail_on_console_exceptions' => $this->failOnConsoleExceptions($value), - 'skip_network_idle_event' => $this->skipNetworkIdleEvent($value), - 'download_from' => $this->downloadFrom($value), - default => throw new InvalidBuilderConfiguration(\sprintf('Invalid option "%s": no method exists in class "%s" to configured it.', $configurationName, static::class)), - }; - } -} diff --git a/src/Builder/Screenshot/AbstractScreenshotBuilder.php b/src/Builder/Screenshot/AbstractScreenshotBuilder.php deleted file mode 100644 index 0d68221a..00000000 --- a/src/Builder/Screenshot/AbstractScreenshotBuilder.php +++ /dev/null @@ -1,40 +0,0 @@ -client = $gotenbergClient; - $this->asset = $asset; - $this->webhookConfigurationRegistry = $webhookConfigurationRegistry; - - $this->normalizers = [ - 'downloadFrom' => fn (array $value): array => $this->downloadFromNormalizer($value, $this->encodeData(...)), - ]; - } - - /** - * @param list}> $downloadFrom - */ - public function downloadFrom(array $downloadFrom): static - { - return $this->withDownloadFrom($this->formFields, $downloadFrom); - } -} diff --git a/src/Builder/Screenshot/HtmlScreenshotBuilder.php b/src/Builder/Screenshot/HtmlScreenshotBuilder.php index 47dacfbe..6a0b15ec 100644 --- a/src/Builder/Screenshot/HtmlScreenshotBuilder.php +++ b/src/Builder/Screenshot/HtmlScreenshotBuilder.php @@ -2,48 +2,37 @@ namespace Sensiolabs\GotenbergBundle\Builder\Screenshot; +use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; +use Sensiolabs\GotenbergBundle\Builder\Attributes\SemanticNode; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\ChromiumScreenshotTrait; +use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; use Sensiolabs\GotenbergBundle\Enumeration\Part; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Exception\ScreenshotPartRenderingException; -final class HtmlScreenshotBuilder extends AbstractChromiumScreenshotBuilder +/** + * @see https://gotenberg.dev/docs/routes#screenshots-route + */ +#[SemanticNode('html')] +final class HtmlScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { - private const ENDPOINT = '/forms/chromium/screenshot/html'; + use ChromiumScreenshotTrait; - /** - * @param string $template #Template - * @param array $context - * - * @package Behavior\\Content - * - * @throws ScreenshotPartRenderingException if the template could not be rendered - */ - public function content(string $template, array $context = []): self - { - return $this->withRenderedPart(Part::Body, $template, $context); - } + public const ENDPOINT = '/forms/chromium/screenshot/html'; - /** - * The HTML file to convert into Screenshot. - * - * @package Behavior\\Content - */ - public function contentFile(string $path): self + protected function getEndpoint(): string { - return $this->withScreenshotPartFile(Part::Body, $path); + return self::ENDPOINT; } - public function getMultipartFormData(): array + protected function validatePayloadBody(): void { - if (!\array_key_exists(Part::Body->value, $this->formFields) && [] === ($this->formFields['downloadFrom'] ?? [])) { + if ($this->getBodyBag()->get(Part::Body->value) === null && $this->getBodyBag()->get('downloadFrom') === null) { throw new MissingRequiredFieldException('Content is required'); } - - return parent::getMultipartFormData(); } - protected function getEndpoint(): string + public static function type(): string { - return self::ENDPOINT; + return 'screenshot'; } } diff --git a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php index f431befc..3f92b660 100644 --- a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php +++ b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php @@ -2,68 +2,86 @@ namespace Sensiolabs\GotenbergBundle\Builder\Screenshot; +use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; +use Sensiolabs\GotenbergBundle\Builder\Attributes\NormalizeGotenbergPayload; +use Sensiolabs\GotenbergBundle\Builder\Attributes\SemanticNode; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\ChromiumScreenshotTrait; +use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; +use Sensiolabs\GotenbergBundle\Builder\Util\NormalizerFactory; +use Sensiolabs\GotenbergBundle\Builder\Util\ValidatorFactory; use Sensiolabs\GotenbergBundle\Enumeration\Part; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Exception\ScreenshotPartRenderingException; -use Symfony\Component\Mime\Part\DataPart; -use Symfony\Component\Mime\Part\File as DataPartFile; -final class MarkdownScreenshotBuilder extends AbstractChromiumScreenshotBuilder +/** + * @see https://gotenberg.dev/docs/routes#screenshots-route + */ +#[SemanticNode('markdown')] +final class MarkdownScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { - private const ENDPOINT = '/forms/chromium/screenshot/markdown'; + use ChromiumScreenshotTrait { + content as wrapper; + contentFile as wrapperFile; + } + + public const ENDPOINT = '/forms/chromium/screenshot/markdown'; /** - * The HTML file that wraps the markdown content, rendered from a Twig template. - * - * @param string $template #Template - * @param array $context + * Add Markdown into a PDF. * - * @throws ScreenshotPartRenderingException if the template could not be rendered + * @see https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route */ - public function wrapper(string $template, array $context = []): self + public function files(string|\Stringable ...$paths): self { - return $this->withRenderedPart(Part::Body, $template, $context); + foreach ($paths as $path) { + $path = (string) $path; + $info = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); + ValidatorFactory::filesExtension([$info], ['md']); + + $files[$path] = $info; + } + + $this->getBodyBag()->set('files', $files ?? null); + + return $this; } /** - * The HTML file that wraps the markdown content. + * @param array $context */ - public function wrapperFile(string $path): self + public function content(string $template, array $context = []): void { - return $this->withScreenshotPartFile(Part::Body, $path); + throw new \BadMethodCallException('Use wrapper() instead of content().'); } - public function files(string|\Stringable ...$paths): self + public function contentFile(string $path): void { - $this->formFields['files'] = []; - - foreach ($paths as $path) { - $path = (string) $path; - $this->assertFileExtension($path, ['md']); - - $dataPart = new DataPart(new DataPartFile($this->asset->resolve($path))); - - $this->formFields['files'][$path] = $dataPart; - } + throw new \BadMethodCallException('Use wrapperFile() instead of contentFile().'); + } - return $this; + protected function getEndpoint(): string + { + return self::ENDPOINT; } - public function getMultipartFormData(): array + protected function validatePayloadBody(): void { - if (!\array_key_exists(Part::Body->value, $this->formFields)) { + if ($this->getBodyBag()->get(Part::Body->value) === null) { throw new MissingRequiredFieldException('HTML template is required'); } - if ([] === ($this->formFields['files'] ?? []) && [] === ($this->formFields['downloadFrom'] ?? [])) { - throw new MissingRequiredFieldException('At least one markdown file is required'); + if ($this->getBodyBag()->get('files') === null && $this->getBodyBag()->get('downloadFrom') === null) { + throw new MissingRequiredFieldException('At least one markdown file is required.'); } + } - return parent::getMultipartFormData(); + #[NormalizeGotenbergPayload] + private function normalizeFiles(): \Generator + { + yield 'files' => NormalizerFactory::asset(); } - protected function getEndpoint(): string + public static function type(): string { - return self::ENDPOINT; + return 'screenshot'; } } diff --git a/src/Builder/Screenshot/ScreenshotBuilderInterface.php b/src/Builder/Screenshot/ScreenshotBuilderInterface.php deleted file mode 100644 index dd8eec60..00000000 --- a/src/Builder/Screenshot/ScreenshotBuilderInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -addNormalizer('route', $this->generateUrlFromRoute(...)); - } - - public function setRequestContext(RequestContext|null $requestContext = null): self - { - $this->requestContext = $requestContext; + public const ENDPOINT = '/forms/chromium/screenshot/url'; - return $this; - } + private RequestContext|null $requestContext = null; /** - * URL of the page you want to screenshot. + * URL of the page you want to convert into PDF. */ public function url(string $url): self { - $this->formFields['url'] = $url; + $this->getBodyBag()->set('url', $url); return $this; } @@ -50,57 +36,45 @@ public function url(string $url): self /** * @param string $name #Route * @param array $parameters - * - * @phpstan-assert !null $this->urlGenerator */ public function route(string $name, array $parameters = []): self { - if (null === $this->urlGenerator) { - throw new \LogicException(\sprintf('Router is required to use "%s" method. Try to run "composer require symfony/routing".', __METHOD__)); - } - - $this->formFields['route'] = [$name, $parameters]; + $this->getBodyBag()->set('route', [$name, $parameters]); return $this; } - /** - * @param array{string, array} $value - * - * @return array{url: string} - */ - private function generateUrlFromRoute(array $value): array + public function setRequestContext(RequestContext|null $requestContext = null): self { - [$route, $parameters] = $value; - - $requestContext = $this->urlGenerator->getContext(); + $this->requestContext = $requestContext; - if (null !== $this->requestContext) { - $this->urlGenerator->setContext($this->requestContext); - } + return $this; + } - try { - return ['url' => $this->urlGenerator->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL)]; - } finally { - $this->urlGenerator->setContext($requestContext); - } + protected function getEndpoint(): string + { + return self::ENDPOINT; } - public function getMultipartFormData(): array + protected function validatePayloadBody(): void { - if (!\array_key_exists('url', $this->formFields) && !\array_key_exists('route', $this->formFields)) { - throw new MissingRequiredFieldException('URL (or route) is required'); + if ($this->getBodyBag()->get('url') === null && $this->getBodyBag()->get('route') === null) { + throw new MissingRequiredFieldException('"url" (or "route") is required'); } - if (\array_key_exists('url', $this->formFields) && \array_key_exists('route', $this->formFields)) { + if ($this->getBodyBag()->get('url') !== null && $this->getBodyBag()->get('route') !== null) { throw new MissingRequiredFieldException('Provide only one of ["route", "url"] parameter. Not both.'); } + } - return parent::getMultipartFormData(); + #[NormalizeGotenbergPayload] + private function normalizeRoute(): \Generator + { + yield 'route' => NormalizerFactory::route($this->requestContext, $this->getUrlGenerator()); } - protected function getEndpoint(): string + public static function type(): string { - return self::ENDPOINT; + return 'screenshot'; } } diff --git a/src/Builder/Util/NormalizerFactory.php b/src/Builder/Util/NormalizerFactory.php new file mode 100644 index 00000000..9e0122e9 --- /dev/null +++ b/src/Builder/Util/NormalizerFactory.php @@ -0,0 +1,166 @@ +) + */ + public static function unit(): \Closure + { + return static fn (string $key, mixed $value) => [$key => is_numeric($value) ? $value.'in' : (string) $value]; + } + + /** + * @return (\Closure(string, array): array) + */ + public static function json(bool $associative = true): \Closure + { + return static function (string $key, array $value) use ($associative) { + try { + return [ + $key => json_encode($associative ? $value : array_values($value), \JSON_THROW_ON_ERROR), + ]; + } catch (\JsonException $exception) { + throw new JsonEncodingException(previous: $exception); + } + }; + } + + /** + * @return (\Closure(string, list): array) + */ + public static function cookie(): \Closure + { + return static function (string $key, array $value) { + $cookies = []; + foreach ($value as $cookie) { + if ($cookie instanceof Cookie) { + $c = [ + 'name' => $cookie->getName(), + 'value' => $cookie->getValue(), + 'domain' => $cookie->getDomain(), + 'path' => $cookie->getPath(), + 'secure' => $cookie->isSecure(), + 'httpOnly' => $cookie->isHttpOnly(), + 'sameSite' => $cookie->getSameSite(), + ]; + + $cookies[] = $c; + } else { + $cookies[] = $cookie; + } + } + + try { + return [ + $key => json_encode($cookies, \JSON_THROW_ON_ERROR), + ]; + } catch (\JsonException $exception) { + throw new JsonEncodingException(previous: $exception); + } + }; + } + + /** + * @return (\Closure(string, bool): array) + */ + public static function bool(): \Closure + { + return static fn (string $key, bool $value) => [$key => $value ? 'true' : 'false']; + } + + /** + * @return (\Closure(string, int): array) + */ + public static function int(): \Closure + { + return static fn (string $key, int $value) => [$key => (string) $value]; + } + + /** + * @return (\Closure(string, float): array) + */ + public static function float(): \Closure + { + return static function (string $key, mixed $value) { + [$left, $right] = sscanf((string) $value, '%d.%s') ?? [$value, '']; + + return [$key => $left.'.'.($right ?? '0')]; + }; + } + + /** + * @return (\Closure(string, \BackedEnum): array) + */ + public static function enum(): \Closure + { + return static fn (string $key, \BackedEnum $value) => [$key => (string) $value->value]; + } + + /** + * @return (\Closure(string, RenderedPart|\SplFileInfo): array{files: DataPart}) + */ + public static function content(): \Closure + { + return static function (string $key, RenderedPart|\SplFileInfo $value) { + if ($value instanceof RenderedPart) { + return [ + 'files' => new DataPart($value->body, $value->type->value, 'text/html'), + ]; + } + + return [ + 'files' => new DataPart(new File($value, $key)), + ]; + }; + } + + /** + * @return (\Closure(string, array): list) + */ + public static function asset(): \Closure + { + return static function (string $key, array $assets): array { + $multipart = []; + foreach ($assets as $asset) { + $multipart[] = [ + 'files' => new DataPart(new File($asset)), + ]; + } + + return $multipart; + }; + } + + /** + * @return (\Closure(string, array): array) + */ + public static function route(RequestContext|null $requestContext, UrlGeneratorInterface $urlGenerator): \Closure + { + return static function (string $key, array $value) use ($requestContext, $urlGenerator): array { + [$route, $parameters] = $value; + + $context = $urlGenerator->getContext(); + + if (null !== $requestContext) { + $urlGenerator->setContext($requestContext); + } + + try { + return ['url' => $urlGenerator->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL)]; + } finally { + $urlGenerator->setContext($context); + } + }; + } +} diff --git a/src/Builder/Util/ValidatorFactory.php b/src/Builder/Util/ValidatorFactory.php new file mode 100644 index 00000000..87b6b5c5 --- /dev/null +++ b/src/Builder/Util/ValidatorFactory.php @@ -0,0 +1,89 @@ +|Cookie> $cookies + */ + public static function cookies(array $cookies): void + { + foreach ($cookies as $cookie) { + if (\is_array($cookie)) { + $keys = array_keys($cookie); + + $fields = ['name', 'value', 'domain', 'path', 'secure', 'httpOnly', 'sameSite']; + if ([] !== array_diff($keys, $fields)) { + throw new InvalidBuilderConfiguration('Invalid cookies schema.'); + } + $required = ['name', 'value', 'domain']; + if ([] !== array_diff($required, $keys)) { + throw new InvalidBuilderConfiguration('Invalid cookies schema.'); + } + } + } + } + + /** + * @param \SplFileInfo[] $files + * @param string[] $validExtensions + */ + public static function filesExtension(array $files, array $validExtensions): void + { + foreach ($files as $file) { + if (!$file instanceof \SplFileInfo) { + throw new InvalidBuilderConfiguration(\sprintf('The option "files" expects an array of "%s" instances, but got "%s".', \SplFileInfo::class, $file)); + } + + $ext = $file->getExtension(); + if (!\in_array($ext, $validExtensions, true)) { + throw new InvalidBuilderConfiguration(\sprintf('The file extension "%s" is not valid in this context.', $ext)); + } + } + } + + /** + * @param list}> $downloadFrom + */ + public static function download(array $downloadFrom): void + { + foreach ($downloadFrom as $file) { + if (!\array_key_exists('url', $file)) { + throw new InvalidBuilderConfiguration('"url" is mandatory into "downloadFrom" array field.'); + } + } + } + + public static function splitSpan(string $value): void + { + if (!preg_match('/([\d]+[-][\d]+)/', $value) !== 1 && preg_match('/(\d+)/', $value) !== 1) { + throw new InvalidBuilderConfiguration('Invalid value, the range value format need to look like e.g 1-20 or as a single int value e.g 2.'); + } + } + + public static function quality(int $value): void + { + if ($value < 0 || $value > 100) { + throw new InvalidBuilderConfiguration(\sprintf('The value "%s" must be between 0 and 100.', $value)); + } + } +} diff --git a/src/Builder/ValueObject/RenderedPart.php b/src/Builder/ValueObject/RenderedPart.php new file mode 100644 index 00000000..66ba4dde --- /dev/null +++ b/src/Builder/ValueObject/RenderedPart.php @@ -0,0 +1,14 @@ +prepareHeaders($formData)); - - $response = $this->client->request( - 'POST', - $endpoint, - [ - 'headers' => $headers, - 'body' => $formData->bodyToString(), - ], - ); - - if (!\in_array($response->getStatusCode(), [200, 204], true)) { - throw new ClientException($response->getContent(false), $response->getStatusCode()); + $headers = $payload->getHeaders(); + $formDataPart = $payload->getFormData(); + foreach ($formDataPart->getPreparedHeaders()->all() as $header) { + $headers->add($header); } - return new GotenbergResponse($this->client->stream($response), $response->getStatusCode(), new ResponseHeaderBag($response->getHeaders())); + try { + return $this->client->request( + 'POST', + $endpoint, + [ + 'headers' => $headers->toArray(), + 'body' => $formDataPart->bodyToIterable(), + ], + ); + } catch (ExceptionInterface $e) { + throw new ClientException($e->getMessage(), $e->getCode(), $e); + } } - /** - * @return array - */ - private function prepareHeaders(FormDataPart $dataPart): array + public function stream(ResponseInterface $response): ResponseStreamInterface { - $preparedHeaders = $dataPart->getPreparedHeaders(); - - $headers = []; - foreach ($preparedHeaders->getNames() as $header) { - $headers[$header] = $preparedHeaders->get($header)?->getBodyAsString(); - } - - return $headers; + return $this->client->stream($response); } } diff --git a/src/Client/GotenbergClientInterface.php b/src/Client/GotenbergClientInterface.php index 12dab586..d7cd3081 100644 --- a/src/Client/GotenbergClientInterface.php +++ b/src/Client/GotenbergClientInterface.php @@ -2,11 +2,13 @@ namespace Sensiolabs\GotenbergBundle\Client; +use Sensiolabs\GotenbergBundle\Builder\Payload; +use Symfony\Contracts\HttpClient\ResponseInterface; +use Symfony\Contracts\HttpClient\ResponseStreamInterface; + interface GotenbergClientInterface { - /** - * @param array> $multipartFormData - * @param array $headers - */ - public function call(string $endpoint, array $multipartFormData, array $headers = []): GotenbergResponse; + public function call(string $endpoint, Payload $payload): ResponseInterface; + + public function stream(ResponseInterface $response): ResponseStreamInterface; } diff --git a/src/Client/GotenbergResponse.php b/src/Client/GotenbergResponse.php deleted file mode 100644 index 34cc2cb2..00000000 --- a/src/Client/GotenbergResponse.php +++ /dev/null @@ -1,55 +0,0 @@ -stream; - } - - public function getStatusCode(): int - { - return $this->statusCode; - } - - public function getHeaders(): ResponseHeaderBag - { - return $this->headers; - } - - public function getFileName(): string|null - { - $disposition = $this->headers->get('content-disposition', ''); - /* @see https://onlinephp.io/c/c2606 */ - if (1 === preg_match('#[^;]*;\sfilename="?(?P[^"]*)"?#', $disposition, $matches)) { - return $matches['fileName']; - } - - return null; - } - - /** - * @return non-negative-int|null - */ - public function getContentLength(): int|null - { - $length = $this->headers->get('content-length'); - if (null !== $length) { - return abs((int) $length); - } - - return null; - } -} diff --git a/src/Configurator/BuilderConfigurator.php b/src/Configurator/BuilderConfigurator.php new file mode 100644 index 00000000..e1ac3c27 --- /dev/null +++ b/src/Configurator/BuilderConfigurator.php @@ -0,0 +1,41 @@ +, array> $configurations + * @param array, array> $values + */ + public function __construct( + private readonly array $configurations, + private readonly array $values, + ) { + } + + public function __invoke(BuilderInterface $builder): void + { + $configuration = $this->configurations[$builder::class]; + $values = $this->values[$builder::class]; + + foreach ($configuration as $key => $configurationMap) { + $value = $values[$key] ?? null; + if (null === $value) { + continue; + } + + if (null !== $configurationMap['callback']) { + $value = $configurationMap['callback']($value); + } + + if (\is_array($value) && true === $configurationMap['mustUseVariadic']) { + $builder->{$configurationMap['method']}(...$value); + } else { + $builder->{$configurationMap['method']}($value); + } + } + } +} diff --git a/src/DataCollector/GotenbergDataCollector.php b/src/DataCollector/GotenbergDataCollector.php index a047b679..fe3a8082 100644 --- a/src/DataCollector/GotenbergDataCollector.php +++ b/src/DataCollector/GotenbergDataCollector.php @@ -2,10 +2,9 @@ namespace Sensiolabs\GotenbergBundle\DataCollector; -use Sensiolabs\GotenbergBundle\Builder\Pdf\PdfBuilderInterface; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\ScreenshotBuilderInterface; -use Sensiolabs\GotenbergBundle\Debug\Builder\TraceablePdfBuilder; -use Sensiolabs\GotenbergBundle\Debug\Builder\TraceableScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; +use Sensiolabs\GotenbergBundle\Debug\Builder\TraceableBuilder; +use Sensiolabs\GotenbergBundle\Debug\Client\TraceableGotenbergClient; use Sensiolabs\GotenbergBundle\Debug\TraceableGotenbergPdf; use Sensiolabs\GotenbergBundle\Debug\TraceableGotenbergScreenshot; use Symfony\Component\DependencyInjection\ServiceLocator; @@ -20,20 +19,20 @@ final class GotenbergDataCollector extends DataCollector implements LateDataCollectorInterface { /** - * @param ServiceLocator $builders - * @param array $defaultOptions + * @param ServiceLocator $builders + * @param array $defaultOptions */ public function __construct( private readonly TraceableGotenbergPdf $traceableGotenbergPdf, private readonly TraceableGotenbergScreenshot $traceableGotenbergScreenshot, private readonly ServiceLocator $builders, + private readonly TraceableGotenbergClient $traceableGotenbergClient, private readonly array $defaultOptions, ) { } public function collect(Request $request, Response $response, \Throwable|null $exception = null): void { - $this->data['request_total_memory'] = 0; $this->data['request_total_size'] = 0; $this->data['request_total_time'] = 0; $this->data['request_count'] = 0; @@ -42,7 +41,7 @@ public function collect(Request $request, Response $response, \Throwable|null $e foreach ($this->builders->getProvidedServices() as $id => $type) { $builder = $this->builders->get($id); - if ($builder instanceof TraceablePdfBuilder || $builder instanceof TraceableScreenshotBuilder) { + if ($builder instanceof TraceableBuilder) { $builder = $builder->getInner(); } @@ -71,21 +70,22 @@ public function lateCollect(): void } /** - * @param list $builders + * @param list $builders */ private function lateCollectFiles(array $builders, string $type): void { foreach ($builders as [$id, $builder]) { foreach ($builder->getFiles() as $request) { $this->data['request_total_time'] += $request['time']; - $this->data['request_total_memory'] += $request['memory']; $this->data['request_total_size'] += $request['size'] ?? 0; $this->data['files'][] = [ 'builderClass' => $builder->getInner()::class, 'configuration' => [ - 'options' => $this->cloneVar([]), - 'default_options' => $this->cloneVar($this->defaultOptions[$id] ?? []), + 'default_options' => $this->cloneVar($this->defaultOptions[$type][$id] ?? []), ], + 'payload' => $this->cloneVar( + $this->traceableGotenbergClient->getPayload()[$this->getRequestCount()] ?? [], + ), 'type' => $type, 'request_type' => $request['type'], 'time' => $request['time'], @@ -139,6 +139,7 @@ private function formatSize(int $size): array * size: int<0, max>|null, * fileName: string, * configuration: array>, + * payload: array>, * calls: listdata['request_total_time'] ?? 0.0; } - public function getRequestTotalMemory(): int - { - return $this->data['request_total_memory'] ?? 0; - } - /** * @return array{float, string} */ diff --git a/src/Debug/Builder/TraceablePdfBuilder.php b/src/Debug/Builder/TraceableBuilder.php similarity index 63% rename from src/Debug/Builder/TraceablePdfBuilder.php rename to src/Debug/Builder/TraceableBuilder.php index 318c45bf..32c45d13 100644 --- a/src/Debug/Builder/TraceablePdfBuilder.php +++ b/src/Debug/Builder/TraceableBuilder.php @@ -2,20 +2,22 @@ namespace Sensiolabs\GotenbergBundle\Debug\Builder; -use Sensiolabs\GotenbergBundle\Builder\AsyncBuilderInterface; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Pdf\PdfBuilderInterface; +use Sensiolabs\GotenbergBundle\Builder\BuilderAsyncInterface; +use Sensiolabs\GotenbergBundle\Builder\BuilderFileInterface; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; +use Sensiolabs\GotenbergBundle\Builder\Result\GotenbergAsyncResult; +use Sensiolabs\GotenbergBundle\Builder\Result\GotenbergFileResult; use Symfony\Component\Stopwatch\Stopwatch; -final class TraceablePdfBuilder implements PdfBuilderInterface +final class TraceableBuilder implements BuilderFileInterface, BuilderAsyncInterface { /** - * @var list|null, 'fileName': string|null, 'calls': list, 'arguments': array}>}> + * @var list|null, 'fileName': string|null, 'calls': list, 'arguments': array}>}> */ - private array $pdfs = []; + private array $files = []; /** - * @var list, 'method': string, 'arguments': array}> + * @var list, 'method': string, 'arguments': array}> */ private array $calls = []; @@ -24,13 +26,17 @@ final class TraceablePdfBuilder implements PdfBuilderInterface private static int $count = 0; public function __construct( - private readonly PdfBuilderInterface $inner, + private readonly BuilderFileInterface|BuilderAsyncInterface $inner, private readonly Stopwatch|null $stopwatch, ) { } public function generate(): GotenbergFileResult { + if (!$this->inner instanceof BuilderFileInterface) { + throw new \LogicException(\sprintf('The inner builder of %s must implement %s.', self::class, BuilderFileInterface::class)); + } + $name = self::$count.'.'.$this->inner::class.'::'.__FUNCTION__; ++self::$count; @@ -38,7 +44,7 @@ public function generate(): GotenbergFileResult $response = $this->inner->generate(); $swEvent?->stop(); - $this->pdfs[] = [ + $this->files[] = [ 'type' => 'sync', 'calls' => $this->calls, 'time' => $swEvent?->getDuration(), @@ -52,20 +58,20 @@ public function generate(): GotenbergFileResult return $response; } - public function generateAsync(): void + public function generateAsync(): GotenbergAsyncResult { - if (!$this->inner instanceof AsyncBuilderInterface) { - throw new \LogicException(\sprintf('The inner builder of %s must implement %s.', self::class, AsyncBuilderInterface::class)); + if (!$this->inner instanceof BuilderAsyncInterface) { + throw new \LogicException(\sprintf('The inner builder of %s must implement %s.', self::class, BuilderAsyncInterface::class)); } $name = self::$count.'.'.$this->inner::class.'::'.__FUNCTION__; ++self::$count; $swEvent = $this->stopwatch?->start($name, 'gotenberg.generate_pdf'); - $this->inner->generateAsync(); + $response = $this->inner->generateAsync(); $swEvent?->stop(); - $this->pdfs[] = [ + $this->files[] = [ 'type' => 'async', 'calls' => $this->calls, 'time' => $swEvent?->getDuration(), @@ -75,6 +81,8 @@ public function generateAsync(): void ]; ++$this->totalGenerated; + + return $response; } /** @@ -98,14 +106,14 @@ public function __call(string $name, array $arguments): mixed } /** - * @return list|null, 'fileName': string|null, 'calls': list, 'method': string, 'arguments': array}>}> + * @return list|null, 'fileName': string|null, 'calls': list, 'method': string, 'arguments': array}>}> */ public function getFiles(): array { - return $this->pdfs; + return $this->files; } - public function getInner(): PdfBuilderInterface + public function getInner(): BuilderFileInterface|BuilderAsyncInterface { return $this->inner; } diff --git a/src/Debug/Builder/TraceableScreenshotBuilder.php b/src/Debug/Builder/TraceableScreenshotBuilder.php deleted file mode 100644 index fdedbaec..00000000 --- a/src/Debug/Builder/TraceableScreenshotBuilder.php +++ /dev/null @@ -1,113 +0,0 @@ -|null, 'fileName': string|null, 'calls': list, 'arguments': array}>}> - */ - private array $screenshots = []; - - /** - * @var list, 'method': string, 'arguments': array}> - */ - private array $calls = []; - - private int $totalGenerated = 0; - - private static int $count = 0; - - public function __construct( - private readonly ScreenshotBuilderInterface $inner, - private readonly Stopwatch|null $stopwatch, - ) { - } - - public function generate(): GotenbergFileResult - { - $name = self::$count.'.'.$this->inner::class.'::'.__FUNCTION__; - ++self::$count; - - $swEvent = $this->stopwatch?->start($name, 'gotenberg.generate_screenshot'); - $response = $this->inner->generate(); - $swEvent?->stop(); - - $this->screenshots[] = [ - 'type' => 'sync', - 'calls' => $this->calls, - 'time' => $swEvent?->getDuration(), - 'memory' => $swEvent?->getMemory(), - 'status' => $response->getStatusCode(), - 'size' => $response->getContentLength(), - 'fileName' => $response->getFileName(), - ]; - - ++$this->totalGenerated; - - return $response; - } - - public function generateAsync(): void - { - if (!$this->inner instanceof AsyncBuilderInterface) { - throw new \LogicException(\sprintf('The inner builder of %s must implement %s.', self::class, AsyncBuilderInterface::class)); - } - - $name = self::$count.'.'.$this->inner::class.'::'.__FUNCTION__; - ++self::$count; - - $swEvent = $this->stopwatch?->start($name, 'gotenberg.generate_screenshot'); - $this->inner->generateAsync(); - $swEvent?->stop(); - - $this->screenshots[] = [ - 'type' => 'async', - 'calls' => $this->calls, - 'time' => $swEvent?->getDuration(), - 'memory' => $swEvent?->getMemory(), - 'size' => null, - 'fileName' => null, - ]; - - ++$this->totalGenerated; - } - - /** - * @param array $arguments - */ - public function __call(string $name, array $arguments): mixed - { - $result = $this->inner->$name(...$arguments); - - $this->calls[] = [ - 'class' => $this->inner::class, - 'method' => $name, - 'arguments' => $arguments, - ]; - - if ($result === $this->inner) { - return $this; - } - - return $result; - } - - /** - * @return list|null, 'fileName': string|null, 'calls': list, 'method': string, 'arguments': array}>}> - */ - public function getFiles(): array - { - return $this->screenshots; - } - - public function getInner(): ScreenshotBuilderInterface - { - return $this->inner; - } -} diff --git a/src/Debug/Client/TraceableGotenbergClient.php b/src/Debug/Client/TraceableGotenbergClient.php new file mode 100644 index 00000000..d44ed68e --- /dev/null +++ b/src/Debug/Client/TraceableGotenbergClient.php @@ -0,0 +1,45 @@ +, 'body': list>}> + */ + private array $payload = []; + + public function __construct(private readonly GotenbergClientInterface $inner) + { + } + + public function call(string $endpoint, Payload $payload): ResponseInterface + { + $response = $this->inner->call($endpoint, $payload); + + $this->payload[] = [ + 'headers' => $payload->getHeadersOptions(), + 'body' => $payload->getBodyOptions(), + ]; + + return $response; + } + + public function stream(ResponseInterface $response): ResponseStreamInterface + { + return $this->inner->stream($response); + } + + /** + * @return list, 'body': list>}> + */ + public function getPayload(): array + { + return $this->payload; + } +} diff --git a/src/Debug/TraceableGotenbergPdf.php b/src/Debug/TraceableGotenbergPdf.php index 09cfc7f7..15033ab8 100644 --- a/src/Debug/TraceableGotenbergPdf.php +++ b/src/Debug/TraceableGotenbergPdf.php @@ -2,21 +2,22 @@ namespace Sensiolabs\GotenbergBundle\Debug; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\FlattenPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\PdfBuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\SplitPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder; -use Sensiolabs\GotenbergBundle\Debug\Builder\TraceablePdfBuilder; +use Sensiolabs\GotenbergBundle\Debug\Builder\TraceableBuilder; use Sensiolabs\GotenbergBundle\GotenbergPdfInterface; final class TraceableGotenbergPdf implements GotenbergPdfInterface { /** - * @var list + * @var list */ private array $builders = []; @@ -25,11 +26,11 @@ public function __construct( ) { } - public function get(string $builder): PdfBuilderInterface + public function get(string $builder): BuilderInterface { $traceableBuilder = $this->inner->get($builder); - if (!$traceableBuilder instanceof TraceablePdfBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -39,14 +40,14 @@ public function get(string $builder): PdfBuilderInterface } /** - * @return HtmlPdfBuilder|TraceablePdfBuilder + * @return HtmlPdfBuilder|TraceableBuilder */ - public function html(): PdfBuilderInterface + public function html(): BuilderInterface { - /** @var HtmlPdfBuilder|TraceablePdfBuilder $traceableBuilder */ + /** @var HtmlPdfBuilder|TraceableBuilder $traceableBuilder */ $traceableBuilder = $this->inner->html(); - if (!$traceableBuilder instanceof TraceablePdfBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -56,14 +57,14 @@ public function html(): PdfBuilderInterface } /** - * @return UrlPdfBuilder|TraceablePdfBuilder + * @return UrlPdfBuilder|TraceableBuilder */ - public function url(): PdfBuilderInterface + public function url(): BuilderInterface { - /** @var UrlPdfBuilder|TraceablePdfBuilder $traceableBuilder */ + /** @var UrlPdfBuilder|TraceableBuilder $traceableBuilder */ $traceableBuilder = $this->inner->url(); - if (!$traceableBuilder instanceof TraceablePdfBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -73,48 +74,48 @@ public function url(): PdfBuilderInterface } /** - * @return LibreOfficePdfBuilder|TraceablePdfBuilder + * @return MarkdownPdfBuilder|TraceableBuilder */ - public function office(): PdfBuilderInterface + public function markdown(): BuilderInterface { - /** @var LibreOfficePdfBuilder|TraceablePdfBuilder $traceableBuilder */ - $traceableBuilder = $this->inner->office(); + /** @var MarkdownPdfBuilder|TraceableBuilder $traceableBuilder */ + $traceableBuilder = $this->inner->markdown(); - if (!$traceableBuilder instanceof TraceablePdfBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } - $this->builders[] = ['office', $traceableBuilder]; + $this->builders[] = ['markdown', $traceableBuilder]; return $traceableBuilder; } /** - * @return MarkdownPdfBuilder|TraceablePdfBuilder + * @return LibreOfficePdfBuilder|TraceableBuilder */ - public function markdown(): PdfBuilderInterface + public function office(): BuilderInterface { - /** @var MarkdownPdfBuilder|TraceablePdfBuilder $traceableBuilder */ - $traceableBuilder = $this->inner->markdown(); + /** @var LibreOfficePdfBuilder|TraceableBuilder $traceableBuilder */ + $traceableBuilder = $this->inner->office(); - if (!$traceableBuilder instanceof TraceablePdfBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } - $this->builders[] = ['markdown', $traceableBuilder]; + $this->builders[] = ['office', $traceableBuilder]; return $traceableBuilder; } /** - * @return MergePdfBuilder|TraceablePdfBuilder + * @return MergePdfBuilder|TraceableBuilder */ - public function merge(): PdfBuilderInterface + public function merge(): BuilderInterface { - /** @var MergePdfBuilder|TraceablePdfBuilder $traceableBuilder */ + /** @var MergePdfBuilder|TraceableBuilder $traceableBuilder */ $traceableBuilder = $this->inner->merge(); - if (!$traceableBuilder instanceof TraceablePdfBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -124,14 +125,14 @@ public function merge(): PdfBuilderInterface } /** - * @return ConvertPdfBuilder|TraceablePdfBuilder + * @return ConvertPdfBuilder|TraceableBuilder */ - public function convert(): PdfBuilderInterface + public function convert(): BuilderInterface { - /** @var ConvertPdfBuilder|TraceablePdfBuilder $traceableBuilder */ + /** @var ConvertPdfBuilder|TraceableBuilder $traceableBuilder */ $traceableBuilder = $this->inner->convert(); - if (!$traceableBuilder instanceof TraceablePdfBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -141,14 +142,14 @@ public function convert(): PdfBuilderInterface } /** - * @return SplitPdfBuilder|TraceablePdfBuilder + * @return SplitPdfBuilder|TraceableBuilder */ - public function split(): PdfBuilderInterface + public function split(): BuilderInterface { - /** @var SplitPdfBuilder|TraceablePdfBuilder $traceableBuilder */ + /** @var SplitPdfBuilder|TraceableBuilder $traceableBuilder */ $traceableBuilder = $this->inner->split(); - if (!$traceableBuilder instanceof TraceablePdfBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -158,7 +159,24 @@ public function split(): PdfBuilderInterface } /** - * @return list + * @return FlattenPdfBuilder|TraceableBuilder + */ + public function flatten(): BuilderInterface + { + /** @var FlattenPdfBuilder|TraceableBuilder $traceableBuilder */ + $traceableBuilder = $this->inner->flatten(); + + if (!$traceableBuilder instanceof TraceableBuilder) { + return $traceableBuilder; + } + + $this->builders[] = ['flatten', $traceableBuilder]; + + return $traceableBuilder; + } + + /** + * @return list */ public function getBuilders(): array { diff --git a/src/Debug/TraceableGotenbergScreenshot.php b/src/Debug/TraceableGotenbergScreenshot.php index 002610f7..f583822b 100644 --- a/src/Debug/TraceableGotenbergScreenshot.php +++ b/src/Debug/TraceableGotenbergScreenshot.php @@ -2,17 +2,17 @@ namespace Sensiolabs\GotenbergBundle\Debug; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder; use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\ScreenshotBuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Debug\Builder\TraceableScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Debug\Builder\TraceableBuilder; use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface; final class TraceableGotenbergScreenshot implements GotenbergScreenshotInterface { /** - * @var list + * @var list */ private array $builders = []; @@ -21,11 +21,11 @@ public function __construct( ) { } - public function get(string $builder): ScreenshotBuilderInterface + public function get(string $builder): BuilderInterface { $traceableBuilder = $this->inner->get($builder); - if (!$traceableBuilder instanceof TraceableScreenshotBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -35,14 +35,14 @@ public function get(string $builder): ScreenshotBuilderInterface } /** - * @return HtmlScreenshotBuilder|TraceableScreenshotBuilder + * @return HtmlScreenshotBuilder|TraceableBuilder */ - public function html(): ScreenshotBuilderInterface + public function html(): BuilderInterface { - /** @var HtmlScreenshotBuilder|TraceableScreenshotBuilder $traceableBuilder */ + /** @var HtmlScreenshotBuilder|TraceableBuilder $traceableBuilder */ $traceableBuilder = $this->inner->html(); - if (!$traceableBuilder instanceof TraceableScreenshotBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -52,14 +52,14 @@ public function html(): ScreenshotBuilderInterface } /** - * @return UrlScreenshotBuilder|TraceableScreenshotBuilder + * @return UrlScreenshotBuilder|TraceableBuilder */ - public function url(): ScreenshotBuilderInterface + public function url(): BuilderInterface { - /** @var UrlScreenshotBuilder|TraceableScreenshotBuilder $traceableBuilder */ + /** @var UrlScreenshotBuilder|TraceableBuilder $traceableBuilder */ $traceableBuilder = $this->inner->url(); - if (!$traceableBuilder instanceof TraceableScreenshotBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -69,14 +69,14 @@ public function url(): ScreenshotBuilderInterface } /** - * @return MarkdownScreenshotBuilder|TraceableScreenshotBuilder + * @return MarkdownScreenshotBuilder|TraceableBuilder */ - public function markdown(): ScreenshotBuilderInterface + public function markdown(): BuilderInterface { - /** @var MarkdownScreenshotBuilder|TraceableScreenshotBuilder $traceableBuilder */ + /** @var MarkdownScreenshotBuilder|TraceableBuilder $traceableBuilder */ $traceableBuilder = $this->inner->markdown(); - if (!$traceableBuilder instanceof TraceableScreenshotBuilder) { + if (!$traceableBuilder instanceof TraceableBuilder) { return $traceableBuilder; } @@ -86,7 +86,7 @@ public function markdown(): ScreenshotBuilderInterface } /** - * @return list + * @return list */ public function getBuilders(): array { diff --git a/src/DependencyInjection/BuilderStack.php b/src/DependencyInjection/BuilderStack.php new file mode 100644 index 00000000..51207a0f --- /dev/null +++ b/src/DependencyInjection/BuilderStack.php @@ -0,0 +1,138 @@ +, string> + */ + private array $builders = []; + + /** + * @var array>> + */ + private array $typeReverseMapping = []; + + /** + * @var array, array|null}>> + */ + private array $configMapping = []; + + /** + * @var array>> + */ + private array $configNode = []; + + /** + * @param class-string $class + */ + public function push(string $class): void + { + if (!is_a($class, BuilderInterface::class, true)) { + throw new \LogicException(\sprintf('Only classes implementing %s are supported.', BuilderInterface::class)); + } + + if (\array_key_exists($class, $this->builders)) { + throw new \LogicException("{$class} has already been added."); + } + + $type = 'custom'; + if (method_exists($class, 'type')) { + $type = $class::type(); + } + + if (!\in_array($type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock + throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); + } + + $this->builders[$class] = $type; + + $reflection = new \ReflectionClass($class); + $nodeAttributes = $reflection->getAttributes(SemanticNode::class); + + if (\count($nodeAttributes) === 0) { + throw new \LogicException(\sprintf('%s is missing the %s attribute', $class, SemanticNode::class)); + } + + /** @var SemanticNode $semanticNode */ + $semanticNode = $nodeAttributes[0]->newInstance(); + + $this->typeReverseMapping[$type][$semanticNode->name] = $class; + + foreach (array_reverse($reflection->getMethods(\ReflectionMethod::IS_PUBLIC)) as $method) { + $attributes = $method->getAttributes(ExposeSemantic::class); + if (\count($attributes) === 0) { + continue; + } + + /** @var ExposeSemantic $attribute */ + $attribute = $attributes[0]->newInstance(); + + $mustUseVariadic = false; + $callback = null; + + if ($attribute->node instanceof ArrayNodeBuilder) { + $mustUseVariadic = null === $attribute->node->prototype; + } elseif ($attribute->node instanceof NativeEnumNodeBuilder) { + $callback = [$attribute->node->enumClass, 'from']; + } elseif ($attribute->node instanceof UnitNodeBuilder) { + $callback = [Unit::class, 'parse']; + $mustUseVariadic = true; + } + + $this->configMapping[$class] ??= []; + $this->configMapping[$class][$attribute->node->getName()] = [ + 'method' => $method->getName(), + 'mustUseVariadic' => $mustUseVariadic, + 'callback' => $callback, + ]; + + $this->configNode[$type][$semanticNode->name][] = $attribute->node; + } + } + + /** + * @return array, string> + */ + public function getBuilders(): array + { + return $this->builders; + } + + /** + * @return array>> + */ + public function getTypeReverseMapping(): array + { + return $this->typeReverseMapping; + } + + /** + * @return array, array|null}>> + */ + public function getConfigMapping(): array + { + return $this->configMapping; + } + + /** + * @return array>> + */ + public function getConfigNode(): array + { + return $this->configNode; + } +} diff --git a/src/DependencyInjection/CompilerPass/GotenbergPass.php b/src/DependencyInjection/CompilerPass/GotenbergPass.php index d6d28026..cfa8759b 100644 --- a/src/DependencyInjection/CompilerPass/GotenbergPass.php +++ b/src/DependencyInjection/CompilerPass/GotenbergPass.php @@ -2,47 +2,57 @@ namespace Sensiolabs\GotenbergBundle\DependencyInjection\CompilerPass; -use Sensiolabs\GotenbergBundle\Debug\Builder\TraceablePdfBuilder; -use Sensiolabs\GotenbergBundle\Debug\Builder\TraceableScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Debug\Builder\TraceableBuilder; +use Sensiolabs\GotenbergBundle\DependencyInjection\BuilderStack; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Reference; final class GotenbergPass implements CompilerPassInterface { - public function process(ContainerBuilder $container): void - { - $this->makePdfBuildersTraceable($container); - $this->makeScreenshotBuildersTraceable($container); + public function __construct( + private readonly BuilderStack $builderStack, + ) { } - private function makePdfBuildersTraceable(ContainerBuilder $container): void + public function process(ContainerBuilder $container): void { - if (!$container->has('sensiolabs_gotenberg.data_collector')) { - return; + $builderPerType = []; + foreach ($container->findTaggedServiceIds('sensiolabs_gotenberg.builder') as $serviceId => $tags) { + $serviceDefinition = $container->getDefinition($serviceId); + $serviceDefinition + ->setShared(false) + ; + + $class = $serviceDefinition->getClass(); + + $type = $this->builderStack->getBuilders()[$class]; + + $builderPerType[$type] ??= []; + $builderPerType[$type][] = new Reference($serviceId); } - foreach ($container->findTaggedServiceIds('sensiolabs_gotenberg.pdf_builder') as $serviceId => $tags) { - $container->register('.debug.'.ltrim($serviceId, '.'), TraceablePdfBuilder::class) - ->setDecoratedService($serviceId) - ->setShared(false) - ->setArguments([ - '$inner' => new Reference('.inner'), - '$stopwatch' => new Reference('debug.stopwatch', ContainerInterface::NULL_ON_INVALID_REFERENCE), - ]) + if ($container->hasDefinition('sensiolabs_gotenberg.pdf')) { + $container->getDefinition('sensiolabs_gotenberg.pdf') + ->replaceArgument(0, ServiceLocatorTagPass::register($container, $builderPerType['pdf'])) + ; + } + + if ($container->hasDefinition('sensiolabs_gotenberg.screenshot')) { + $container->getDefinition('sensiolabs_gotenberg.screenshot') + ->replaceArgument(0, ServiceLocatorTagPass::register($container, $builderPerType['screenshot'])) ; } - } - private function makeScreenshotBuildersTraceable(ContainerBuilder $container): void - { if (!$container->has('sensiolabs_gotenberg.data_collector')) { return; } - foreach ($container->findTaggedServiceIds('sensiolabs_gotenberg.screenshot_builder') as $serviceId => $tags) { - $container->register('.debug.'.ltrim($serviceId, '.'), TraceableScreenshotBuilder::class) + foreach ($container->findTaggedServiceIds('sensiolabs_gotenberg.builder') as $serviceId => $tags) { + $container + ->register('.debug.'.ltrim($serviceId, '.'), TraceableBuilder::class) ->setDecoratedService($serviceId) ->setShared(false) ->setArguments([ diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 347e1e7b..91e66c07 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -2,19 +2,21 @@ namespace Sensiolabs\GotenbergBundle\DependencyInjection; -use Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType; -use Sensiolabs\GotenbergBundle\Enumeration\ImageResolutionDPI; -use Sensiolabs\GotenbergBundle\Enumeration\PaperSize; -use Sensiolabs\GotenbergBundle\Enumeration\PdfFormat; -use Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat; -use Sensiolabs\GotenbergBundle\Enumeration\SplitMode; -use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Sensiolabs\GotenbergBundle\NodeBuilder\NodeBuilderInterface; use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; class Configuration implements ConfigurationInterface { + /** + * @param array>> $builders + */ + public function __construct( + private readonly array $builders, + ) { + } + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('sensiolabs_gotenberg'); @@ -44,645 +46,49 @@ public function getConfigTreeBuilder(): TreeBuilder ->info('Enables the listener on kernel.view to stream GotenbergFileResult object.') ->end() ->append($this->addNamedWebhookDefinition()) - ->arrayNode('default_options') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('webhook') - ->info('Webhook configuration name.') - ->end() - ->arrayNode('pdf') - ->addDefaultsIfNotSet() - ->append($this->addPdfHtmlNode()) - ->append($this->addPdfUrlNode()) - ->append($this->addPdfMarkdownNode()) - ->append($this->addPdfOfficeNode()) - ->append($this->addPdfMergeNode()) - ->append($this->addPdfConvertNode()) - ->append($this->addPdfSplitNode()) - ->end() - ->arrayNode('screenshot') - ->addDefaultsIfNotSet() - ->append($this->addScreenshotHtmlNode()) - ->append($this->addScreenshotUrlNode()) - ->append($this->addScreenshotMarkdownNode()) - ->end() - ->end() - ->end() + ->append($this->addDefaultOptionsNode()) ->end() ; return $treeBuilder; } - private function addPdfHtmlNode(): NodeDefinition - { - $treebuilder = new TreeBuilder('html'); - - $treebuilder - ->getRootNode() - ->addDefaultsIfNotSet() - ; - - $this->addChromiumPdfOptionsNode($treebuilder->getRootNode()); - $this->addWebhookDeclarationNode($treebuilder->getRootNode()); - - return $treebuilder->getRootNode(); - } - - private function addPdfUrlNode(): NodeDefinition - { - $treebuilder = new TreeBuilder('url'); - - $treebuilder - ->getRootNode() - ->addDefaultsIfNotSet() - ; - - $this->addChromiumPdfOptionsNode($treebuilder->getRootNode()); - $this->addWebhookDeclarationNode($treebuilder->getRootNode()); - - return $treebuilder->getRootNode(); - } - - private function addPdfMarkdownNode(): NodeDefinition + private function addDefaultOptionsNode(): NodeDefinition { - $treebuilder = new TreeBuilder('markdown'); - - $treebuilder - ->getRootNode() + $defaultOptionsTreeBuilder = new TreeBuilder('default_options'); + $defaultOptionsTreeBuilder->getRootNode() ->addDefaultsIfNotSet() ; - $this->addChromiumPdfOptionsNode($treebuilder->getRootNode()); - $this->addWebhookDeclarationNode($treebuilder->getRootNode()); - - return $treebuilder->getRootNode(); - } - - private function addScreenshotHtmlNode(): NodeDefinition - { - $treebuilder = new TreeBuilder('html'); - - $treebuilder + $webhookNode = (new TreeBuilder('webhook', 'scalar')) ->getRootNode() - ->addDefaultsIfNotSet() + ->info('Webhook configuration name.') ; - $this->addChromiumScreenshotOptionsNode($treebuilder->getRootNode()); - $this->addWebhookDeclarationNode($treebuilder->getRootNode()); - - return $treebuilder->getRootNode(); - } - - private function addScreenshotUrlNode(): NodeDefinition - { - $treebuilder = new TreeBuilder('url'); - - $treebuilder - ->getRootNode() - ->addDefaultsIfNotSet() - ; - - $this->addChromiumScreenshotOptionsNode($treebuilder->getRootNode()); - $this->addWebhookDeclarationNode($treebuilder->getRootNode()); - - return $treebuilder->getRootNode(); - } - - private function addScreenshotMarkdownNode(): NodeDefinition - { - $treebuilder = new TreeBuilder('markdown'); - - $treebuilder - ->getRootNode() - ->addDefaultsIfNotSet() - ; - - $this->addChromiumScreenshotOptionsNode($treebuilder->getRootNode()); - $this->addWebhookDeclarationNode($treebuilder->getRootNode()); - - return $treebuilder->getRootNode(); - } - - private function addChromiumPdfOptionsNode(ArrayNodeDefinition $parent): void - { - $parent - ->children() - ->arrayNode('header') - ->info('Add default header to the builder.') - ->children() - ->scalarNode('template') - ->info('Default header twig template to apply.') - ->isRequired() - ->cannotBeEmpty() - ->end() - ->arrayNode('context') - ->info('Default context for header twig template.') - ->defaultValue([]) - ->normalizeKeys(false) - ->variablePrototype() - ->end() - ->end() - ->end() - ->end() - ->arrayNode('footer') - ->info('Add default footer to the builder.') - ->children() - ->scalarNode('template') - ->info('Default footer twig template to apply.') - ->isRequired() - ->cannotBeEmpty() - ->end() - ->arrayNode('context') - ->info('Default context for footer twig template.') - ->defaultValue([]) - ->normalizeKeys(false) - ->variablePrototype() - ->end() - ->end() - ->end() - ->end() - ->booleanNode('single_page') - ->info('Define whether to print the entire content in one single page. - default false. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->enumNode('paper_standard_size') - ->info('The standard paper size to use, either "letter", "legal", "tabloid", "ledger", "A0", "A1", "A2", "A3", "A4", "A5", "A6" - default None.') - ->values(array_map(static fn (PaperSize $case): string => $case->value, PaperSize::cases())) - ->defaultNull() - ->end() - ->scalarNode('paper_width') - ->info('Paper width, in inches - default 8.5. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->scalarNode('paper_height') - ->info('Paper height, in inches - default 11. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->scalarNode('margin_top') - ->info('Top margin, in inches - default 0.39. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->scalarNode('margin_bottom') - ->info('Bottom margin, in inches - default 0.39. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->scalarNode('margin_left') - ->info('Left margin, in inches - default 0.39. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->scalarNode('margin_right') - ->info('Right margin, in inches - default 0.39. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->booleanNode('prefer_css_page_size') - ->info('Define whether to prefer page size as defined by CSS - default false. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->booleanNode('generate_document_outline') - ->info('Define whether the document outline should be embedded into the PDF - default false. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->booleanNode('print_background') - ->info('Print the background graphics - default false. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->booleanNode('omit_background') - ->info('Hide the default white background and allow generating PDFs with transparency - default false. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->booleanNode('landscape') - ->info('The paper orientation to landscape - default false. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->floatNode('scale') - ->info('The scale of the page rendering (e.g., 1.0) - default 1.0. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->scalarNode('native_page_ranges') - ->info('Page ranges to print, e.g., "1-5, 8, 11-13" - default All pages. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->validate() - ->ifTrue(static function ($option): bool { - return preg_match('/([\d]+[-][\d]+)/', $option) !== 1; - }) - ->thenInvalid('Invalid range values, the range value format need to look like e.g 1-20.') - ->end() - ->end() - ->scalarNode('wait_delay') - ->info('Duration (e.g, "5s") to wait when loading an HTML document before converting it into PDF - default None. https://gotenberg.dev/docs/routes#wait-before-rendering') - ->defaultNull() - ->validate() - ->ifTrue(static function ($option): bool { - return !\is_string($option); - }) - ->thenInvalid('Invalid value %s') - ->end() - ->end() - ->scalarNode('wait_for_expression') - ->info('The JavaScript expression to wait before converting an HTML document into PDF until it returns true - default None. https://gotenberg.dev/docs/routes#wait-before-rendering') - ->defaultNull() - ->validate() - ->ifTrue(static function ($option): bool { - return !\is_string($option); - }) - ->thenInvalid('Invalid value %s') - ->end() - ->end() - ->enumNode('emulated_media_type') - ->info('The media type to emulate, either "screen" or "print" - default "print". https://gotenberg.dev/docs/routes#emulated-media-type') - ->values(array_map(static fn (EmulatedMediaType $case): string => $case->value, EmulatedMediaType::cases())) - ->defaultNull() - ->end() - ->arrayNode('cookies') - ->info('Cookies to store in the Chromium cookie jar - default None. https://gotenberg.dev/docs/routes#cookies-chromium') - ->defaultValue([]) - ->arrayPrototype() - ->children() - ->scalarNode('name')->end() - ->scalarNode('value')->end() - ->scalarNode('domain')->end() - ->scalarNode('path') - ->defaultNull() - ->end() - ->booleanNode('secure') - ->defaultNull() - ->end() - ->booleanNode('httpOnly') - ->defaultNull() - ->end() - ->enumNode('sameSite') - ->info('Accepted values are "Strict", "Lax" or "None". https://gotenberg.dev/docs/routes#cookies-chromium') - ->values(['Strict', 'Lax', 'None']) - ->defaultNull() - ->end() - ->end() - ->end() - ->end() - ->scalarNode('user_agent') - ->info('Override the default User-Agent HTTP header. - default None. https://gotenberg.dev/docs/routes#custom-http-headers-chromium') - ->defaultNull() - ->validate() - ->ifTrue(static function ($option): bool { - return !\is_string($option); - }) - ->thenInvalid('Invalid value %s') - ->end() - ->end() - ->append($this->addExtraHttpHeadersNode()) - ->arrayNode('fail_on_http_status_codes') - ->info('Return a 409 Conflict response if the HTTP status code from the main page is not acceptable. - default [499,599]. https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium') - ->defaultValue([499, 599]) - ->integerPrototype() - ->end() - ->end() - ->arrayNode('fail_on_resource_http_status_codes') - ->info('Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. - default None. https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium') - ->defaultValue([]) - ->integerPrototype() - ->end() - ->end() - ->booleanNode('fail_on_resource_loading_failed') - ->info('Return a 409 Conflict response if Chromium fails to load at least one resource - default false. https://gotenberg.dev/docs/routes#network-errors-chromium') - ->defaultNull() - ->end() - ->booleanNode('fail_on_console_exceptions') - ->info('Return a 409 Conflict response if there are exceptions in the Chromium console - default false. https://gotenberg.dev/docs/routes#console-exceptions') - ->defaultNull() - ->end() - ->booleanNode('skip_network_idle_event') - ->info('Do not wait for Chromium network to be idle. - default false. https://gotenberg.dev/docs/routes#performance-mode-chromium') - ->defaultNull() - ->end() - ->append($this->addPdfMetadataNode()) - ->append($this->addDownloadFromNode()) - ->end() - ->validate() - ->ifTrue(function ($v): bool { - return isset($v['paper_standard_size']) && (isset($v['paper_height']) || isset($v['paper_width'])); - }) - ->thenInvalid('You cannot use "paper_standard_size" when "paper_height", "paper_width" or both are set".') - ->end() - ; + $defaultOptionsTreeBuilder->getRootNode()->append($webhookNode); - $this->addPdfFormatNode($parent); - $this->addSplitConfigurationNode($parent); - } + foreach ($this->builders as $type => $innerBuilders) { + $typeTreeBuilder = new TreeBuilder($type); + $typeTreeBuilder->getRootNode() + ->addDefaultsIfNotSet() + ; - private function addChromiumScreenshotOptionsNode(ArrayNodeDefinition $parent): void - { - $parent - ->children() - ->integerNode('width') - ->info('The device screen width in pixels. - default 800. https://gotenberg.dev/docs/routes#screenshots-route') - ->defaultNull() - ->end() - ->integerNode('height') - ->info('The device screen height in pixels. - default 600. https://gotenberg.dev/docs/routes#screenshots-route') - ->defaultNull() - ->end() - ->booleanNode('clip') - ->info('Define whether to clip the screenshot according to the device dimensions - default false. https://gotenberg.dev/docs/routes#screenshots-route') - ->defaultNull() - ->end() - ->enumNode('format') - ->info('The image compression format, either "png", "jpeg" or "webp" - default png. https://gotenberg.dev/docs/routes#screenshots-route') - ->values(array_map(static fn (ScreenshotFormat $case): string => $case->value, ScreenshotFormat::cases())) - ->defaultNull() - ->end() - ->integerNode('quality') - ->info('The compression quality from range 0 to 100 (jpeg only) - default 100. https://gotenberg.dev/docs/routes#screenshots-route') - ->min(0) - ->max(100) - ->defaultNull() - ->end() - ->booleanNode('omit_background') - ->info('Hide the default white background and allow generating PDFs with transparency - default false. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->booleanNode('optimize_for_speed') - ->info('Define whether to optimize image encoding for speed, not for resulting size. - default false. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->scalarNode('wait_delay') - ->info('Duration (e.g, "5s") to wait when loading an HTML document before converting it into PDF - default None. https://gotenberg.dev/docs/routes#wait-before-rendering') - ->defaultNull() - ->validate() - ->ifTrue(static function ($option): bool { - return !\is_string($option); - }) - ->thenInvalid('Invalid value %s') - ->end() - ->end() - ->scalarNode('wait_for_expression') - ->info('The JavaScript expression to wait before converting an HTML document into PDF until it returns true - default None. https://gotenberg.dev/docs/routes#wait-before-rendering') - ->defaultNull() - ->validate() - ->ifTrue(static function ($option): bool { - return !\is_string($option); - }) - ->thenInvalid('Invalid value %s') - ->end() - ->end() - ->enumNode('emulated_media_type') - ->info('The media type to emulate, either "screen" or "print" - default "print". https://gotenberg.dev/docs/routes#emulated-media-type') - ->values(array_map(static fn (EmulatedMediaType $case): string => $case->value, EmulatedMediaType::cases())) - ->defaultNull() - ->end() - ->arrayNode('cookies') - ->info('Cookies to store in the Chromium cookie jar - default None. https://gotenberg.dev/docs/routes#cookies-chromium') - ->defaultValue([]) - ->arrayPrototype() - ->children() - ->scalarNode('name')->end() - ->scalarNode('value')->end() - ->scalarNode('domain')->end() - ->scalarNode('path') - ->defaultNull() - ->end() - ->booleanNode('secure') - ->defaultNull() - ->end() - ->booleanNode('httpOnly') - ->defaultNull() - ->end() - ->enumNode('sameSite') - ->info('Accepted values are "Strict", "Lax" or "None". https://gotenberg.dev/docs/routes#cookies-chromium') - ->values(['Strict', 'Lax', 'None']) - ->defaultNull() - ->end() - ->end() - ->end() - ->end() - ->scalarNode('user_agent') - ->info('Override the default User-Agent HTTP header. - default None. https://gotenberg.dev/docs/routes#custom-http-headers-chromium') - ->defaultNull() - ->validate() - ->ifTrue(static function ($option): bool { - return !\is_string($option); - }) - ->thenInvalid('Invalid value %s') - ->end() - ->end() - ->append($this->addExtraHttpHeadersNode()) - ->arrayNode('fail_on_http_status_codes') - ->info('Return a 409 Conflict response if the HTTP status code from the main page is not acceptable. - default [499,599]. https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium') - ->defaultValue([499, 599]) - ->integerPrototype() - ->end() - ->end() - ->arrayNode('fail_on_resource_http_status_codes') - ->info('Return a 409 Conflict response if the HTTP status code from the main page is not acceptable. - default None. https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium') - ->defaultValue([]) - ->integerPrototype() - ->end() - ->end() - ->booleanNode('fail_on_resource_loading_failed') - ->info('Return a 409 Conflict response if Chromium fails to load at least one resource - default false. https://gotenberg.dev/docs/routes#network-errors-chromium') - ->defaultNull() - ->end() - ->booleanNode('fail_on_console_exceptions') - ->info('Return a 409 Conflict response if there are exceptions in the Chromium console - default false. https://gotenberg.dev/docs/routes#console-exceptions') - ->defaultNull() - ->end() - ->booleanNode('skip_network_idle_event') - ->info('Do not wait for Chromium network to be idle. - default false. https://gotenberg.dev/docs/routes#performance-mode-chromium') - ->defaultNull() - ->end() - ->append($this->addDownloadFromNode()) - ->end() - ; - } - - private function addPdfOfficeNode(): NodeDefinition - { - $treeBuilder = new TreeBuilder('office'); - - $treeBuilder->getRootNode() - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('password') - ->info('Set the password for opening the source file. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('landscape') - ->info('The paper orientation to landscape - default false. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->end() - ->scalarNode('native_page_ranges') - ->info('Page ranges to print, e.g., "1-5, 8, 11-13" - default All pages. https://gotenberg.dev/docs/routes#page-properties-chromium') - ->defaultNull() - ->validate() - ->ifTrue(static function ($option): bool { - return preg_match('/([\d]+[-][\d]+)/', $option) !== 1; - }) - ->thenInvalid('Invalid range values, the range value format need to look like e.g 1-20.') - ->end() - ->end() - ->booleanNode('do_not_export_form_fields') - ->info('Set whether to export the form fields or to use the inputted/selected content of the fields. - default true. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('single_page_sheets') - ->info('Set whether to render the entire spreadsheet as a single page. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('merge') - ->info('Merge alphanumerically the resulting PDFs. - default false. https://gotenberg.dev/docs/routes#merge-libreoffice') - ->defaultNull() - ->end() - ->append($this->addPdfMetadataNode()) - ->booleanNode('allow_duplicate_field_names') - ->info('Specify whether multiple form fields exported are allowed to have the same field name. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('do_not_export_bookmarks') - ->info('Specify if bookmarks are exported to PDF. - default true. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('export_bookmarks_to_pdf_destination') - ->info('Specify that the bookmarks contained in the source LibreOffice file should be exported to the PDF file as Named Destination. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('export_placeholders') - ->info('Export the placeholders fields visual markings only. The exported placeholder is ineffective. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('export_notes') - ->info('Specify if notes are exported to PDF. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('export_notes_pages') - ->info('Specify if notes pages are exported to PDF. Notes pages are available in Impress documents only. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('export_only_notes_pages') - ->info('Specify, if the form field exportNotesPages is set to true, if only notes pages are exported to PDF. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('export_notes_in_margin') - ->info('Specify if notes in margin are exported to PDF. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('convert_ooo_target_to_pdf_target') - ->info('Specify that the target documents with .od[tpgs] extension, will have that extension changed to .pdf when the link is exported to PDF. The source document remains untouched. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('export_links_relative_fsys') - ->info('Specify that the file system related hyperlinks (file:// protocol) present in the document will be exported as relative to the source document location. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('export_hidden_slides') - ->info('Export, for LibreOffice Impress, slides that are not included in slide shows. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('skip_empty_pages') - ->info('Specify that automatically inserted empty pages are suppressed. This option is active only if storing Writer documents. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('add_original_document_as_stream') - ->info('Specify that a stream is inserted to the PDF file which contains the original document for archiving purposes. - default false. https://gotenberg.dev/docs/routes#page-properties-libreoffice') - ->defaultNull() - ->end() - ->booleanNode('lossless_image_compression') - ->info('Specify if images are exported to PDF using a lossless compression format like PNG or compressed using the JPEG format. - default false. https://gotenberg.dev/docs/routes#images-libreoffice') - ->defaultNull() - ->end() - ->integerNode('quality') - ->info('Specify the quality of the JPG export. A higher value produces a higher-quality image and a larger file. Between 1 and 100. - default 90. https://gotenberg.dev/docs/routes#images-libreoffice') - ->min(0) - ->max(100) - ->defaultNull() - ->end() - ->booleanNode('reduce_image_resolution') - ->info('Specify if the resolution of each image is reduced to the resolution specified by the form field maxImageResolution. - default false. https://gotenberg.dev/docs/routes#images-libreoffice') - ->defaultNull() - ->end() - ->enumNode('max_image_resolution') - ->info('If the form field reduceImageResolution is set to true, tell if all images will be reduced to the given value in DPI. Possible values are: 75, 150, 300, 600 and 1200. - default 300. https://gotenberg.dev/docs/routes#images-libreoffice') - ->values(array_map(static fn (ImageResolutionDPI $case): int => $case->value, ImageResolutionDPI::cases())) - ->defaultNull() - ->end() - ->append($this->addDownloadFromNode()) - ->end() - ; - - $this->addPdfFormatNode($treeBuilder->getRootNode()); - $this->addSplitConfigurationNode($treeBuilder->getRootNode()); - - return $treeBuilder->getRootNode(); - } - - private function addPdfConvertNode(): NodeDefinition - { - $treeBuilder = new TreeBuilder('convert'); - $this->addPdfFormatNode($treeBuilder->getRootNode()); - $treeBuilder->getRootNode() - ->append($this->addDownloadFromNode()) - ->end(); - - return $treeBuilder->getRootNode(); - } - - private function addPdfMergeNode(): NodeDefinition - { - $treeBuilder = new TreeBuilder('merge'); - $this->addPdfFormatNode($treeBuilder->getRootNode()); - $treeBuilder->getRootNode() - ->append($this->addPdfMetadataNode()) - ->append($this->addDownloadFromNode()) - ->end(); + foreach ($innerBuilders as $builderType => $builderNodes) { + $builderTypeTreeBuilder = new TreeBuilder($builderType); + $builderTypeTreeBuilder->getRootNode() + ->addDefaultsIfNotSet() + ; + foreach ($builderNodes as $node) { + $builderTypeTreeBuilder->getRootNode()->append($node->create()); + } - return $treeBuilder->getRootNode(); - } + $typeTreeBuilder->getRootNode()->append($builderTypeTreeBuilder->getRootNode()); + } - private function addPdfSplitNode(): NodeDefinition - { - $treeBuilder = new TreeBuilder('split'); - $this->addSplitConfigurationNode($treeBuilder->getRootNode()); + $defaultOptionsTreeBuilder->getRootNode()->append($typeTreeBuilder->getRootNode()); + } - return $treeBuilder->getRootNode(); - } - - private function addPdfFormatNode(ArrayNodeDefinition $parent): void - { - $parent - ->addDefaultsIfNotSet() - ->children() - ->enumNode('pdf_format') - ->info('Convert PDF into the given PDF/A format - default None.') - ->values(array_map(static fn (PdfFormat $case): string => $case->value, PdfFormat::cases())) - ->defaultNull() - ->end() - ->booleanNode('pdf_universal_access') - ->info('Enable PDF for Universal Access for optimal accessibility - default false.') - ->defaultNull() - ->end() - ->end() - ; - } - - private function addPdfMetadataNode(): NodeDefinition - { - $treeBuilder = new TreeBuilder('metadata'); - - return $treeBuilder->getRootNode() - ->info('The metadata to write. Not all metadata are writable. Consider taking a look at https://exiftool.org/TagNames/XMP.html#pdf for an (exhaustive?) list of available metadata.') - ->children() - ->scalarNode('Author')->end() - ->scalarNode('Copyright')->end() - ->scalarNode('CreationDate')->end() - ->scalarNode('Creator')->end() - ->scalarNode('Keywords')->end() - ->booleanNode('Marked')->end() - ->scalarNode('ModDate')->end() - ->scalarNode('PDFVersion')->end() - ->scalarNode('Producer')->end() - ->scalarNode('Subject')->end() - ->scalarNode('Title')->end() - ->enumNode('Trapped')->values(['True', 'False', 'Unknown'])->end() - ->end() - ; + return $defaultOptionsTreeBuilder->getRootNode(); } private function addNamedWebhookDefinition(): NodeDefinition @@ -715,35 +121,6 @@ private function addNamedWebhookDefinition(): NodeDefinition ->end(); } - private function addWebhookDeclarationNode(ArrayNodeDefinition $parent): void - { - $parent - ->children() - ->arrayNode('webhook') - ->info('Webhook configuration name or definition.') - ->beforeNormalization() - ->ifString() - ->then(static function (string $v): array { - return ['config_name' => $v]; - }) - ->end() - ->children() - ->scalarNode('config_name') - ->info('The name of the webhook configuration to use.') - ->end() - ->append($this->addWebhookConfigurationNode('success')) - ->append($this->addWebhookConfigurationNode('error')) - ->append($this->addExtraHttpHeadersNode()) - ->end() - ->validate() - ->ifTrue(static function ($option): bool { - return !isset($option['config_name']) && !isset($option['success']); - }) - ->thenInvalid('Invalid webhook configuration : either reference an existing webhook configuration or declare a new one with "success" and optionally "error" keys.') - ->end() - ->end(); - } - private function addWebhookConfigurationNode(string $name): NodeDefinition { $treeBuilder = new TreeBuilder($name); @@ -754,9 +131,8 @@ private function addWebhookConfigurationNode(string $name): NodeDefinition ->info('The URL to call.') ->example('https://webhook.site/#!/view/{some-token}') ->end() - ->arrayNode('route') + ->variableNode('route') ->info('Route configuration.') - ->example([['my_route', ['param1' => 'value1', 'param2' => 'value2']]]) ->beforeNormalization() ->ifArray() ->then(function (array $v): array { @@ -773,7 +149,7 @@ private function addWebhookConfigurationNode(string $name): NodeDefinition }) ->thenInvalid('The "route" parameter must be a string or an array containing a string and an array.') ->end() - ->variablePrototype()->end() + ->example("['my_route', ['param1' => 'value1', 'param2' => 'value2']]") ->end() ->enumNode('method') ->info('HTTP method to use on that endpoint.') @@ -784,44 +160,6 @@ private function addWebhookConfigurationNode(string $name): NodeDefinition ; } - private function addDownloadFromNode(): NodeDefinition - { - $treeBuilder = new TreeBuilder('download_from'); - - return $treeBuilder->getRootNode() - ->info('URLs to download files from (JSON format). - default None. https://gotenberg.dev/docs/routes#download-from') - ->defaultValue([]) - ->arrayPrototype() - ->children() - ->scalarNode('url')->end() - ->arrayNode('extraHttpHeaders') - ->useAttributeAsKey('name') - ->arrayPrototype() - ->children() - ->scalarNode('name') - ->validate() - ->ifTrue(static function ($option): bool { - return !\is_string($option); - }) - ->thenInvalid('Invalid header name %s') - ->end() - ->end() - ->scalarNode('value') - ->validate() - ->ifTrue(static function ($option): bool { - return !\is_string($option); - }) - ->thenInvalid('Invalid header value %s') - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ->end() - ; - } - private function addExtraHttpHeadersNode(): NodeDefinition { $treeBuilder = new TreeBuilder('extra_http_headers'); @@ -835,38 +173,4 @@ private function addExtraHttpHeadersNode(): NodeDefinition ->end() ; } - - private function addSplitConfigurationNode(ArrayNodeDefinition $parent): void - { - $parent - ->addDefaultsIfNotSet() - ->children() - ->enumNode('split_mode') - ->info('Either intervals or pages. - default None. https://gotenberg.dev/docs/routes#split-chromium') - ->values(array_map(static fn (SplitMode $case): string => $case->value, SplitMode::cases())) - ->defaultNull() - ->end() - ->scalarNode('split_span') - ->info('Either the intervals or the page ranges to extract, depending on the selected mode. - default None. https://gotenberg.dev/docs/routes#split-chromium') - ->defaultNull() - ->validate() - ->ifTrue(static function ($option): bool { - return preg_match('/([\d]+[-][\d]+)/', $option) !== 1 && preg_match('/(\d+)/', $option) !== 1; - }) - ->thenInvalid('Invalid value, the range value format need to look like e.g 1-20 or as a single int value e.g 2.') - ->end() - ->end() - ->booleanNode('split_unify') - ->info('Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. - default false. https://gotenberg.dev/docs/routes#split-chromium') - ->defaultNull() - ->end() - ->end() - ->validate() - ->ifTrue(static function ($option): bool { - return isset($option['split_mode']) && !isset($option['split_span']); - }) - ->thenInvalid('"splitMode" and "splitSpan" must be provided.') - ->end() - ; - } } diff --git a/src/DependencyInjection/SensiolabsGotenbergExtension.php b/src/DependencyInjection/SensiolabsGotenbergExtension.php index b01e2c58..8aa90fe2 100644 --- a/src/DependencyInjection/SensiolabsGotenbergExtension.php +++ b/src/DependencyInjection/SensiolabsGotenbergExtension.php @@ -2,27 +2,24 @@ namespace Sensiolabs\GotenbergBundle\DependencyInjection; -use Sensiolabs\GotenbergBundle\Builder\Pdf\PdfBuilderInterface; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\ScreenshotBuilderInterface; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\WebhookTrait; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; use Symfony\Component\Routing\RequestContext; /** + * @phpstan-import-type WebhookConfiguration from WebhookTrait + * * @phpstan-type SensiolabsGotenbergConfiguration array{ * assets_directory: string, - * http_client: string, + * http_client?: string, * request_context?: array{base_uri?: string}, * controller_listener: bool, - * webhook: array - * }>, + * webhook: array, * default_options: array{ * webhook?: string, * pdf: array{ @@ -41,145 +38,167 @@ * } * } * } - * @phpstan-type WebhookDefinition array{url?: string, route?: array{0: string, 1: array}, method?: 'POST'|'PUT'|'PATCH'|null} */ class SensiolabsGotenbergExtension extends Extension { + private BuilderStack $builderStack; + + /** + * @param class-string $class + */ + public function registerBuilder(string $class): void + { + $this->builderStack->push($class); + } + + public function setBuilderStack(BuilderStack $builderStack): void + { + $this->builderStack = $builderStack; + } + + /** + * @param array $config + */ + public function getConfiguration(array $config, ContainerBuilder $container): Configuration + { + return new Configuration($this->builderStack->getConfigNode()); + } + public function load(array $configs, ContainerBuilder $container): void { - $configuration = new Configuration(); + $configuration = $this->getConfiguration($configs, $container); - /** @var SensiolabsGotenbergConfiguration $config + /** + * @var SensiolabsGotenbergConfiguration $config */ $config = $this->processConfiguration($configuration, $configs); + $defaultConfiguration = $this->processDefaultConfiguration($config); $loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../config')); + + // Services + $loader->load('services.php'); + + // Builders + $loader->load('builder.php'); $loader->load('builder_pdf.php'); $loader->load('builder_screenshot.php'); - $loader->load('services.php'); - if (false === $config['controller_listener']) { + // HTTP Client + $container->setAlias('sensiolabs_gotenberg.http_client', new Alias($defaultConfiguration['http_client'] ?? 'http_client', false)); + + // Request context + $baseUri = $defaultConfiguration['request_context']['base_uri'] ?? null; + if (null !== $baseUri) { + $container + ->register('.sensiolabs_gotenberg.request_context', RequestContext::class) + ->setFactory([RequestContext::class, 'fromUri']) + ->setArguments([$baseUri]) + ; + } + + // Asset base dir formatter + $container + ->getDefinition('.sensiolabs_gotenberg.asset.base_dir_formatter') + ->replaceArgument(1, $defaultConfiguration['assets_directory']) + ; + + if (false === $defaultConfiguration['controller_listener']) { $container->removeDefinition('sensiolabs_gotenberg.http_kernel.stream_builder'); } if ($container->getParameter('kernel.debug') === true) { $loader->load('debug.php'); $container->getDefinition('sensiolabs_gotenberg.data_collector') - ->replaceArgument(3, [ - 'html' => $this->cleanUserOptions($config['default_options']['pdf']['html']), - 'url' => $this->cleanUserOptions($config['default_options']['pdf']['url']), - 'markdown' => $this->cleanUserOptions($config['default_options']['pdf']['markdown']), - 'office' => $this->cleanUserOptions($config['default_options']['pdf']['office']), - 'merge' => $this->cleanUserOptions($config['default_options']['pdf']['merge']), - 'convert' => $this->cleanUserOptions($config['default_options']['pdf']['convert']), - 'split' => $this->cleanUserOptions($config['default_options']['pdf']['split']), - ]) + ->replaceArgument(4, $defaultConfiguration['default_options']) ; } - $container->registerForAutoconfiguration(PdfBuilderInterface::class) - ->addTag('sensiolabs_gotenberg.pdf_builder') - ; - - $container->registerForAutoconfiguration(ScreenshotBuilderInterface::class) - ->addTag('sensiolabs_gotenberg.screenshot_builder') + $container->registerForAutoconfiguration(BuilderInterface::class) + ->addTag('sensiolabs_gotenberg.builder') ; - $container->setAlias('sensiolabs_gotenberg.http_client', new Alias($config['http_client'], false)); - - $baseUri = $config['request_context']['base_uri'] ?? null; - - if (null !== $baseUri) { - $requestContextDefinition = new Definition(RequestContext::class); - $requestContextDefinition->setFactory([RequestContext::class, 'fromUri']); - $requestContextDefinition->setArguments([$baseUri]); - - $container->setDefinition('.sensiolabs_gotenberg.request_context', $requestContextDefinition); + // Configurators + $configValueMapping = []; + foreach ($defaultConfiguration['default_options'] as $type => $buildersOptions) { + if ('webhook' === $type) { + continue; + } + + foreach ($buildersOptions as $builderName => $builderOptions) { + $class = $this->builderStack->getTypeReverseMapping()[$type][$builderName]; + $configValueMapping[$class] = $defaultConfiguration['default_options'][$type][$builderName]; + } } - foreach ($config['webhook'] as $name => $configuration) { - $container->getDefinition('.sensiolabs_gotenberg.webhook_configuration_registry') - ->addMethodCall('add', [$name, $configuration]); - } - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.pdf_builder.html', $config['default_options']['pdf']['html']); - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.pdf_builder.url', $config['default_options']['pdf']['url']); - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.pdf_builder.markdown', $config['default_options']['pdf']['markdown']); - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.pdf_builder.office', $config['default_options']['pdf']['office']); - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.pdf_builder.merge', $config['default_options']['pdf']['merge']); - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.pdf_builder.convert', $config['default_options']['pdf']['convert']); - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.pdf_builder.split', $config['default_options']['pdf']['split']); - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.screenshot_builder.html', $config['default_options']['screenshot']['html']); - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.screenshot_builder.url', $config['default_options']['screenshot']['url']); - - $this->processDefaultOptions($container, $config, '.sensiolabs_gotenberg.screenshot_builder.markdown', $config['default_options']['screenshot']['markdown']); - - $definition = $container->getDefinition('.sensiolabs_gotenberg.asset.base_dir_formatter'); - $definition->replaceArgument(1, $config['assets_directory']); + $container->getDefinition('sensiolabs_gotenberg.builder_configurator') + ->replaceArgument(0, $this->builderStack->getConfigMapping()) + ->replaceArgument(1, $configValueMapping) + ; } /** - * @param array $userConfigurations + * @param array $config * * @return array */ - private function cleanUserOptions(array $userConfigurations): array - { - return array_filter($userConfigurations, static function ($config, $configName): bool { - return null !== $config && 'webhook' !== $configName; - }, \ARRAY_FILTER_USE_BOTH); - } - - /** - * @param SensiolabsGotenbergConfiguration $config - * @param array $serviceConfig - */ - private function processDefaultOptions(ContainerBuilder $container, array $config, string $serviceId, array $serviceConfig): void + private function processDefaultConfiguration(array $config): array { - $definition = $container->getDefinition($serviceId); - - $definition->addMethodCall('setConfigurations', [$this->cleanUserOptions($serviceConfig)]); + foreach ($config['default_options'] as $type => $builders) { + if ('webhook' === $type) { + continue; + } + + foreach ($builders as $builderName => $builderOptions) { + $builderWebhookConfig = []; + $builderWebhookConfigName = null; + if (isset($builderOptions['webhook'])) { + if (\is_array($builderOptions['webhook'])) { + $builderWebhookConfig = $builderOptions['webhook']; + + /** @var string|null $builderWebhookConfigName */ + $builderWebhookConfigName = $builderOptions['webhook']['config_name'] ?? null; + } + + if (\is_string($builderOptions['webhook'])) { + $builderWebhookConfigName = $builderOptions['webhook']; + } + } + + $webhookConfigName = $builderWebhookConfigName ?? $config['default_options']['webhook'] ?? null; + $defaultWebhookConfig = $config['webhook'][$webhookConfigName] ?? []; + + $config['default_options'][$type][$builderName]['webhook'] = array_merge( + $this->cleanBuilderConfiguration($defaultWebhookConfig), + $this->cleanBuilderConfiguration($builderWebhookConfig), + ); + + $config['default_options'][$type][$builderName] = $this->cleanBuilderConfiguration($config['default_options'][$type][$builderName]); + } + } - $this->processWebhookOptions($container, $serviceId, $config['webhook'], $config['default_options']['webhook'] ?? null, $serviceConfig); + return $config; } /** - * @param array}> $webhookConfig - * @param array $config + * @param array $userConfigurations + * + * @return array */ - private function processWebhookOptions(ContainerBuilder $container, string $serviceId, array $webhookConfig, string|null $webhookDefaultConfigName, array $config): void + private function cleanBuilderConfiguration(array $userConfigurations): array { - $definition = $container->getDefinition($serviceId); - - $serviceWebhookConfig = $config['webhook'] ?? []; - $webhookConfigName = $serviceWebhookConfig['config_name'] ?? $webhookDefaultConfigName ?? null; - unset($serviceWebhookConfig['config_name']); - - if ([] !== $serviceWebhookConfig && ['extra_http_headers' => []] !== $serviceWebhookConfig) { - $webhookConfig = array_merge($webhookConfig[$webhookConfigName] ?? [], $serviceWebhookConfig); - - $webhookConfigName = ltrim($serviceId, '.'); - $webhookConfigName = ".{$webhookConfigName}.webhook_configuration"; - - $registryDefinition = $container->getDefinition('.sensiolabs_gotenberg.webhook_configuration_registry'); - $registryDefinition->addMethodCall('add', [ - $webhookConfigName, - $webhookConfig, - ]); - } - - if (null === $webhookConfigName) { - return; + foreach ($userConfigurations as $key => $value) { + if (\is_array($value)) { + $userConfigurations[$key] = $this->cleanBuilderConfiguration($value); + + if ([] === $userConfigurations[$key]) { + unset($userConfigurations[$key]); + } + } elseif (null === $value) { + unset($userConfigurations[$key]); + } } - $definition->addMethodCall('webhookConfiguration', [$webhookConfigName]); + return $userConfigurations; } } diff --git a/src/Enumeration/NodeType.php b/src/Enumeration/NodeType.php new file mode 100644 index 00000000..e3d8bec9 --- /dev/null +++ b/src/Enumeration/NodeType.php @@ -0,0 +1,14 @@ +container->get($builder); } /** - * @param 'html'|'url'|'markdown'|'office'|'merge'|'convert'|'split' $key + * @param 'html'|'url'|'markdown'|'office'|'merge'|'convert'|'split'|'flatten' $key * * @return ( * $key is 'html' ? HtmlPdfBuilder : @@ -35,46 +36,52 @@ public function get(string $builder): PdfBuilderInterface * $key is 'merge' ? MergePdfBuilder : * $key is 'convert' ? ConvertPdfBuilder : * $key is 'split' ? SplitPdfBuilder : - * PdfBuilderInterface + * $key is 'flatten' ? FlattenPdfBuilder : + * BuilderInterface * ) */ - private function getInternal(string $key): PdfBuilderInterface + private function getInternal(string $key): BuilderInterface { return $this->get(".sensiolabs_gotenberg.pdf_builder.{$key}"); } - public function html(): PdfBuilderInterface + public function html(): BuilderInterface { return $this->getInternal('html'); } - public function url(): PdfBuilderInterface + public function url(): BuilderInterface { return $this->getInternal('url'); } - public function office(): PdfBuilderInterface + public function office(): BuilderInterface { return $this->getInternal('office'); } - public function markdown(): PdfBuilderInterface + public function markdown(): BuilderInterface { return $this->getInternal('markdown'); } - public function merge(): PdfBuilderInterface + public function merge(): BuilderInterface { return $this->getInternal('merge'); } - public function convert(): PdfBuilderInterface + public function convert(): BuilderInterface { return $this->getInternal('convert'); } - public function split(): PdfBuilderInterface + public function split(): BuilderInterface { return $this->getInternal('split'); } + + public function flatten(): BuilderInterface + { + return $this->getInternal('flatten'); + } } diff --git a/src/GotenbergPdfInterface.php b/src/GotenbergPdfInterface.php index 8a952884..dfb7e518 100644 --- a/src/GotenbergPdfInterface.php +++ b/src/GotenbergPdfInterface.php @@ -2,58 +2,64 @@ namespace Sensiolabs\GotenbergBundle; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\FlattenPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\PdfBuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\SplitPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder; interface GotenbergPdfInterface { /** - * @template T of PdfBuilderInterface + * @template T of BuilderInterface * * @param string|class-string $builder * - * @return ($builder is class-string ? T : PdfBuilderInterface) + * @return ($builder is class-string ? T : BuilderInterface) */ - public function get(string $builder): PdfBuilderInterface; + public function get(string $builder): BuilderInterface; /** * @return HtmlPdfBuilder */ - public function html(): PdfBuilderInterface; + public function html(): BuilderInterface; /** * @return UrlPdfBuilder */ - public function url(): PdfBuilderInterface; + public function url(): BuilderInterface; /** - * @return LibreOfficePdfBuilder + * @return MarkdownPdfBuilder */ - public function office(): PdfBuilderInterface; + public function markdown(): BuilderInterface; /** - * @return MarkdownPdfBuilder + * @return LibreOfficePdfBuilder */ - public function markdown(): PdfBuilderInterface; + public function office(): BuilderInterface; /** * @return MergePdfBuilder */ - public function merge(): PdfBuilderInterface; + public function merge(): BuilderInterface; /** * @return ConvertPdfBuilder */ - public function convert(): PdfBuilderInterface; + public function convert(): BuilderInterface; /** * @return SplitPdfBuilder */ - public function split(): PdfBuilderInterface; + public function split(): BuilderInterface; + + /** + * @return FlattenPdfBuilder + */ + public function flatten(): BuilderInterface; } diff --git a/src/GotenbergScreenshot.php b/src/GotenbergScreenshot.php index ec911291..eb872e9c 100644 --- a/src/GotenbergScreenshot.php +++ b/src/GotenbergScreenshot.php @@ -3,9 +3,9 @@ namespace Sensiolabs\GotenbergBundle; use Psr\Container\ContainerInterface; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder; use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\ScreenshotBuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder; final class GotenbergScreenshot implements GotenbergScreenshotInterface @@ -15,7 +15,7 @@ public function __construct( ) { } - public function get(string $builder): ScreenshotBuilderInterface + public function get(string $builder): BuilderInterface { return $this->container->get($builder); } @@ -27,25 +27,25 @@ public function get(string $builder): ScreenshotBuilderInterface * $key is 'html' ? HtmlScreenshotBuilder : * $key is 'url' ? UrlScreenshotBuilder : * $key is 'markdown' ? MarkdownScreenshotBuilder : - * ScreenshotBuilderInterface + * BuilderInterface * ) */ - private function getInternal(string $key): ScreenshotBuilderInterface + private function getInternal(string $key): BuilderInterface { return $this->get(".sensiolabs_gotenberg.screenshot_builder.{$key}"); } - public function html(): ScreenshotBuilderInterface + public function html(): BuilderInterface { return $this->getInternal('html'); } - public function url(): ScreenshotBuilderInterface + public function url(): BuilderInterface { return $this->getInternal('url'); } - public function markdown(): ScreenshotBuilderInterface + public function markdown(): BuilderInterface { return $this->getInternal('markdown'); } diff --git a/src/GotenbergScreenshotInterface.php b/src/GotenbergScreenshotInterface.php index 69680dfa..4c7dcbc1 100644 --- a/src/GotenbergScreenshotInterface.php +++ b/src/GotenbergScreenshotInterface.php @@ -2,34 +2,34 @@ namespace Sensiolabs\GotenbergBundle; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder; use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\ScreenshotBuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder; interface GotenbergScreenshotInterface { /** - * @template T of ScreenshotBuilderInterface + * @template T of BuilderInterface * * @param string|class-string $builder * - * @return ($builder is class-string ? T : ScreenshotBuilderInterface) + * @return ($builder is class-string ? T : BuilderInterface) */ - public function get(string $builder): ScreenshotBuilderInterface; + public function get(string $builder): BuilderInterface; /** * @return HtmlScreenshotBuilder */ - public function html(): ScreenshotBuilderInterface; + public function html(): BuilderInterface; /** * @return UrlScreenshotBuilder */ - public function url(): ScreenshotBuilderInterface; + public function url(): BuilderInterface; /** * @return MarkdownScreenshotBuilder */ - public function markdown(): ScreenshotBuilderInterface; + public function markdown(): BuilderInterface; } diff --git a/src/NodeBuilder/ArrayNodeBuilder.php b/src/NodeBuilder/ArrayNodeBuilder.php new file mode 100644 index 00000000..19e57c9e --- /dev/null +++ b/src/NodeBuilder/ArrayNodeBuilder.php @@ -0,0 +1,57 @@ +name); + + $node->normalizeKeys($this->normalizeKeys); + + if (\is_string($this->useAttributeAsKey)) { + $node->useAttributeAsKey($this->useAttributeAsKey); + } + + if (\is_string($this->prototype)) { + $prototype = match ($this->prototype) { + 'integer' => $node->integerPrototype(), + 'array' => $node->arrayPrototype(), + 'variable' => $node->variablePrototype(), + }; + + if (\count($this->children) > 0) { + foreach ($this->children as $child) { + $prototype->append($child->create()); + } + } + } elseif (\count($this->children) > 0) { + foreach ($this->children as $child) { + $node->append($child->create()); + } + + $node->addDefaultsIfNotSet(); + } + + return $node; + } +} diff --git a/src/NodeBuilder/BooleanNodeBuilder.php b/src/NodeBuilder/BooleanNodeBuilder.php new file mode 100644 index 00000000..5ec6ef67 --- /dev/null +++ b/src/NodeBuilder/BooleanNodeBuilder.php @@ -0,0 +1,31 @@ +name); + + if ($this->required) { + $node->isRequired(); + } + + $node->defaultValue($this->defaultValue); + + return $node; + } +} diff --git a/src/NodeBuilder/EnumNodeBuilder.php b/src/NodeBuilder/EnumNodeBuilder.php new file mode 100644 index 00000000..728b4caa --- /dev/null +++ b/src/NodeBuilder/EnumNodeBuilder.php @@ -0,0 +1,75 @@ + + */ + public array $values = [], + + string|callable|null $callback = null, + ) { + parent::__construct($name); + $this->callback = $callback; + } + + public function create(): EnumNodeDefinition + { + $node = new EnumNodeDefinition($this->name); + + if (\count($this->values) === 0 && null === $this->callback) { + throw new InvalidBuilderConfiguration(\sprintf('You must choose between "values" or "callback" to provide any choice for "%s".', $this->name)); + } + + if (\count($this->values) > 0 && null !== $this->callback) { + throw new InvalidBuilderConfiguration(\sprintf('You must choose between "values" or "callback" to provide any choice for "%s".', $this->name)); + } + + $values = []; + + if (\count($this->values) > 0) { + $values = $this->values; + } elseif (null !== $this->callback) { + if (\is_string($this->callback)) { + if (is_a($this->callback, \BackedEnum::class, true) === false) { + throw new InvalidBuilderConfiguration('The class from the "callback" option is not a valid class "\BackedEnum"'); + } + + $this->callback = [$this->callback, 'cases']; + } + + $values = array_map(static function (mixed $value): int|string|float|bool|null { + if ($value instanceof \BackedEnum) { + return $value->value; + } + + return $value; + }, ($this->callback)()); + } + + $node->values($values); + + if (null !== $this->defaultValue) { + if (!\in_array($this->defaultValue, $values, true)) { + throw new InvalidBuilderConfiguration(\sprintf('The default value "%s" is not part of the configured values "%s".', $this->defaultValue, implode(', ', $values))); + } + } + + $node->defaultValue($this->defaultValue); + + return $node; + } +} diff --git a/src/NodeBuilder/FloatNodeBuilder.php b/src/NodeBuilder/FloatNodeBuilder.php new file mode 100644 index 00000000..abce33f1 --- /dev/null +++ b/src/NodeBuilder/FloatNodeBuilder.php @@ -0,0 +1,24 @@ +name); + $node->defaultValue($this->defaultValue); + + return $node; + } +} diff --git a/src/NodeBuilder/IntegerNodeBuilder.php b/src/NodeBuilder/IntegerNodeBuilder.php new file mode 100644 index 00000000..9cbbfcda --- /dev/null +++ b/src/NodeBuilder/IntegerNodeBuilder.php @@ -0,0 +1,47 @@ +name); + + if (null !== $this->min) { + $node->min($this->min); + } + + if (null !== $this->max) { + $node->max($this->max); + } + + if (null !== $this->defaultValue) { + if (null !== $this->min && $this->defaultValue < $this->min) { + throw new \InvalidArgumentException(\sprintf('The default value "%s" is less than the minimum configured value "%s".', $this->defaultValue, $this->min)); + } + + if (null !== $this->max && $this->defaultValue > $this->max) { + throw new \InvalidArgumentException(\sprintf('The default value "%s" is greater than the maximum configured value "%s".', $this->defaultValue, $this->max)); + } + } + + $node->defaultValue($this->defaultValue); + + return $node; + } +} diff --git a/src/NodeBuilder/MetadataNodeBuilder.php b/src/NodeBuilder/MetadataNodeBuilder.php new file mode 100644 index 00000000..d0d2f002 --- /dev/null +++ b/src/NodeBuilder/MetadataNodeBuilder.php @@ -0,0 +1,22 @@ +name, children: $this->children))->create(); + } +} diff --git a/src/NodeBuilder/NativeEnumNodeBuilder.php b/src/NodeBuilder/NativeEnumNodeBuilder.php new file mode 100644 index 00000000..6cb64e1a --- /dev/null +++ b/src/NodeBuilder/NativeEnumNodeBuilder.php @@ -0,0 +1,33 @@ + $enumClass + */ + public function __construct( + protected string $name, + + public string $enumClass, + + public \BackedEnum|null $defaultValue = null, + ) { + parent::__construct($name); + } + + public function create(): EnumNodeDefinition + { + $defaultValue = $this->defaultValue?->value; + if (null !== $defaultValue) { + $defaultValue = (string) $defaultValue; + } + + return (new EnumNodeBuilder($this->name, $defaultValue, callback: ($this->enumClass)::cases(...))) + ->create() + ; + } +} diff --git a/src/NodeBuilder/NodeBuilder.php b/src/NodeBuilder/NodeBuilder.php new file mode 100644 index 00000000..702108e7 --- /dev/null +++ b/src/NodeBuilder/NodeBuilder.php @@ -0,0 +1,16 @@ +name; + } +} diff --git a/src/NodeBuilder/NodeBuilderInterface.php b/src/NodeBuilder/NodeBuilderInterface.php new file mode 100644 index 00000000..f29aef6a --- /dev/null +++ b/src/NodeBuilder/NodeBuilderInterface.php @@ -0,0 +1,12 @@ +name); + + if ($this->required) { + $node->isRequired(); + } + + if ($this->cannotBeEmpty) { + $node->cannotBeEmpty(); + } + + if (\is_string($this->restrictTo)) { + match ($this->restrictTo) { + 'boolean' => $node->validate()->ifTrue(static fn ($option): bool => !\is_bool($option))->thenInvalid('Invalid value %s, available type is "boolean".'), + 'string' => $node->validate()->ifTrue(static fn ($option): bool => !\is_string($option))->thenInvalid('Invalid value %s, available type is "string".'), + 'integer' => $node->validate()->ifTrue(static fn ($option): bool => !\is_int($option))->thenInvalid('Invalid value %s, available type is "integer".'), + 'float' => $node->validate()->ifTrue(static fn ($option): bool => !\is_float($option))->thenInvalid('Invalid value %s, available type is "float".'), + }; + } + + $node->defaultValue($this->defaultValue); + + return $node; + } +} diff --git a/src/NodeBuilder/UnitNodeBuilder.php b/src/NodeBuilder/UnitNodeBuilder.php new file mode 100644 index 00000000..9af187a0 --- /dev/null +++ b/src/NodeBuilder/UnitNodeBuilder.php @@ -0,0 +1,13 @@ +name))->create(); + } +} diff --git a/src/NodeBuilder/VariableNodeBuilder.php b/src/NodeBuilder/VariableNodeBuilder.php new file mode 100644 index 00000000..56f465f0 --- /dev/null +++ b/src/NodeBuilder/VariableNodeBuilder.php @@ -0,0 +1,19 @@ +name); + } +} diff --git a/src/NodeBuilder/WebhookNodeBuilder.php b/src/NodeBuilder/WebhookNodeBuilder.php new file mode 100644 index 00000000..ae3ee3ab --- /dev/null +++ b/src/NodeBuilder/WebhookNodeBuilder.php @@ -0,0 +1,31 @@ +name, children: $this->children))->create(); + + $node->beforeNormalization() + ->ifString() + ->then(static function (string $v): array { + return ['config_name' => $v]; + }) + ; + + return $node; + } +} diff --git a/src/SensiolabsGotenbergBundle.php b/src/SensiolabsGotenbergBundle.php index 937fdca6..754d73dc 100644 --- a/src/SensiolabsGotenbergBundle.php +++ b/src/SensiolabsGotenbergBundle.php @@ -2,7 +2,20 @@ namespace Sensiolabs\GotenbergBundle; +use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\FlattenPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\SplitPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder; +use Sensiolabs\GotenbergBundle\DependencyInjection\BuilderStack; use Sensiolabs\GotenbergBundle\DependencyInjection\CompilerPass\GotenbergPass; +use Sensiolabs\GotenbergBundle\DependencyInjection\SensiolabsGotenbergExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; @@ -15,6 +28,25 @@ public function getPath(): string public function build(ContainerBuilder $container): void { - $container->addCompilerPass(new GotenbergPass()); + $builderStack = new BuilderStack(); + + /** @var SensiolabsGotenbergExtension $extension */ + $extension = $container->getExtension('sensiolabs_gotenberg'); + $extension->setBuilderStack($builderStack); + + $extension->registerBuilder(ConvertPdfBuilder::class); + $extension->registerBuilder(FlattenPdfBuilder::class); + $extension->registerBuilder(HtmlPdfBuilder::class); + $extension->registerBuilder(LibreOfficePdfBuilder::class); + $extension->registerBuilder(MarkdownPdfBuilder::class); + $extension->registerBuilder(MergePdfBuilder::class); + $extension->registerBuilder(SplitPdfBuilder::class); + $extension->registerBuilder(UrlPdfBuilder::class); + + $extension->registerBuilder(HtmlScreenshotBuilder::class); + $extension->registerBuilder(MarkdownScreenshotBuilder::class); + $extension->registerBuilder(UrlScreenshotBuilder::class); + + $container->addCompilerPass(new GotenbergPass($builderStack)); } } diff --git a/src/Twig/GotenbergRuntime.php b/src/Twig/GotenbergRuntime.php index 2eb43646..cd9584f0 100644 --- a/src/Twig/GotenbergRuntime.php +++ b/src/Twig/GotenbergRuntime.php @@ -2,17 +2,16 @@ namespace Sensiolabs\GotenbergBundle\Twig; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractChromiumPdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractChromiumScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; /** * @internal */ final class GotenbergRuntime { - private AbstractChromiumPdfBuilder|AbstractChromiumScreenshotBuilder|null $builder = null; + private BuilderAssetInterface|null $builder = null; - public function setBuilder(AbstractChromiumPdfBuilder|AbstractChromiumScreenshotBuilder|null $builder): void + public function setBuilder(BuilderAssetInterface|null $builder): void { $this->builder = $builder; } @@ -21,8 +20,7 @@ public function setBuilder(AbstractChromiumPdfBuilder|AbstractChromiumScreenshot * This function is used to get the URL of an asset during the rendering * of a PDF or a screenshot with the Gotenberg client. * - * It only works if the builder is an instance of AbstractChromiumPdfBuilder - * or AbstractChromiumScreenshotBuilder. + * It only works if the builder is an instance of BuilderAssetInterface */ public function getAssetUrl(string $path): string { @@ -38,11 +36,7 @@ public function getFont(string $path, string $name): string $name = htmlspecialchars($name); $basename = htmlspecialchars(basename($path)); - return '@font-face { - font-family: "'.$name.'"; - src: url("'.$basename.'"); - }' - ; + return '@font-face { font-family: "'.$name.'"; src: url("'.$basename.'"); }'; } private function addAsset(string $path, string $function): void diff --git a/src/Webhook/WebhookConfigurationRegistry.php b/src/Webhook/WebhookConfigurationRegistry.php deleted file mode 100644 index e243940b..00000000 --- a/src/Webhook/WebhookConfigurationRegistry.php +++ /dev/null @@ -1,99 +0,0 @@ - - * }> - */ - private array $configurations = []; - - public function __construct( - private readonly UrlGeneratorInterface $urlGenerator, - private readonly RequestContext|null $requestContext, - ) { - } - - /** - * @param array{success: WebhookDefinition, error?: WebhookDefinition, extra_http_headers?: array} $configuration - */ - public function add(string $name, array $configuration): void - { - $requestContext = $this->urlGenerator->getContext(); - if (null !== $this->requestContext) { - $this->urlGenerator->setContext($this->requestContext); - } - - try { - $success = [ - 'url' => $this->processWebhookConfiguration($configuration['success']), - 'method' => $configuration['success']['method'] ?? null, - ]; - $error = $success; - - if (isset($configuration['error'])) { - $error = [ - 'url' => $this->processWebhookConfiguration($configuration['error']), - 'method' => $configuration['error']['method'] ?? null, - ]; - } - - $namedConfiguration = ['success' => $success, 'error' => $error]; - - if (\array_key_exists('extra_http_headers', $configuration) && [] !== $configuration['extra_http_headers']) { - $namedConfiguration['extra_http_headers'] = $configuration['extra_http_headers']; - } - - $this->configurations[$name] = $namedConfiguration; - } finally { - $this->urlGenerator->setContext($requestContext); - } - } - - public function get(string $name): array - { - if (!\array_key_exists($name, $this->configurations)) { - throw new WebhookConfigurationException("Webhook configuration \"{$name}\" not found."); - } - - return $this->configurations[$name]; - } - - /** - * @param WebhookDefinition $webhookDefinition - * - * @throws WebhookConfigurationException - */ - private function processWebhookConfiguration(array $webhookDefinition): string - { - if (isset($webhookDefinition['url'])) { - return $webhookDefinition['url']; - } - - if (isset($webhookDefinition['route'])) { - return $this->urlGenerator->generate($webhookDefinition['route'][0], $webhookDefinition['route'][1], UrlGeneratorInterface::ABSOLUTE_URL); - } - - throw new WebhookConfigurationException('Invalid webhook configuration'); - } -} diff --git a/src/Webhook/WebhookConfigurationRegistryInterface.php b/src/Webhook/WebhookConfigurationRegistryInterface.php deleted file mode 100644 index 48f2dd22..00000000 --- a/src/Webhook/WebhookConfigurationRegistryInterface.php +++ /dev/null @@ -1,33 +0,0 @@ -}, method?: 'POST'|'PUT'|'PATCH'|null} - */ -interface WebhookConfigurationRegistryInterface -{ - /** - * @param array{success: WebhookDefinition, error?: WebhookDefinition} $configuration - */ - public function add(string $name, array $configuration): void; - - /** - * @return array{ - * success: array{ - * url: string, - * method: 'POST'|'PUT'|'PATCH'|null, - * }, - * error: array{ - * url: string, - * method: 'POST'|'PUT'|'PATCH'|null, - * }, - * extra_http_headers?: array - * } - * - * @throws WebhookConfigurationException if configuration not found - */ - public function get(string $name): array; -} diff --git a/templates/Collector/sensiolabs_gotenberg.html.twig b/templates/Collector/sensiolabs_gotenberg.html.twig index 2156a138..c71ddfac 100644 --- a/templates/Collector/sensiolabs_gotenberg.html.twig +++ b/templates/Collector/sensiolabs_gotenberg.html.twig @@ -66,15 +66,6 @@ {% endif %} Total time -
- {% if collector.requestTotalMemory is null %} - n/a - {% else %} - {{ '%.1f'|format(collector.requestTotalMemory / 1024 / 1024) }} MiB - {% endif %} - Total memory -
{% set total_size = collector.requestTotalSize %} {% set total_size_value = total_size[0] %} @@ -87,10 +78,11 @@

Files

+ {% for index, file in collector.files %} - + @@ -99,7 +91,6 @@ - {% for index, file in collector.files %} - -
Type File Time Memory
@@ -116,11 +107,12 @@ {{ file.fileName }} @@ -152,8 +144,25 @@
+ +
+ + + + + + + + + {% for configuration, value in file.configuration %} + + + + + {% endfor %} + +
ConfigurationValue
{{ configuration }}{{ profiler_dump(value, maxDepth=5) }}
+
@@ -172,18 +181,18 @@
-
+
- - + + - {% for configuration, value in file.configuration %} + {% for payload, value in file.payload %} - + {% endfor %} @@ -192,7 +201,7 @@ - {% endfor %}
ConfigurationValueRequest componentNormalized data sent
{{ configuration }}{{ payload }} {{ profiler_dump(value, maxDepth=5) }}
+ {% endfor %} {% endblock %} diff --git a/tests/Builder/AbstractBuilderTestCase.php b/tests/Builder/AbstractBuilderTestCase.php deleted file mode 100644 index 6f64b024..00000000 --- a/tests/Builder/AbstractBuilderTestCase.php +++ /dev/null @@ -1,78 +0,0 @@ - true, - ]); - self::$twig->addExtension(new GotenbergExtension()); - self::$twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { - public function load(string $class): object|null - { - return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; - } - }); - self::$assetBaseDirFormatter = new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR); - } - - protected function setUp(): void - { - $this->gotenbergClient = $this->createMock(GotenbergClientInterface::class); - $this->webhookConfigurationRegistry = $this->createMock(WebhookConfigurationRegistryInterface::class); - } - - /** - * @param array $data - */ - protected static function assertFile(array $data, string $filename, string $contentType = 'text/html', string|null $expectedContent = null): void - { - self::assertArrayHasKey('files', $data); - - $file = $data['files']; - - self::assertInstanceOf(DataPart::class, $file); - self::assertSame($filename, $file->getFilename()); - self::assertSame($contentType, $file->getContentType()); - - if (null !== $expectedContent) { - self::assertSame($expectedContent, $file->getBody()); - } - - iterator_to_array($file->bodyToIterable()); // Check if path is correct - } -} diff --git a/tests/Builder/AsyncBuilderTraitTest.php b/tests/Builder/AsyncBuilderTraitTest.php deleted file mode 100644 index e01f42f9..00000000 --- a/tests/Builder/AsyncBuilderTraitTest.php +++ /dev/null @@ -1,224 +0,0 @@ -getBuilder(new MockHttpClient([])); - - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('->webhookUrl() was never called.'); - - $builder->generateAsync(); - } - - public function testItGenerateWithJustTheSuccessWebhookUrlSet(): void - { - $callback = function ($method, $url, $options): MockResponse { - $this->assertSame('POST', $method); - $this->assertSame('https://example.com/fake/endpoint', $url); - $this->assertContains('Gotenberg-Webhook-Url: https://webhook.local', $options['headers']); - $this->assertContains('Gotenberg-Webhook-Error-Url: https://webhook.local', $options['headers']); - $this->assertArrayNotHasKey('gotenberg-webhook-method', $options['normalized_headers']); - $this->assertArrayNotHasKey('gotenberg-webhook-error-method', $options['normalized_headers']); - - return new MockResponse('', [ - 'response_headers' => [ - 'Content-Type' => 'text/plain; charset=UTF-8', - 'Gotenberg-Trace' => '{trace}', - ], - ]); - }; - - $builder = $this->getBuilder(new MockHttpClient($callback)); - $builder->webhookUrl('https://webhook.local'); - - $builder->generateAsync(); - } - - public function testItAlsoAcceptsADifferentErrorWebhookUrl(): void - { - $callback = function ($method, $url, $options): MockResponse { - $this->assertContains('Gotenberg-Webhook-Url: https://webhook.local', $options['headers']); - $this->assertContains('Gotenberg-Webhook-Error-Url: https://webhook.local/error', $options['headers']); - - return new MockResponse('', [ - 'response_headers' => [ - 'Content-Type' => 'text/plain; charset=UTF-8', - 'Gotenberg-Trace' => '{trace}', - ], - ]); - }; - - $builder = $this->getBuilder(new MockHttpClient($callback)); - $builder->webhookUrl('https://webhook.local'); - $builder->errorWebhookUrl('https://webhook.local/error'); - - $builder->generateAsync(); - } - - public function testWebhookUrlsCanChangeTheirRespectiveHttpMethods(): void - { - $callback = function ($method, $url, $options): MockResponse { - $this->assertContains('Gotenberg-Webhook-Url: https://webhook.local', $options['headers']); - $this->assertContains('Gotenberg-Webhook-Method: PUT', $options['headers']); - $this->assertContains('Gotenberg-Webhook-Error-Url: https://webhook.local/error', $options['headers']); - $this->assertContains('Gotenberg-Webhook-Error-Method: PATCH', $options['headers']); - - return new MockResponse('', [ - 'response_headers' => [ - 'Content-Type' => 'text/plain; charset=UTF-8', - 'Gotenberg-Trace' => '{trace}', - ], - ]); - }; - - $builder = $this->getBuilder(new MockHttpClient($callback)); - $builder->webhookUrl('https://webhook.local', 'PUT'); - $builder->errorWebhookUrl('https://webhook.local/error', 'PATCH'); - - $builder->generateAsync(); - } - - public function testWebhookUrlsCanSendCustomHttpHeaderToEndpoint(): void - { - $callback = function ($method, $url, $options): MockResponse { - $this->assertContains('Gotenberg-Webhook-Extra-Http-Headers: {"plop":"plop"}', $options['headers']); - - return new MockResponse('', [ - 'response_headers' => [ - 'Content-Type' => 'text/plain; charset=UTF-8', - 'Gotenberg-Trace' => '{trace}', - ], - ]); - }; - - $builder = $this->getBuilder(new MockHttpClient($callback)); - $builder->webhookUrl('https://webhook.local'); - $builder->webhookExtraHeaders(['plop' => 'plop']); - - $builder->generateAsync(); - } - - public function testWebhookUrlsCanBeSetUsingTheRegistry(): void - { - $registry = new class($this) implements WebhookConfigurationRegistryInterface { - public function __construct(private AsyncBuilderTraitTest $assert) - { - } - - public function add(string $name, array $configuration): void - { - // TODO: Implement add() method. - } - - public function get(string $name): array - { - $this->assert->assertSame('fake', $name); - - return [ - 'success' => [ - 'url' => 'https://webhook.local', - 'method' => 'PUT', - ], - 'error' => [ - 'url' => 'https://webhook.local/error', - 'method' => 'PATCH', - ], - 'extra_http_headers' => [ - 'plop' => 'plop', - ], - ]; - } - }; - - $callback = function ($method, $url, $options): MockResponse { - $this->assertContains('Gotenberg-Webhook-Url: https://webhook.local', $options['headers']); - $this->assertContains('Gotenberg-Webhook-Method: PUT', $options['headers']); - $this->assertContains('Gotenberg-Webhook-Error-Url: https://webhook.local/error', $options['headers']); - $this->assertContains('Gotenberg-Webhook-Error-Method: PATCH', $options['headers']); - - return new MockResponse('', [ - 'response_headers' => [ - 'Content-Type' => 'text/plain; charset=UTF-8', - 'Gotenberg-Trace' => '{trace}', - ], - ]); - }; - - $builder = $this->getBuilder(new MockHttpClient($callback), $registry); - $builder->webhookConfiguration('fake'); - - $builder->generateAsync(); - } - - private function getBuilder(MockHttpClient $httpClient, WebhookConfigurationRegistryInterface|null $registry = null): AsyncBuilderInterface - { - $registry ??= new class implements WebhookConfigurationRegistryInterface { - public function add(string $name, array $configuration): void - { - // TODO: Implement add() method. - } - - public function get(string $name): array - { - return [ - 'success' => [ - 'url' => 'https://webhook.local', - 'method' => 'POST', - ], - 'error' => [ - 'url' => 'https://webhook.local/error', - 'method' => 'POST', - ], - ]; - } - }; - - return new class($httpClient, $registry) implements AsyncBuilderInterface { - use AsyncBuilderTrait; - - public function __construct(HttpClientInterface $httpClient, WebhookConfigurationRegistryInterface $registry) - { - $this->client = new GotenbergClient($httpClient); - $this->webhookConfigurationRegistry = $registry; - $this->asset = new AssetBaseDirFormatter('', ''); - } - - protected function getEndpoint(): string - { - return '/fake/endpoint'; - } - - /** - * @param array $configurations - */ - public function setConfigurations(array $configurations): static - { - return $this; - } - }; - } -} diff --git a/tests/Builder/Behaviors/BehaviorTrait.php b/tests/Builder/Behaviors/BehaviorTrait.php new file mode 100644 index 00000000..2e684b18 --- /dev/null +++ b/tests/Builder/Behaviors/BehaviorTrait.php @@ -0,0 +1,41 @@ +getBuilder(); + + return $this->initializeBuilder($builder, $this->dependencies); + } +} diff --git a/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php new file mode 100644 index 00000000..a0651bab --- /dev/null +++ b/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php @@ -0,0 +1,70 @@ + */ + use BehaviorTrait; + + abstract protected function assertContentFile(string $filename, string $contentType = 'text/html', string|null $expectedContent = null): void; + abstract protected function assertGotenbergFormDataFile(string $name, string $contentType, string $path): void; + + /** + * @dataProvider provideTestToAddAssets + */ + public function testToAddAssets(string|\Stringable $asset, string $expectedFilename, string $expectedContentType, string $expectedPath): void + { + $this->getDefaultBuilder() + ->assets($asset) + ->generate() + ; + + $this->assertGotenbergFormDataFile($expectedFilename, $expectedContentType, $expectedPath); + + $this->assertContentFile($expectedFilename, $expectedContentType); + } + + public static function provideTestToAddAssets(): \Generator + { + yield 'string' => ['assets/logo.png', 'logo.png', 'image/png', self::FIXTURE_DIR.'/assets/logo.png']; + yield 'SplFileInfo' => [new \SplFileInfo('assets/logo.png'), 'logo.png', 'image/png', 'assets/logo.png']; + + $stringable = new class implements \Stringable { + public function __toString(): string + { + return 'assets/logo.png'; + } + }; + yield 'Stringable' => [$stringable, 'logo.png', 'image/png', 'assets/logo.png']; + } + + public function testToAddAssetsToExistingAssets(): void + { + $this->getDefaultBuilder() + ->assets('assets/logo.png') + ->addAsset('assets/other_logo.png') + ->generate() + ; + + $this->assertContentFile('logo.png', 'image/png'); + $this->assertContentFile('other_logo.png', 'image/png'); + } + + public function testToAddSameAssetButLoadOnce(): void + { + $this->getDefaultBuilder() + ->assets('assets/logo.png') + ->addAsset('assets/logo.png') + ->generate() + ; + + $this->assertContentFile('logo.png', 'image/png'); + } +} diff --git a/tests/Builder/Behaviors/Chromium/CookieTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/CookieTestCaseTrait.php new file mode 100644 index 00000000..5f6851f9 --- /dev/null +++ b/tests/Builder/Behaviors/Chromium/CookieTestCaseTrait.php @@ -0,0 +1,178 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testSetCookiesWithMultipleArrays(): void + { + $this->getDefaultBuilder() + ->cookies([ + [ + 'name' => 'my_cookie', + 'value' => 'symfony', + 'domain' => 'symfony.com', + 'secure' => true, + 'httpOnly' => true, + 'sameSite' => 'Lax', + ], + [ + 'name' => 'cook', + 'value' => 'sensiolabs', + 'domain' => 'sensiolabs.com', + 'secure' => true, + 'httpOnly' => true, + 'sameSite' => 'Lax', + ], + ]) + ->generate() + ; + + $this->assertGotenbergFormData('cookies', '[{"name":"my_cookie","value":"symfony","domain":"symfony.com","secure":true,"httpOnly":true,"sameSite":"Lax"},{"name":"cook","value":"sensiolabs","domain":"sensiolabs.com","secure":true,"httpOnly":true,"sameSite":"Lax"}]'); + } + + public function testSetAddCookiesWithSimpleArrayToExistingCookies(): void + { + $this->getDefaultBuilder() + ->cookies([[ + 'name' => 'my_cookie', + 'value' => 'symfony', + 'domain' => 'symfony.com', + 'secure' => true, + 'httpOnly' => true, + 'sameSite' => 'Lax', + ]]) + ->addCookies([[ + 'name' => 'cook', + 'value' => 'sensiolabs', + 'domain' => 'sensiolabs.com', + 'secure' => true, + 'httpOnly' => true, + 'sameSite' => 'Lax', + ]]) + ->generate() + ; + + $this->assertGotenbergFormData('cookies', '[{"name":"my_cookie","value":"symfony","domain":"symfony.com","secure":true,"httpOnly":true,"sameSite":"Lax"},{"name":"cook","value":"sensiolabs","domain":"sensiolabs.com","secure":true,"httpOnly":true,"sameSite":"Lax"}]'); + } + + public function testSetCookieWithCookieObject(): void + { + $this->getDefaultBuilder() + ->setCookie('my_cookie', new Cookie('my_cookie', 'value', domain: 'symfony.com')) + ->generate() + ; + + $this->assertGotenbergFormData('cookies', '[{"name":"my_cookie","value":"value","domain":"symfony.com","path":"\/","secure":false,"httpOnly":true,"sameSite":"lax"}]'); + } + + public function testToUnsetExistingCookie(): void + { + $builder = $this->getDefaultBuilder() + ->setCookie('my_cookie', new Cookie('my_cookie', 'value', domain: 'symfony.com')) + ; + + self::assertArrayHasKey('cookies', $builder->getBodyBag()->all()); + + $builder->cookies([]); + self::assertArrayNotHasKey('cookies', $builder->getBodyBag()->all()); + } + + public function testSetCookieWithSimpleArray(): void + { + $this->getDefaultBuilder() + ->setCookie('my_cookie', [ + 'name' => 'my_cookie', + 'value' => 'symfony', + 'domain' => 'symfony.com', + 'secure' => true, + 'httpOnly' => true, + 'sameSite' => 'Lax', + ]) + ->generate() + ; + + $this->assertGotenbergFormData('cookies', '[{"name":"my_cookie","value":"symfony","domain":"symfony.com","secure":true,"httpOnly":true,"sameSite":"Lax"}]'); + } + + public function testToAddMultipleTimeTheSameCookie(): void + { + $cookie = new Cookie('my_cookie', 'value', domain: 'symfony.com'); + $builder = $this->getDefaultBuilder() + ->setCookie('my_cookie', $cookie) + ; + + self::assertArrayHasKey('cookies', $builder->getBodyBag()->all()); + + $builder->addCookies([$cookie]); + self::assertArrayHasKey('cookies', $builder->getBodyBag()->all()); + self::assertCount(1, $builder->getBodyBag()->all()['cookies']); + } + + public function testToForwardCookiesWithNoCurrentRequest(): void + { + $this->dependencies->set('request_stack', new RequestStack()); + + $builder = $this->getDefaultBuilder() + ->forwardCookie('my_cookie') + ; + + self::assertArrayNotHasKey('cookies', $builder->getBodyBag()->all()); + } + + public function testToForwardCookiesWithCurrentRequest(): void + { + $request = new Request(); + $request->setMethod('GET'); + $request->cookies->set('my_cookie', new Cookie('my_cookie', 'value', domain: 'symfony.com')); + + $this->dependencies->set('request_stack', new RequestStack([$request])); + $this->dependencies->set('logger', $this->getMockBuilder(LoggerInterface::class)); + + $builder = $this->getDefaultBuilder() + ->forwardCookie('my_cookie') + ; + + self::assertArrayHasKey('cookies', $builder->getBodyBag()->all()); + } + + public function testToForwardCookiesWithCurrentRequestWithoutCookies(): void + { + $request = new Request(); + $request->setMethod('GET'); + + $this->dependencies->set('request_stack', new RequestStack([$request])); + $this->dependencies->set('logger', $this->getMockBuilder(LoggerInterface::class)); + + $builder = $this->getDefaultBuilder() + ->forwardCookie('my_cookie') + ; + + self::assertArrayNotHasKey('cookies', $builder->getBodyBag()->all()); + } + + public function testRequestStackDependencyRequirementForForwardCookies(): void + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('RequestStack is required to use "Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies\RequestAwareTrait::getCurrentRequest" method. Try to run "composer require symfony/http-foundation".'); + + $this->getDefaultBuilder() + ->forwardCookie('my_cookie') + ; + } +} diff --git a/tests/Builder/Behaviors/Chromium/CustomHttpHeadersTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/CustomHttpHeadersTestCaseTrait.php new file mode 100644 index 00000000..fe816e86 --- /dev/null +++ b/tests/Builder/Behaviors/Chromium/CustomHttpHeadersTestCaseTrait.php @@ -0,0 +1,72 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testSetUserAgentWithUserAgentConstant(): void + { + $this->getDefaultBuilder() + ->userAgent(UserAgent::LinuxFirefox) + ->generate() + ; + + $this->assertGotenbergFormData('userAgent', UserAgent::LinuxFirefox); + } + + public function testSetExtraHttpHeaders(): void + { + $this->getDefaultBuilder() + ->extraHttpHeaders(['my_header' => 'my_value']) + ->generate() + ; + + $this->assertGotenbergFormData('extraHttpHeaders', '{"my_header":"my_value"}'); + } + + public function testToUnsetExistingExtraHttpHeaders(): void + { + $builder = $this->getDefaultBuilder() + ->extraHttpHeaders(['my_header' => 'my_value']) + ; + + self::assertArrayHasKey('extraHttpHeaders', $builder->getBodyBag()->all()); + + $builder->extraHttpHeaders([]); + self::assertArrayNotHasKey('extraHttpHeaders', $builder->getBodyBag()->all()); + } + + public function testAddExtraHttpHeadersToExistingHeaders(): void + { + $this->getDefaultBuilder() + ->extraHttpHeaders(['my_header' => 'my_value']) + ->addExtraHttpHeaders(['additional_header' => 'my_value']) + ->generate() + ; + + $this->assertGotenbergFormData('extraHttpHeaders', '{"my_header":"my_value","additional_header":"my_value"}'); + } + + public function testDoNotAddEmptyExtraHttpHeadersToExistingHeaders(): void + { + $this->getDefaultBuilder() + ->extraHttpHeaders(['my_header' => 'my_value']) + ->addExtraHttpHeaders([]) + ->generate() + ; + + $this->assertGotenbergFormData('extraHttpHeaders', '{"my_header":"my_value"}'); + } +} diff --git a/tests/Builder/Behaviors/Chromium/EmulatedMediaTypeTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/EmulatedMediaTypeTestCaseTrait.php new file mode 100644 index 00000000..40ff3d37 --- /dev/null +++ b/tests/Builder/Behaviors/Chromium/EmulatedMediaTypeTestCaseTrait.php @@ -0,0 +1,28 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testSetEmulatedMediaTypeWithPrintMediaType(): void + { + $this->getDefaultBuilder() + ->emulatedMediaType(EmulatedMediaType::Print) + ->generate() + ; + + $this->assertGotenbergFormData('emulatedMediaType', EmulatedMediaType::Print->value); + } +} diff --git a/tests/Builder/Behaviors/Chromium/FailOnTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/FailOnTestCaseTrait.php new file mode 100644 index 00000000..2195ea1a --- /dev/null +++ b/tests/Builder/Behaviors/Chromium/FailOnTestCaseTrait.php @@ -0,0 +1,57 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testSetFailOnHttpStatusCodesOnUnauthorizedStatusCode(): void + { + $this->getDefaultBuilder() + ->failOnHttpStatusCodes([401]) + ->generate() + ; + + $this->assertGotenbergFormData('failOnHttpStatusCodes', '[401]'); + } + + public function testSetFailOnResourceHttpStatusCodesOnUnauthorizedStatusCode(): void + { + $this->getDefaultBuilder() + ->failOnResourceHttpStatusCodes([401]) + ->generate() + ; + + $this->assertGotenbergFormData('failOnResourceHttpStatusCodes', '[401]'); + } + + public function testSetFailOnResourceLoaded(): void + { + $this->getDefaultBuilder() + ->failOnResourceLoadingFailed() + ->generate() + ; + + $this->assertGotenbergFormData('failOnResourceLoadingFailed', 'true'); + } + + public function testSetFailOnConsoleExceptions(): void + { + $this->getDefaultBuilder() + ->failOnConsoleExceptions() + ->generate() + ; + + $this->assertGotenbergFormData('failOnConsoleExceptions', 'true'); + } +} diff --git a/tests/Builder/Behaviors/Chromium/PdfPagePropertiesTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/PdfPagePropertiesTestCaseTrait.php new file mode 100644 index 00000000..1f92e9fc --- /dev/null +++ b/tests/Builder/Behaviors/Chromium/PdfPagePropertiesTestCaseTrait.php @@ -0,0 +1,278 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testSetSinglePageOnRendering(): void + { + $this->getDefaultBuilder() + ->singlePage() + ->generate() + ; + + $this->assertGotenbergFormData('singlePage', 'true'); + } + + public function testSetWidthOnRendering(): void + { + $this->getDefaultBuilder() + ->paperWidth(200) + ->generate() + ; + + $this->assertGotenbergFormData('paperWidth', '200in'); + } + + public function testSetWidthOnRenderingWithUnit(): void + { + $this->getDefaultBuilder() + ->paperWidth(21, Unit::Centimeters) + ->generate() + ; + + $this->assertGotenbergFormData('paperWidth', '21cm'); + } + + public function testSetPaperHeightOnRendering(): void + { + $this->getDefaultBuilder() + ->paperHeight(150) + ->generate() + ; + + $this->assertGotenbergFormData('paperHeight', '150in'); + } + + public function testSetPaperHeightOnRenderingWithUnit(): void + { + $this->getDefaultBuilder() + ->paperHeight(29.7, Unit::Centimeters) + ->generate() + ; + + $this->assertGotenbergFormData('paperHeight', '29.7cm'); + } + + public function testSetPaperSizeOnRendering(): void + { + $this->getDefaultBuilder() + ->paperSize(200, 150) + ->generate() + ; + + $this->assertGotenbergFormData('paperWidth', '200in'); + $this->assertGotenbergFormData('paperHeight', '150in'); + } + + public function testSetPaperSizeOnRenderingWithUnit(): void + { + $this->getDefaultBuilder() + ->paperSize(21, 29.7, Unit::Centimeters) + ->generate() + ; + + $this->assertGotenbergFormData('paperWidth', '21cm'); + $this->assertGotenbergFormData('paperHeight', '29.7cm'); + } + + public function testSetPaperStandardSizeOnRendering(): void + { + $this->getDefaultBuilder() + ->paperStandardSize(PaperSize::A4) + ->generate() + ; + + $this->assertGotenbergFormData('paperWidth', '8.27in'); + $this->assertGotenbergFormData('paperHeight', '11.7in'); + } + + public function testSetMarginTopOnRendering(): void + { + $this->getDefaultBuilder() + ->marginTop(2) + ->generate() + ; + + $this->assertGotenbergFormData('marginTop', '2in'); + } + + public function testSetMarginTopOnRenderingWithUnit(): void + { + $this->getDefaultBuilder() + ->marginTop(2, Unit::Centimeters) + ->generate() + ; + + $this->assertGotenbergFormData('marginTop', '2cm'); + } + + public function testSetMarginBottomOnRendering(): void + { + $this->getDefaultBuilder() + ->marginBottom(2) + ->generate() + ; + + $this->assertGotenbergFormData('marginBottom', '2in'); + } + + public function testSetMarginBottomOnRenderingWithUnit(): void + { + $this->getDefaultBuilder() + ->marginBottom(2, Unit::Centimeters) + ->generate() + ; + + $this->assertGotenbergFormData('marginBottom', '2cm'); + } + + public function testSetMarginLeftOnRendering(): void + { + $this->getDefaultBuilder() + ->marginLeft(2) + ->generate() + ; + + $this->assertGotenbergFormData('marginLeft', '2in'); + } + + public function testSetMarginLeftOnRenderingWithUnit(): void + { + $this->getDefaultBuilder() + ->marginLeft(2, Unit::Centimeters) + ->generate() + ; + + $this->assertGotenbergFormData('marginLeft', '2cm'); + } + + public function testSetMarginRightOnRendering(): void + { + $this->getDefaultBuilder() + ->marginRight(2) + ->generate() + ; + + $this->assertGotenbergFormData('marginRight', '2in'); + } + + public function testSetMarginRightOnRenderingWithUnit(): void + { + $this->getDefaultBuilder() + ->marginRight(2, Unit::Centimeters) + ->generate() + ; + + $this->assertGotenbergFormData('marginRight', '2cm'); + } + + public function testSetMarginsOnRendering(): void + { + $this->getDefaultBuilder() + ->margins(2, 2, 2, 2) + ->generate() + ; + + $this->assertGotenbergFormData('marginTop', '2in'); + $this->assertGotenbergFormData('marginBottom', '2in'); + $this->assertGotenbergFormData('marginLeft', '2in'); + $this->assertGotenbergFormData('marginRight', '2in'); + } + + public function testSetMarginsOnRenderingWithUnit(): void + { + $this->getDefaultBuilder() + ->margins(2, 2, 2, 2, Unit::Centimeters) + ->generate() + ; + + $this->assertGotenbergFormData('marginTop', '2cm'); + $this->assertGotenbergFormData('marginBottom', '2cm'); + $this->assertGotenbergFormData('marginLeft', '2cm'); + $this->assertGotenbergFormData('marginRight', '2cm'); + } + + public function testPreferCssPageSizeOnRendering(): void + { + $this->getDefaultBuilder() + ->preferCssPageSize(true) + ->generate() + ; + + $this->assertGotenbergFormData('preferCssPageSize', 'true'); + } + + public function testGenerateDocumentOutlineEmbeddedIntoPdf(): void + { + $this->getDefaultBuilder() + ->generateDocumentOutline(true) + ->generate() + ; + + $this->assertGotenbergFormData('generateDocumentOutline', 'true'); + } + + public function testPrintBackgroundIntoPdf(): void + { + $this->getDefaultBuilder() + ->printBackground(true) + ->generate() + ; + + $this->assertGotenbergFormData('printBackground', 'true'); + } + + public function testSetOmitBackgroundOnRendering(): void + { + $this->getDefaultBuilder() + ->omitBackground(true) + ->generate() + ; + + $this->assertGotenbergFormData('omitBackground', 'true'); + } + + public function testSetOrientationToLandscape(): void + { + $this->getDefaultBuilder() + ->landscape() + ->generate() + ; + + $this->assertGotenbergFormData('landscape', 'true'); + } + + public function testSetScaleOnRendering(): void + { + $this->getDefaultBuilder() + ->scale(1.5) + ->generate() + ; + + $this->assertGotenbergFormData('scale', '1.5'); + } + + public function testNativePageRangesForRendering(): void + { + $this->getDefaultBuilder() + ->nativePageRanges('1-5') + ->generate() + ; + + $this->assertGotenbergFormData('nativePageRanges', '1-5'); + } +} diff --git a/tests/Builder/Behaviors/Chromium/PerformanceModeTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/PerformanceModeTestCaseTrait.php new file mode 100644 index 00000000..0eff1001 --- /dev/null +++ b/tests/Builder/Behaviors/Chromium/PerformanceModeTestCaseTrait.php @@ -0,0 +1,27 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testWaitForChromiumNetworkToBeIdle(): void + { + $this->getDefaultBuilder() + ->skipNetworkIdleEvent() + ->generate() + ; + + $this->assertGotenbergFormData('skipNetworkIdleEvent', 'true'); + } +} diff --git a/tests/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTestCaseTrait.php new file mode 100644 index 00000000..5c3b7a0f --- /dev/null +++ b/tests/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTestCaseTrait.php @@ -0,0 +1,88 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testSetWidthOnScreenshotRendering(): void + { + $this->getDefaultBuilder() + ->width(500) + ->generate() + ; + + $this->assertGotenbergFormData('width', '500'); + } + + public function testSetHeightOnScreenshotRendering(): void + { + $this->getDefaultBuilder() + ->height(200) + ->generate() + ; + + $this->assertGotenbergFormData('height', '200'); + } + + public function testClipAccordingToTheDeviceDimensions(): void + { + $this->getDefaultBuilder() + ->clip() + ->generate() + ; + + $this->assertGotenbergFormData('clip', 'true'); + } + + public function testScreenshotFormatOutput(): void + { + $this->getDefaultBuilder() + ->format(ScreenshotFormat::Png) + ->generate() + ; + + $this->assertGotenbergFormData('format', 'png'); + } + + public function testQualityOfTheScreenshotRendering(): void + { + $this->getDefaultBuilder() + ->quality(50) + ->generate() + ; + + $this->assertGotenbergFormData('quality', '50'); + } + + public function testSetOmitBackgroundOnRendering(): void + { + $this->getDefaultBuilder() + ->omitBackground(true) + ->generate() + ; + + $this->assertGotenbergFormData('omitBackground', 'true'); + } + + public function testOptimizeImageEncodingForSpeed(): void + { + $this->getDefaultBuilder() + ->optimizeForSpeed() + ->generate() + ; + + $this->assertGotenbergFormData('optimizeForSpeed', 'true'); + } +} diff --git a/tests/Builder/Behaviors/Chromium/WaitBeforeRenderingTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/WaitBeforeRenderingTestCaseTrait.php new file mode 100644 index 00000000..978ec042 --- /dev/null +++ b/tests/Builder/Behaviors/Chromium/WaitBeforeRenderingTestCaseTrait.php @@ -0,0 +1,37 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testWaitDurationBeforeConverting(): void + { + $this->getDefaultBuilder() + ->waitDelay('2s') + ->generate() + ; + + $this->assertGotenbergFormData('waitDelay', '2s'); + } + + public function testSetWaitForExpression(): void + { + $this->getDefaultBuilder() + ->waitForExpression("window.status === 'ready'") + ->generate() + ; + + $this->assertGotenbergFormData('waitForExpression', "window.status === 'ready'"); + } +} diff --git a/tests/Builder/Behaviors/ChromiumPdfTestCaseTrait.php b/tests/Builder/Behaviors/ChromiumPdfTestCaseTrait.php new file mode 100644 index 00000000..3df71d22 --- /dev/null +++ b/tests/Builder/Behaviors/ChromiumPdfTestCaseTrait.php @@ -0,0 +1,50 @@ + */ + use Chromium\AssetTestCaseTrait; + + /** @use Chromium\CookieTestCaseTrait */ + use Chromium\CookieTestCaseTrait; + + /** @use Chromium\CustomHttpHeadersTestCaseTrait */ + use Chromium\CustomHttpHeadersTestCaseTrait; + + /** @use Chromium\EmulatedMediaTypeTestCaseTrait */ + use Chromium\EmulatedMediaTypeTestCaseTrait; + + /** @use Chromium\FailOnTestCaseTrait */ + use Chromium\FailOnTestCaseTrait; + + /** @use Chromium\PdfPagePropertiesTestCaseTrait */ + use Chromium\PdfPagePropertiesTestCaseTrait; + + /** @use Chromium\PerformanceModeTestCaseTrait */ + use Chromium\PerformanceModeTestCaseTrait; + + /** @use Chromium\WaitBeforeRenderingTestCaseTrait */ + use Chromium\WaitBeforeRenderingTestCaseTrait; + + /** @use DownloadFromTestCaseTrait */ + use DownloadFromTestCaseTrait; + + /** @use MetadataTestCaseTrait */ + use MetadataTestCaseTrait; + + /** @use PdfFormatTestCaseTrait */ + use PdfFormatTestCaseTrait; + + /** @use SplitTestCaseTrait */ + use SplitTestCaseTrait; + + /** @use WebhookTestCaseTrait */ + use WebhookTestCaseTrait; +} diff --git a/tests/Builder/Behaviors/ChromiumScreenshotTestCaseTrait.php b/tests/Builder/Behaviors/ChromiumScreenshotTestCaseTrait.php new file mode 100644 index 00000000..5bec87e5 --- /dev/null +++ b/tests/Builder/Behaviors/ChromiumScreenshotTestCaseTrait.php @@ -0,0 +1,38 @@ + */ + use Chromium\CookieTestCaseTrait; + + /** @use Chromium\CustomHttpHeadersTestCaseTrait */ + use Chromium\CustomHttpHeadersTestCaseTrait; + + /** @use Chromium\EmulatedMediaTypeTestCaseTrait */ + use Chromium\EmulatedMediaTypeTestCaseTrait; + + /** @use Chromium\FailOnTestCaseTrait */ + use Chromium\FailOnTestCaseTrait; + + /** @use Chromium\PerformanceModeTestCaseTrait */ + use Chromium\PerformanceModeTestCaseTrait; + + /** @use Chromium\ScreenshotPagePropertiesTestCaseTrait */ + use Chromium\ScreenshotPagePropertiesTestCaseTrait; + + /** @use Chromium\WaitBeforeRenderingTestCaseTrait */ + use Chromium\WaitBeforeRenderingTestCaseTrait; + + /** @use DownloadFromTestCaseTrait */ + use DownloadFromTestCaseTrait; + + /** @use WebhookTestCaseTrait */ + use WebhookTestCaseTrait; +} diff --git a/tests/Builder/Behaviors/DownloadFromTestCaseTrait.php b/tests/Builder/Behaviors/DownloadFromTestCaseTrait.php new file mode 100644 index 00000000..eb42c073 --- /dev/null +++ b/tests/Builder/Behaviors/DownloadFromTestCaseTrait.php @@ -0,0 +1,50 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testAddAnExternalResource(): void + { + $this->getDefaultBuilder() + ->downloadFrom([ + [ + 'url' => 'http://url/to/file.com', + 'extraHttpHeaders' => ['MyHeader' => 'MyValue', 'User-Agent' => 'MyValue'], + ], + ]) + ->generate() + ; + + $this->assertGotenbergFormData('downloadFrom', '[{"url":"http:\/\/url\/to\/file.com","extraHttpHeaders":{"MyHeader":"MyValue","User-Agent":"MyValue"}}]'); + } + + public function testUnsetDownloadResource(): void + { + $builder = $this->getDefaultBuilder() + ->downloadFrom([ + [ + 'url' => 'http://url/to/file.com', + 'extraHttpHeaders' => ['MyHeader' => 'MyValue', 'User-Agent' => 'MyValue'], + ], + ]) + ; + + self::assertArrayHasKey('downloadFrom', $builder->getBodyBag()->all()); + + $builder->downloadFrom([]); + self::assertArrayNotHasKey('downloadFrom', $builder->getBodyBag()->all()); + } +} diff --git a/tests/Builder/Behaviors/FlattenTestCaseTrait.php b/tests/Builder/Behaviors/FlattenTestCaseTrait.php new file mode 100644 index 00000000..d013d74b --- /dev/null +++ b/tests/Builder/Behaviors/FlattenTestCaseTrait.php @@ -0,0 +1,28 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testFlattenContentsIntoSinglePdf(): void + { + $this->getDefaultBuilder() + ->flatten() + ->generate() + ; + + $this->assertGotenbergFormData('flatten', 'true'); + } +} diff --git a/tests/Builder/Behaviors/LibreOffice/PagePropertiesTestCaseTrait.php b/tests/Builder/Behaviors/LibreOffice/PagePropertiesTestCaseTrait.php new file mode 100644 index 00000000..2e9ecb35 --- /dev/null +++ b/tests/Builder/Behaviors/LibreOffice/PagePropertiesTestCaseTrait.php @@ -0,0 +1,270 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testSetPassword(): void + { + $this->getDefaultBuilder() + ->password('my_password') + ->generate() + ; + + $this->assertGotenbergFormData('password', 'my_password'); + } + + public function testSetOrientationToLandscape(): void + { + $this->getDefaultBuilder() + ->landscape() + ->generate() + ; + + $this->assertGotenbergFormData('landscape', 'true'); + } + + public function testNativePageRangesForRendering(): void + { + $this->getDefaultBuilder() + ->nativePageRanges('1-2') + ->generate() + ; + + $this->assertGotenbergFormData('nativePageRanges', '1-2'); + } + + public function testDoNotExportFormFields(): void + { + $this->getDefaultBuilder() + ->doNotExportFormFields() + ->generate() + ; + + $this->assertGotenbergFormData('exportFormFields', 'false'); + } + + public function testAllowDuplicateFieldNames(): void + { + $this->getDefaultBuilder() + ->allowDuplicateFieldNames() + ->generate() + ; + + $this->assertGotenbergFormData('allowDuplicateFieldNames', 'true'); + } + + public function testDoNotExportBookmarks(): void + { + $this->getDefaultBuilder() + ->doNotExportBookmarks() + ->generate() + ; + + $this->assertGotenbergFormData('exportBookmarks', 'false'); + } + + public function testExportBookmarksToPdfDestination(): void + { + $this->getDefaultBuilder() + ->exportBookmarksToPdfDestination() + ->generate() + ; + + $this->assertGotenbergFormData('exportBookmarksToPdfDestination', 'true'); + } + + public function testExportPlaceholders(): void + { + $this->getDefaultBuilder() + ->exportPlaceholders() + ->generate() + ; + + $this->assertGotenbergFormData('exportPlaceholders', 'true'); + } + + public function testExportNotes(): void + { + $this->getDefaultBuilder() + ->exportNotes() + ->generate() + ; + + $this->assertGotenbergFormData('exportNotes', 'true'); + } + + public function testExportNotesPages(): void + { + $this->getDefaultBuilder() + ->exportNotesPages() + ->generate() + ; + + $this->assertGotenbergFormData('exportNotesPages', 'true'); + } + + public function testExportOnlyNotesPages(): void + { + $this->getDefaultBuilder() + ->exportOnlyNotesPages() + ->generate() + ; + + $this->assertGotenbergFormData('exportOnlyNotesPages', 'true'); + } + + public function testExportNotesInMargin(): void + { + $this->getDefaultBuilder() + ->exportNotesInMargin() + ->generate() + ; + + $this->assertGotenbergFormData('exportNotesInMargin', 'true'); + } + + public function testConvertOooTargetToPdfTarget(): void + { + $this->getDefaultBuilder() + ->convertOooTargetToPdfTarget() + ->generate() + ; + + $this->assertGotenbergFormData('convertOooTargetToPdfTarget', 'true'); + } + + public function testExportLinksRelativeFsys(): void + { + $this->getDefaultBuilder() + ->exportLinksRelativeFsys() + ->generate() + ; + + $this->assertGotenbergFormData('exportLinksRelativeFsys', 'true'); + } + + public function testExportHiddenSlides(): void + { + $this->getDefaultBuilder() + ->exportHiddenSlides() + ->generate() + ; + + $this->assertGotenbergFormData('exportHiddenSlides', 'true'); + } + + public function testSkipEmptyPages(): void + { + $this->getDefaultBuilder() + ->skipEmptyPages() + ->generate() + ; + + $this->assertGotenbergFormData('skipEmptyPages', 'true'); + } + + public function testAddOriginalDocumentAsStream(): void + { + $this->getDefaultBuilder() + ->addOriginalDocumentAsStream() + ->generate() + ; + + $this->assertGotenbergFormData('addOriginalDocumentAsStream', 'true'); + } + + public function testSinglePageSheets(): void + { + $this->getDefaultBuilder() + ->singlePageSheets() + ->generate() + ; + + $this->assertGotenbergFormData('singlePageSheets', 'true'); + } + + public function testMergeTheResultingPdf(): void + { + $this->getDefaultBuilder() + ->merge() + ->generate() + ; + + $this->assertGotenbergFormData('merge', 'true'); + } + + public function testLosslessImageCompression(): void + { + $this->getDefaultBuilder() + ->losslessImageCompression() + ->generate() + ; + + $this->assertGotenbergFormData('losslessImageCompression', 'true'); + } + + public function testQualityOfTheJpgExport(): void + { + $this->getDefaultBuilder() + ->quality(50) + ->generate() + ; + + $this->assertGotenbergFormData('quality', '50'); + } + + public function testReduceImageResolution(): void + { + $this->getDefaultBuilder() + ->reduceImageResolution() + ->generate() + ; + + $this->assertGotenbergFormData('reduceImageResolution', 'true'); + } + + public function testMaxImageResolution(): void + { + $this->getDefaultBuilder() + ->maxImageResolution(ImageResolutionDPI::DPI150) + ->generate() + ; + + $this->assertGotenbergFormData('maxImageResolution', (string) ImageResolutionDPI::DPI150->value); + } + + public function testUnsetMaxImageResolution(): void + { + $builder = $this->getDefaultBuilder() + ->maxImageResolution(ImageResolutionDPI::DPI150) + ; + + self::assertArrayHasKey('maxImageResolution', $builder->getBodyBag()->all()); + + $builder->maxImageResolution(null); + self::assertArrayNotHasKey('maxImageResolution', $builder->getBodyBag()->all()); + } + + public function testDoNotUpdateIndexes(): void + { + $this->getDefaultBuilder() + ->doNotUpdateIndexes() + ->generate() + ; + + $this->assertGotenbergFormData('updateIndexes', 'false'); + } +} diff --git a/tests/Builder/Behaviors/LibreOfficeTestCaseTrait.php b/tests/Builder/Behaviors/LibreOfficeTestCaseTrait.php new file mode 100644 index 00000000..75132e04 --- /dev/null +++ b/tests/Builder/Behaviors/LibreOfficeTestCaseTrait.php @@ -0,0 +1,32 @@ + */ + use DownloadFromTestCaseTrait; + + /** @use FlattenTestCaseTrait */ + use FlattenTestCaseTrait; + + /** @use LibreOffice\PagePropertiesTestCaseTrait */ + use LibreOffice\PagePropertiesTestCaseTrait; + + /** @use MetadataTestCaseTrait */ + use MetadataTestCaseTrait; + + /** @use PdfFormatTestCaseTrait */ + use PdfFormatTestCaseTrait; + + /** @use SplitTestCaseTrait */ + use SplitTestCaseTrait; + + /** @use WebhookTestCaseTrait */ + use WebhookTestCaseTrait; +} diff --git a/tests/Builder/Behaviors/MetadataTestCaseTrait.php b/tests/Builder/Behaviors/MetadataTestCaseTrait.php new file mode 100644 index 00000000..155b4216 --- /dev/null +++ b/tests/Builder/Behaviors/MetadataTestCaseTrait.php @@ -0,0 +1,47 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testSetMetadataWithArray(): void + { + $this->getDefaultBuilder() + ->metadata([ + 'Author' => 'SensioLabs', + 'Creator' => 'SensioLabs', + 'Title' => 'GotenbergBundle', + ]) + ->generate() + ; + + $this->assertGotenbergFormData('metadata', '{"Author":"SensioLabs","Creator":"SensioLabs","Title":"GotenbergBundle"}'); + } + + public function testAddMetadataToExistingMetadata(): void + { + $this->getDefaultBuilder() + ->metadata([ + 'Author' => 'SensioLabs', + 'Creator' => 'SensioLabs', + 'Title' => 'GotenbergBundle', + ]) + ->addMetadata('Title', 'MyBundle') + ->generate() + ; + + $this->assertGotenbergFormData('metadata', '{"Title":"MyBundle","Author":"SensioLabs","Creator":"SensioLabs"}'); + } +} diff --git a/tests/Builder/Behaviors/PdfFormatTestCaseTrait.php b/tests/Builder/Behaviors/PdfFormatTestCaseTrait.php new file mode 100644 index 00000000..1a4901d5 --- /dev/null +++ b/tests/Builder/Behaviors/PdfFormatTestCaseTrait.php @@ -0,0 +1,51 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testPdfFormatForTheResultingPdf(): void + { + $this->getDefaultBuilder() + ->pdfFormat(PdfFormat::Pdf1b) + ->generate() + ; + + $this->assertGotenbergFormData('pdfa', PdfFormat::Pdf1b->value); + } + + public function testPdfUniversalAccessForTheResultingPdf(): void + { + $this->getDefaultBuilder() + ->pdfUniversalAccess() + ->generate() + ; + + $this->assertGotenbergFormData('pdfua', 'true'); + } + + public function testUnsetPdfFormat(): void + { + $builder = $this->getDefaultBuilder() + ->pdfFormat(PdfFormat::Pdf1b) + ; + + self::assertArrayHasKey('pdfa', $builder->getBodyBag()->all()); + + $builder->pdfFormat(null); + self::assertArrayNotHasKey('pdfa', $builder->getBodyBag()->all()); + } +} diff --git a/tests/Builder/Behaviors/SplitTestCaseTrait.php b/tests/Builder/Behaviors/SplitTestCaseTrait.php new file mode 100644 index 00000000..91d25152 --- /dev/null +++ b/tests/Builder/Behaviors/SplitTestCaseTrait.php @@ -0,0 +1,61 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergFormData(string $field, string $expectedValue): void; + + public function testSplitPdfIntoPageMode(): void + { + $this->getDefaultBuilder() + ->splitMode(SplitMode::Pages) + ->generate() + ; + + $this->assertGotenbergFormData('splitMode', SplitMode::Pages->value); + } + + public function testSplitPdfWithPageRanges(): void + { + $this->getDefaultBuilder() + ->splitSpan('1-2') + ->generate() + ; + + $this->assertGotenbergFormData('splitSpan', '1-2'); + } + + public function testUnifyTheSplittingResultIntoOnePdf(): void + { + $this->getDefaultBuilder() + ->splitUnify() + ->generate() + ; + + $this->assertGotenbergFormData('splitUnify', 'true'); + } + + public function testUnsetSplitMode(): void + { + $builder = $this->getDefaultBuilder() + ->splitMode(SplitMode::Pages) + ; + + self::assertArrayHasKey('splitMode', $builder->getBodyBag()->all()); + + $builder->splitMode(null); + self::assertArrayNotHasKey('splitMode', $builder->getBodyBag()->all()); + } +} diff --git a/tests/Builder/Behaviors/WebhookTestCaseTrait.php b/tests/Builder/Behaviors/WebhookTestCaseTrait.php new file mode 100644 index 00000000..afbd341a --- /dev/null +++ b/tests/Builder/Behaviors/WebhookTestCaseTrait.php @@ -0,0 +1,276 @@ + */ + use BehaviorTrait; + + abstract protected function assertGotenbergHeader(string $name, mixed $value): void; + + public function testAddFullWebhookConfiguration(): void + { + $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); + + $this->getDefaultBuilder() + ->webhook([ + 'config_name' => 'my_config', + 'success' => [ + 'url' => 'http://example.com/success', + 'method' => 'PUT', + ], + 'error' => [ + 'url' => 'http://example.com/error', + 'method' => 'POST', + ], + 'extra_http_headers' => [ + 'my_header' => 'value', + ], + ]) + ->generate() + ; + + $this->assertGotenbergHeader('Gotenberg-Webhook-Url', 'http://example.com/success'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Method', 'PUT'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Url', 'http://example.com/error'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Method', 'POST'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Extra-Http-Headers', '{"my_header":"value"}'); + } + + public function testFullWebhookConfigurationWithRoute(): void + { + $router = $this->createMock(Router::class); + $router->expects($this->exactly(2)) + ->method('generate') + ->willReturnOnConsecutiveCalls('http://example.com/success', 'http://example.com/error') + ; + + $this->dependencies->set('router', $router); + + $this->getDefaultBuilder() + ->webhook([ + 'config_name' => 'my_config', + 'success' => [ + 'route' => 'my_route', + 'method' => 'PUT', + ], + 'error' => [ + 'route' => 'my_error_route', + 'method' => 'POST', + ], + 'extra_http_headers' => [ + 'my_header' => 'value', + ], + ]) + ->generate() + ; + + $this->assertGotenbergHeader('Gotenberg-Webhook-Url', 'http://example.com/success'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Method', 'PUT'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Url', 'http://example.com/error'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Method', 'POST'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Extra-Http-Headers', '{"my_header":"value"}'); + } + + public function testFullWebhookConfigurationWithRouteParams(): void + { + $router = $this->createMock(Router::class); + $router->expects($this->exactly(2)) + ->method('generate') + ->willReturnOnConsecutiveCalls('http://example.com/success', 'http://example.com/error') + ; + + $this->dependencies->set('router', $router); + + $this->getDefaultBuilder() + ->webhook([ + 'config_name' => 'my_config', + 'success' => [ + 'route' => [ + 'my_route', + ['var' => 'foo'], + ], + 'method' => 'PUT', + ], + 'error' => [ + 'route' => [ + 'my_error_route', + ['var' => 'foo'], + ], + 'method' => 'POST', + ], + 'extra_http_headers' => [ + 'my_header' => 'value', + ], + ]) + ->generate() + ; + + $this->assertGotenbergHeader('Gotenberg-Webhook-Url', 'http://example.com/success'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Method', 'PUT'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Url', 'http://example.com/error'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Method', 'POST'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Extra-Http-Headers', '{"my_header":"value"}'); + } + + public function testAddWebhookUrlToCallOnSuccessResult(): void + { + $this->getDefaultBuilder() + ->webhookUrl('http://example.com/success', 'PUT') + ->generate() + ; + + $this->assertGotenbergHeader('Gotenberg-Webhook-Url', 'http://example.com/success'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Method', 'PUT'); + } + + public function testAddWebhookUrlToCallOnErrorResult(): void + { + $this->getDefaultBuilder() + ->webhookErrorUrl('http://example.com/error', 'POST') + ->generate() + ; + + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Url', 'http://example.com/error'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Method', 'POST'); + } + + public function testAddWebhookExtraHeaders(): void + { + $this->getDefaultBuilder() + ->webhookExtraHeaders(['my_header' => 'value']) + ->generate() + ; + + $this->assertGotenbergHeader('Gotenberg-Webhook-Extra-Http-Headers', '{"my_header":"value"}'); + } + + /** + * @return iterable>> + */ + public static function provideInvalidWebhookConfiguration(): iterable + { + yield 'with missing success configuration' => [ + [ + 'config_name' => 'my_config', + ], + 'Invalid webhook configuration : At least a "success" key is required.', + ]; + yield 'with invalid method' => [ + [ + 'success' => [ + 'url' => 'http://example.com/success', + 'method' => 'GET', + ], + ], + 'Invalid webhook configuration : "POST" "PUT", "PATCH" are the only available methods for "success" configuration.', + ]; + + yield 'with invalid route configuration' => [ + [ + 'success' => [ + 'route' => [ + ['my_route'], + ['var' => 'foo'], + ], + 'method' => 'PUT', + ], + ], + 'Invalid webhook configuration : You must provide a valid route name for "success" configuration.', + ]; + yield 'with invalid route params configuration' => [ + [ + 'success' => [ + 'route' => [ + 'my_route', + 'foo', + ], + 'method' => 'PUT', + ], + ], + 'Invalid webhook configuration : You must provide valid route parameters for "success" configuration.', + ]; + yield 'with route and url configuration' => [ + [ + 'success' => [ + 'url' => 'http://example.com/success', + 'route' => [ + 'my_route', + ], + 'method' => 'PUT', + ], + ], + 'Invalid webhook configuration : You must provide "url" or "route" keys for "success" configuration.', + ]; + } + + /** + * @param array $configuration + */ + #[DataProvider('provideInvalidWebhookConfiguration')] + public function testWebhookConfigurationRequirement(array $configuration, string $exceptionMessage): void + { + $this->expectException(InvalidBuilderConfiguration::class); + $this->expectExceptionMessage($exceptionMessage); + + $this->getDefaultBuilder() + ->webhook($configuration) + ->generate() + ; + } + + public function testUnsetWebhook(): void + { + $builder = $this->getDefaultBuilder() + ->webhook([ + 'config_name' => 'my_config', + 'success' => [ + 'url' => 'http://example.com/success', + 'method' => 'PUT', + ], + 'error' => [ + 'url' => 'http://example.com/error', + 'method' => 'POST', + ], + 'extra_http_headers' => [ + 'my_header' => 'value', + ], + ]) + ; + + self::assertArrayHasKey('Gotenberg-Webhook-Url', $builder->getHeadersBag()->all()); + self::assertSame('http://example.com/success', $builder->getHeadersBag()->get('Gotenberg-Webhook-Url')); + + self::assertArrayHasKey('Gotenberg-Webhook-Method', $builder->getHeadersBag()->all()); + self::assertSame('PUT', $builder->getHeadersBag()->get('Gotenberg-Webhook-Method')); + + self::assertArrayHasKey('Gotenberg-Webhook-Error-Url', $builder->getHeadersBag()->all()); + self::assertSame('http://example.com/error', $builder->getHeadersBag()->get('Gotenberg-Webhook-Error-Url')); + + self::assertArrayHasKey('Gotenberg-Webhook-Error-Method', $builder->getHeadersBag()->all()); + self::assertSame('POST', $builder->getHeadersBag()->get('Gotenberg-Webhook-Error-Method')); + + self::assertArrayHasKey('Gotenberg-Webhook-Extra-Http-Headers', $builder->getHeadersBag()->all()); + self::assertSame('{"my_header":"value"}', $builder->getHeadersBag()->get('Gotenberg-Webhook-Extra-Http-Headers')); + + $builder->webhook([]); + + self::assertArrayNotHasKey('Gotenberg-Webhook-Url', $builder->getHeadersBag()->all()); + self::assertArrayNotHasKey('Gotenberg-Webhook-Method', $builder->getHeadersBag()->all()); + self::assertArrayNotHasKey('Gotenberg-Webhook-Error-Url', $builder->getHeadersBag()->all()); + self::assertArrayNotHasKey('Gotenberg-Webhook-Error-Method', $builder->getHeadersBag()->all()); + self::assertArrayNotHasKey('Gotenberg-Webhook-Extra-Http-Headers', $builder->getHeadersBag()->all()); + } +} diff --git a/tests/Builder/DefaultBuilderTraitTest.php b/tests/Builder/DefaultBuilderTraitTest.php deleted file mode 100644 index 93ebb357..00000000 --- a/tests/Builder/DefaultBuilderTraitTest.php +++ /dev/null @@ -1,142 +0,0 @@ -getBuilder(); - - self::assertSame([ - 'key' => '{"key_v1":"value_v1"}', - ], $builder->encodeData('key', ['key_v1' => 'value_v1'])); - } - - public function testEncodeDataFailIfSomethingWentWrong(): void - { - $builder = $this->getBuilder(); - - $this->expectException(JsonEncodingException::class); - $this->expectExceptionMessage('Could not encode property "key" into JSON'); - - $builder->encodeData('key', [\INF]); - } - - public static function canConvertToMultiPartProvider(): \Generator - { - yield 'simple boolean (true)' => [true, [['key' => 'true']]]; - yield 'simple boolean (false)' => [false, [['key' => 'false']]]; - - yield 'simple int' => [12, [['key' => '12']]]; - - yield 'simple float' => [12.2, [['key' => '12.2']]]; - yield 'rounded float' => [12.0, [['key' => '12.0']]]; - - yield 'any BackedEnum' => [PdfFormat::Pdf2b, [['key' => 'PDF/A-2b']]]; - - yield 'any Stringable' => [new class implements \Stringable { - public function __toString(): string - { - return __FUNCTION__; - } - }, [['key' => '__toString']]]; - - yield 'nested array' => [[ - 'level1' => [ - 'level2' => [ - 'level2_rounded_float' => 12.0, - 'level2_simple_float' => 12.5, - 'level2_boolean' => true, - ], - 'simple_boolean' => true, - ], - ], [ - ['key' => '12.0'], - ['key' => '12.5'], - ['key' => 'true'], - ['key' => 'true'], - ]]; - - yield 'simple string' => ['hello world', [['key' => 'hello world']]]; - - yield 'with custom normalizer' => ['', [['key' => 'plop']], static function (): array { - return ['key' => 'plop']; - }]; - } - - #[DataProvider('canConvertToMultiPartProvider')] - public function testCanConvertToMultiPart(mixed $value, array $expectedResult, callable|null $normalizer = null): void - { - $builder = $this->getBuilder(); - $builder->addFormField('key', $value); - - if (null !== $normalizer) { - $builder->addNormalizer('key', $normalizer); - } - - self::assertSame($expectedResult, $builder->getMultipartFormData()); - } - - public function testCanAssertFileExtensionsAndThrowIfNotValid(): void - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The file extension "html" is not valid in this context.'); - - $builder = $this->getBuilder(); - $builder->assertFileExtension('content.html', ['txt']); - } - - public function testCanAssertFileExtensions(): void - { - $builder = $this->getBuilder(); - $builder->assertFileExtension('content.html', ['html']); - - $this->addToAssertionCount(1); - } - - private function getBuilder(): object - { - return new class { - use DefaultBuilderTrait { - addNormalizer as public; - encodeData as public; - assertFileExtension as public; - } - - public function __construct() - { - $this->asset = new AssetBaseDirFormatter( - __DIR__.'/../Fixtures', - 'files', - ); - } - - protected function getEndpoint(): string - { - // TODO: Implement getEndpoint() method. - } - - public function setConfigurations(array $configurations): static - { - // TODO: Implement setConfigurations() method. - } - - public function addFormField(string $key, mixed $value): void - { - $this->formFields[$key] = $value; - } - }; - } -} diff --git a/tests/Builder/GotenbergBuilderTestCase.php b/tests/Builder/GotenbergBuilderTestCase.php new file mode 100644 index 00000000..b9467082 --- /dev/null +++ b/tests/Builder/GotenbergBuilderTestCase.php @@ -0,0 +1,146 @@ +client = new GotenbergClientAsserter(); + $this->dependencies = new Container(); + + $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(static::FIXTURE_DIR, static::FIXTURE_DIR)); + } + + /** + * @return T + */ + abstract protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): BuilderInterface; + + /** + * @return T + */ + protected function getBuilder(): BuilderInterface + { + return $this->builder ??= $this->createBuilder($this->client, $this->dependencies); + } + + protected function getDependencies(): Container + { + return $this->dependencies; + } + + protected function assertGotenbergEndpoint(string $endpoint): void + { + $this->assertSame($endpoint, $this->client->getEndpoint()); + } + + protected function assertGotenbergFormData(string $name, string $value): void + { + $availableNames = []; + $found = false; + $matches = false; + $expected = null; + + /** @var TextPart|DataPart $part */ + foreach ($this->client->getBody() as $part) { + $availableNames[] = $part->getName(); + + if ($part->getName() !== $name) { + continue; + } + $found = true; + + $expected = trim($part->getBody()); + if (trim($value) === $expected) { + $this->addToAssertionCount(1); + + $matches = true; + } + } + + if (false === $found) { + $this->fail(\sprintf('No matching form data with name "%s". Did you mean one of "%s" ?', $name, implode(', ', $availableNames))); + } + + if (false === $matches) { + $this->fail(\sprintf('No matching form data with name "%s" and value "%s". Expected "%s".', $name, $value, $expected)); + } + } + + protected function assertGotenbergFormDataFile(string $name, string $contentType, string $path): void + { + dd($this->client->getBody()); + foreach ($this->client->getBody() as $part) { + if (!$part instanceof DataPart) { + continue; + } + + $body = \Closure::bind(static fn (DataPart $part) => $part->body, null, TextPart::class)($part); + if ($part->getContentType() === $contentType && $body instanceof File && $body->getPath() === Path::canonicalize($path)) { + $this->addToAssertionCount(1); + + return; + } + } + $this->fail(\sprintf('No matching form data file found with name "%s", content type "%s" and path "%s".', $name, $contentType, $path)); + } + + protected function assertGotenbergHeader(string $name, mixed $value): void + { + foreach ($this->client->getHeaders() as $header) { + if ($header->getName() === $name && $header->getBodyAsString() === $value) { + $this->addToAssertionCount(1); + + return; + } + } + + $this->fail(\sprintf('No matching header found with name "%s" and value "%s".', $name, $value)); + } + + protected function assertGotenbergException(string $message): void + { + $this->assertSame($message, $this->client->getThrowable()->getMessage()); + } + + protected function assertContentFile(string $filename, string $contentType = 'text/html', string|null $expectedContent = null): void + { + foreach ($this->client->getBody() as $part) { + if (!$part instanceof DataPart || $part->getFilename() !== $filename) { + continue; + } + + self::assertSame($contentType, $part->getContentType()); + if (null !== $expectedContent) { + self::assertSame($expectedContent, $part->getBody()); + } + + return; + } + + $this->fail(\sprintf('No matching content file found with name "%s" and content type "%s".', $filename, $contentType)); + } +} diff --git a/tests/Builder/GotenbergClientAsserter.php b/tests/Builder/GotenbergClientAsserter.php new file mode 100644 index 00000000..fce42a7f --- /dev/null +++ b/tests/Builder/GotenbergClientAsserter.php @@ -0,0 +1,96 @@ +|null */ + private array|null $body = null; + private \Throwable|null $throwable = null; + private Payload|null $payload = null; + + public function __construct() + { + $this->httpClient = new MockHttpClient(); + } + + public function call(string $endpoint, Payload $payload): ResponseInterface + { + try { + $this->endpoint = $endpoint; + $this->payload = $payload; + $this->body = $payload->getFormData()->getParts(); + } catch (\Throwable $t) { + $this->throwable = $t; + } + + return $this->httpClient->request('POST', $endpoint); + } + + public function stream(ResponseInterface $response): ResponseStreamInterface + { + return $this->httpClient->stream($response); + } + + public function getEndpoint(): string + { + if ($this->throwable) { + throw new \LogicException('An exception occurred during call.', previous: $this->throwable); + } + + return $this->endpoint ?? throw new \LogicException('No calls done. Did you forget to call the generate method?'); + } + + public function getPayload(): Payload + { + if ($this->throwable) { + throw new \LogicException('An exception occurred during call.', previous: $this->throwable); + } + + return $this->payload ?? throw new \LogicException('No calls done. Did you forget to call the generate method?'); + } + + /** + * @return list + */ + public function getBody(): array + { + if ($this->throwable) { + throw new \LogicException('An exception occurred during call.', previous: $this->throwable); + } + + return $this->body ?? throw new \LogicException('No calls done. Did you forget to call the generate method?'); + } + + /** + * @return iterable + */ + public function getHeaders(): iterable + { + if ($this->throwable) { + throw new \LogicException('An exception occurred during call.', previous: $this->throwable); + } + + return $this->payload?->getHeaders()->all() ?? throw new \LogicException('No calls done. Did you forget to call the generate method?'); + } + + public function getThrowable(): \Throwable + { + if (!$this->endpoint) { + throw new \LogicException('No calls done. Did you forget to call the generate method?'); + } + + return $this->throwable ?? throw new \LogicException('No exceptions thrown.'); + } +} diff --git a/tests/Builder/GotenbergFileResultTest.php b/tests/Builder/GotenbergFileResultTest.php deleted file mode 100644 index 96e3e01b..00000000 --- a/tests/Builder/GotenbergFileResultTest.php +++ /dev/null @@ -1,68 +0,0 @@ - */ - private \Generator $processorGenerator; - - protected function setUp(): void - { - $client = new MockHttpClient(new MockResponse(['a', 'b', 'c'])); - $this->response = new GotenbergResponse( - $client->stream($client->request('GET', '/')), - 200, - new ResponseHeaderBag(), - ); - - $this->processorGenerator = (function () { - $content = ''; - do { - $chunk = yield; - $content .= $chunk->getContent(); - } while (!$chunk->isLast()); - - return $content; - })(); - } - - #[TestDox('Response is processed')] - public function testProcess(): void - { - $result = new GotenbergFileResult($this->response, $this->processorGenerator, 'inline', 'file.pdf'); - $process = $result->process(); - - self::assertSame('abc', $process); - self::assertSame('abc', $this->processorGenerator->getReturn()); - } - - #[TestDox('Response is streamed')] - public function testStream(): void - { - $result = new GotenbergFileResult($this->response, $this->processorGenerator, 'inline', 'file.pdf'); - $stream = $result->stream(); - - ob_start(); - $stream->sendHeaders(); - $stream->sendContent(); - ob_end_clean(); - - self::assertSame('inline; filename=file.pdf', $stream->headers->get('Content-Disposition')); - self::assertSame('no', $stream->headers->get('X-Accel-Buffering')); - self::assertSame('abc', $this->processorGenerator->getReturn()); - } -} diff --git a/tests/Builder/Pdf/AbstractChromiumPdfBuilderTest.php b/tests/Builder/Pdf/AbstractChromiumPdfBuilderTest.php deleted file mode 100644 index 926bfaef..00000000 --- a/tests/Builder/Pdf/AbstractChromiumPdfBuilderTest.php +++ /dev/null @@ -1,472 +0,0 @@ - ['single_page', false, [ - ['singlePage' => 'false'], - ]]; - yield 'pdf_format - A-1b' => ['pdf_format', 'PDF/A-1b', [ - ['pdfa' => 'PDF/A-1b'], - ]]; - yield 'pdf_universal_access' => ['pdf_universal_access', false, [ - ['pdfua' => 'false'], - ]]; - yield 'paper_standard_size' => ['paper_standard_size', 'A4', [ - ['paperWidth' => '8.27in'], - ['paperHeight' => '11.7in'], - ]]; - yield 'paper_width' => ['paper_width', 10.0, [ - ['paperWidth' => '10in'], - ]]; - yield 'paper_height' => ['paper_height', 10.0, [ - ['paperHeight' => '10in'], - ]]; - yield 'margin_top' => ['margin_top', 10.0, [ - ['marginTop' => '10in'], - ]]; - yield 'margin_bottom' => ['margin_bottom', 10.0, [ - ['marginBottom' => '10in'], - ]]; - yield 'margin_left' => ['margin_left', 10.0, [ - ['marginLeft' => '10in'], - ]]; - yield 'margin_right' => ['margin_right', 10.0, [ - ['marginRight' => '10in'], - ]]; - yield 'prefer_css_page_size' => ['prefer_css_page_size', false, [ - ['preferCssPageSize' => 'false'], - ]]; - yield 'generate_document_outline' => ['generate_document_outline', false, [ - ['generateDocumentOutline' => 'false'], - ]]; - yield 'print_background' => ['print_background', false, [ - ['printBackground' => 'false'], - ]]; - yield 'omit_background' => ['omit_background', false, [ - ['omitBackground' => 'false'], - ]]; - yield 'landscape' => ['landscape', false, [ - ['landscape' => 'false'], - ]]; - yield 'scale' => ['scale', 2.0, [ - ['scale' => '2.0'], - ]]; - yield 'native_page_ranges' => ['native_page_ranges', '1-10', [ - ['nativePageRanges' => '1-10'], - ]]; - yield 'wait_delay' => ['wait_delay', '3ms', [ - ['waitDelay' => '3ms'], - ]]; - yield 'wait_for_expression' => ['wait_for_expression', "window.status === 'ready'", [ - ['waitForExpression' => "window.status === 'ready'"], - ]]; - yield 'emulated_media_type' => ['emulated_media_type', 'screen', [ - ['emulatedMediaType' => 'screen'], - ]]; - yield 'cookies' => ['cookies', [['name' => 'MyCookie', 'value' => 'raspberry']], [ - ['cookies' => '[{"name":"MyCookie","value":"raspberry"}]'], - ]]; - yield 'user_agent' => ['user_agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)', [ - ['userAgent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)'], - ]]; - yield 'extra_http_headers' => ['extra_http_headers', ['MyHeader' => 'SomeValue'], [ - ['extraHttpHeaders' => '{"MyHeader":"SomeValue"}'], - ]]; - yield 'fail_on_http_status_codes' => ['fail_on_http_status_codes', [499, 500], [ - ['failOnHttpStatusCodes' => '[499,500]'], - ]]; - yield 'fail_on_resource_http_status_codes' => ['fail_on_resource_http_status_codes', [499, 500], [ - ['failOnResourceHttpStatusCodes' => '[499,500]'], - ]]; - yield 'fail_on_resource_loading_failed' => ['fail_on_resource_loading_failed', false, [ - ['failOnResourceLoadingFailed' => 'false'], - ]]; - yield 'fail_on_console_exceptions' => ['fail_on_console_exceptions', false, [ - ['failOnConsoleExceptions' => 'false'], - ]]; - yield 'skip_network_idle_event' => ['skip_network_idle_event', false, [ - ['skipNetworkIdleEvent' => 'false'], - ]]; - yield 'metadata' => ['metadata', ['Author' => 'SensioLabs'], [ - ['metadata' => '{"Author":"SensioLabs"}'], - ]]; - } - - /** - * @param array $expected - */ - #[DataProvider('configurationIsCorrectlySetProvider')] - #[TestDox('Configuration "$_dataName" is correctly set')] - public function testConfigurationIsCorrectlySet(string $key, mixed $value, array $expected): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->setConfigurations([ - $key => $value, - ]); - - self::assertEquals($expected, $builder->getMultipartFormData()); - } - - public function testConfigurationNotFoundThrowError(): void - { - $builder = $this->getChromiumPdfBuilder(); - - $this->expectException(InvalidBuilderConfiguration::class); - - $builder->setConfigurations([ - 'fake' => 'value', - ]); - } - - public function testPaperSizeAppliesWidthAndHeight(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->paperSize(10.0, 50.5, Unit::Centimeters); - - self::assertEquals([ - ['paperWidth' => '10cm'], - ['paperHeight' => '50.5cm'], - ], $builder->getMultipartFormData()); - } - - public function testPaperStandardSizeAppliesCorrectly(): void - { - $paperStandardSize = new class implements PaperSizeInterface { - public function width(): float - { - return 10.0; - } - - public function height(): float - { - return 50.5; - } - - public function unit(): Unit - { - return Unit::Pixels; - } - }; - - $builder = $this->getChromiumPdfBuilder(); - $builder->paperStandardSize($paperStandardSize); - - self::assertEquals([ - ['paperWidth' => '10px'], - ['paperHeight' => '50.5px'], - ], $builder->getMultipartFormData()); - } - - public function testMarginsAppliesCorrectly(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->margins(1.1, 2.2, 3.3, 4.4, Unit::Picas); - - self::assertEquals([ - ['marginTop' => '1.1pc'], - ['marginBottom' => '2.2pc'], - ['marginLeft' => '3.3pc'], - ['marginRight' => '4.4pc'], - ], $builder->getMultipartFormData()); - } - - public function testPdfFormatCanBeReset(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->pdfFormat(PdfFormat::Pdf1b); - - self::assertEquals([ - ['pdfa' => 'PDF/A-1b'], - ], $builder->getMultipartFormData()); - - $builder->pdfFormat(null); - - self::assertEquals([], $builder->getMultipartFormData()); - } - - public function testTwigHeaderIsCorrectlyRendered(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->header('templates/header.html.twig', ['name' => 'World']); - - $data = $builder->getMultipartFormData()[0]; - - $expected = << - - - - My Header - - -

Hello World!

- - - - HTML; - - self::assertFile($data, 'header.html', expectedContent: $expected); - } - - public function testTwigFooterIsCorrectlyRendered(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->footer('templates/footer.html.twig', ['name' => 'World']); - - $data = $builder->getMultipartFormData()[0]; - - $expected = << - - - - My Footer - - -

Hello World!

- - - - HTML; - - self::assertFile($data, 'footer.html', expectedContent: $expected); - } - - public function testPlainFileHeaderIsCorrectlyRendered(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->headerFile('files/header.html'); - - $data = $builder->getMultipartFormData()[0]; - - $expected = << - - - - My Header - - -

Hello Header

- - - - HTML; - - self::assertFile($data, 'header.html', expectedContent: $expected); - } - - public function testPlainFileFooterIsCorrectlyRendered(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->footerFile('files/footer.html'); - - $data = $builder->getMultipartFormData()[0]; - - $expected = << - - - - My Footer - - -

Hello Footer

- - - - HTML; - - self::assertFile($data, 'footer.html', expectedContent: $expected); - } - - public function testAssetsCanBeAddedUsingPhp(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->assets( - self::FIXTURE_DIR.'/assets/logo.png', - self::FIXTURE_DIR.'/assets/logo.png', - self::FIXTURE_DIR.'/assets/other_logo.png', - ); - - $data = $builder->getMultipartFormData(); - - self::assertCount(2, $data); - - $logo = $data[0]; - self::assertFile($logo, 'logo.png', 'image/png'); - - $otherLogo = $data[1]; - self::assertFile($otherLogo, 'other_logo.png', 'image/png'); - } - - public function testAssetsCanBeAddedUsingTwig(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->header('templates/header_with_asset.html.twig', ['name' => 'World']); - - $data = $builder->getMultipartFormData(); - - self::assertCount(2, $data); - - $logo = $data[0]; - self::assertFile($logo, 'logo.png', 'image/png'); - } - - public function testCanAddCookies(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->addCookies([ - [ - 'name' => 'MyCookie', - 'value' => 'Chocolate', - 'domain' => 'sensiolabs.com', - ], - [ - 'name' => 'MyCookie', - 'value' => 'Vanilla', - 'domain' => 'sensiolabs.com', - ], - ]); - - $data = $builder->getMultipartFormData(); - - self::assertEquals([ - 'cookies' => '[{"name":"MyCookie","value":"Vanilla","domain":"sensiolabs.com"}]', - ], $data[0]); - } - - public function testCanForwardCookies(): void - { - $request = new Request(); - $request->headers->set('Host', 'sensiolabs.com'); - $request->cookies->set('MyCookie', 'Chocolate'); - - $requestStack = new RequestStack(); - $requestStack->push($request); - - $builder = $this->getChromiumPdfBuilder(requestStack: $requestStack); - $builder->forwardCookie('MyCookie'); - - $data = $builder->getMultipartFormData(); - - self::assertEquals([ - 'cookies' => '[{"name":"MyCookie","value":"Chocolate","domain":"sensiolabs.com"}]', - ], $data[0]); - } - - public function testCanAddExtraHttpHeaders(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->addExtraHttpHeaders([ - 'MyHeader' => 'SomeValue', - ]); - $builder->addExtraHttpHeaders([ - 'MyHeader' => 'SomeOtherValue', - ]); - - $data = $builder->getMultipartFormData(); - - self::assertEquals([ - 'extraHttpHeaders' => '{"MyHeader":"SomeOtherValue"}', - ], $data[0]); - } - - public function testAddExtraHttpHeadersDoesNothingIfEmpty(): void - { - $builder = $this->getChromiumPdfBuilder(); - - $data = $builder->getMultipartFormData(); - $dataCount = \count($data); - - $builder->addExtraHttpHeaders([]); - self::assertCount(max($dataCount - 1, 0), $builder->getMultipartFormData()); - } - - public function testCanResetExtraHttpHeaders(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->addExtraHttpHeaders([ - 'MyHeader' => 'SomeValue', - ]); - - $data = $builder->getMultipartFormData(); - - $dataCount = \count($data); - - $builder->extraHttpHeaders([]); - - $data = $builder->getMultipartFormData(); - self::assertCount($dataCount - 1, $data); - } - - public function testCanAddMetadata(): void - { - $builder = $this->getChromiumPdfBuilder(); - $builder->addMetadata('Author', 'Me'); - $builder->addMetadata('Author', 'SensioLabs'); - - $data = $builder->getMultipartFormData(); - - self::assertEquals([ - 'metadata' => '{"Author":"SensioLabs"}', - ], $data[0]); - } - - public function testThrowIfTwigNotAvailable(): void - { - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Twig is required to use "Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractChromiumPdfBuilder::withRenderedPart" method. Try to run "composer require symfony/twig-bundle".'); - - $builder = $this->getChromiumPdfBuilder(false); - $builder->header('header.html.twig', ['name' => 'World']); - } - - public function testThrowIfTwigTemplateIsInvalid(): void - { - $this->expectException(PdfPartRenderingException::class); - $this->expectExceptionMessage('Could not render template "templates/invalid.html.twig" into PDF part "header.html". Unexpected character "!".'); - - $builder = $this->getChromiumPdfBuilder(); - $builder->header('templates/invalid.html.twig'); - } - - private function getChromiumPdfBuilder(bool $twig = true, RequestStack $requestStack = new RequestStack()): AbstractChromiumPdfBuilder - { - return new class($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry, $requestStack, true === $twig ? self::$twig : null) extends AbstractChromiumPdfBuilder { - protected function getEndpoint(): string - { - return '/fake/endpoint'; - } - }; - } -} diff --git a/tests/Builder/Pdf/AbstractPdfBuilderTest.php b/tests/Builder/Pdf/AbstractPdfBuilderTest.php deleted file mode 100644 index d9a63641..00000000 --- a/tests/Builder/Pdf/AbstractPdfBuilderTest.php +++ /dev/null @@ -1,103 +0,0 @@ -gotenbergClient = new GotenbergClient(new MockHttpClient([ - new MockResponse(), - ])); - - $response = $this->getPdfBuilder() - ->fileName('some_file.png', HeaderUtils::DISPOSITION_ATTACHMENT) - ->generate() - ->stream() - ; - - self::assertSame('attachment; filename=some_file.png', $response->headers->get('Content-Disposition')); - } - - public static function nativeNormalizersProvider(): \Generator - { - yield 'boolean (true)' => ['boolean', true, 'true']; - yield 'boolean (false)' => ['boolean', false, 'false']; - - yield 'int' => ['int', 12, '12']; - yield 'float (.0)' => ['float', 12.0, '12.0']; - yield 'float (.5)' => ['float', 12.5, '12.5']; - } - - #[DataProvider('nativeNormalizersProvider')] - #[TestDox('Native "$_dataName" is correctly normalized')] - public function testNativeNormalizers(string $key, mixed $raw, mixed $expected): void - { - $builder = $this->getPdfBuilder([$key => $raw]); - $data = $builder->getMultipartFormData()[0]; - - self::assertArrayHasKey($key, $data); - self::assertSame($expected, $data[$key]); - } - - /** - * @param array{ - * 'extraHttpHeaders'?: array, - * 'assets'?: array, - * 'header.html'?: DataPart, - * 'footer.html'?: DataPart, - * 'index.html'?: DataPart, - * 'failOnHttpStatusCodes'?: list, - * 'cookies'?: list, - * 'metadata'?: array - * } $formFields - */ - private function getPdfBuilder(array $formFields = []): AbstractPdfBuilder - { - return (new class($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry, $formFields) extends AbstractPdfBuilder { - /** - * @param array $formFields - */ - public function __construct(GotenbergClientInterface $gotenbergClient, AssetBaseDirFormatter $asset, WebhookConfigurationRegistryInterface $webhookConfigurationRegistry, array $formFields = []) - { - parent::__construct($gotenbergClient, $asset, $webhookConfigurationRegistry); - $this->formFields = $formFields; - } - - public function setConfigurations(array $configurations): static - { - return $this; - } - - protected function getEndpoint(): string - { - return '/fake/endpoint'; - } - }) - ->processor(new NullProcessor()) - ; - } -} diff --git a/tests/Builder/Pdf/ConvertPdfBuilderTest.php b/tests/Builder/Pdf/ConvertPdfBuilderTest.php index e0f48a3e..ba67365b 100644 --- a/tests/Builder/Pdf/ConvertPdfBuilderTest.php +++ b/tests/Builder/Pdf/ConvertPdfBuilderTest.php @@ -2,141 +2,107 @@ namespace Sensiolabs\GotenbergBundle\Tests\Builder\Pdf; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder; +use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; +use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\Processor\NullProcessor; -use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; -use Symfony\Component\Mime\Part\DataPart; - -#[CoversClass(ConvertPdfBuilder::class)] -#[UsesClass(AbstractPdfBuilder::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(GotenbergFileResult::class)] -final class ConvertPdfBuilderTest extends AbstractBuilderTestCase +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\DownloadFromTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\PdfFormatTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\WebhookTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; +use Symfony\Component\DependencyInjection\Container; + +/** + * @extends GotenbergBuilderTestCase + */ +final class ConvertPdfBuilderTest extends GotenbergBuilderTestCase { - private const PDF_DOCUMENTS_DIR = 'assets/pdf'; + /** @use DownloadFromTestCaseTrait */ + use DownloadFromTestCaseTrait; - public function testEndpointIsCorrect(): void - { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/pdfengines/convert'), - $this->anything(), - $this->anything(), - ) - ; + /** @use PdfFormatTestCaseTrait */ + use PdfFormatTestCaseTrait; - $this->getConvertPdfBuilder() - ->files(self::PDF_DOCUMENTS_DIR.'/document.pdf') - ->pdfUniversalAccess() - ->generate() - ; - } + /** @use WebhookTestCaseTrait */ + use WebhookTestCaseTrait; - public static function configurationIsCorrectlySetProvider(): \Generator + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): ConvertPdfBuilder { - yield 'pdf_format' => ['pdf_format', 'PDF/A-1b', [ - 'pdfa' => 'PDF/A-1b', - ]]; - yield 'pdf_universal_access' => ['pdf_universal_access', false, [ - 'pdfua' => 'false', - ]]; + return new ConvertPdfBuilder($client, $dependencies); } /** - * @param array $expected + * @param ConvertPdfBuilder $builder */ - #[DataProvider('configurationIsCorrectlySetProvider')] - public function testConfigurationIsCorrectlySet(string $key, mixed $value, array $expected): void + protected function initializeBuilder(BuilderInterface $builder, Container $container): ConvertPdfBuilder { - $builder = $this->getConvertPdfBuilder(); - $builder->setConfigurations([ - $key => $value, - ]); - $builder->files(self::PDF_DOCUMENTS_DIR.'/document.pdf'); - - self::assertEquals($expected, $builder->getMultipartFormData()[0]); + return $builder + ->files('pdf/simple_pdf.pdf') + ->pdfUniversalAccess() + ; } - public function testRequiredFormat(): void + public function testAddFilesAsContent(): void { - $builder = $this->getConvertPdfBuilder(); - $builder - ->files(self::PDF_DOCUMENTS_DIR.'/document.pdf') + $this->getBuilder() + ->files('pdf/simple_pdf.pdf') + ->pdfUniversalAccess() + ->generate() ; - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('At least "pdfa" or "pdfua" must be provided.'); - - $builder->getMultipartFormData(); + $this->assertGotenbergEndpoint('/forms/pdfengines/convert'); + $this->assertGotenbergFormDataFile('files', 'application/pdf', self::FIXTURE_DIR.'/pdf/simple_pdf.pdf'); } public function testWithStringableObject(): void { - $stringable = new class(self::PDF_DOCUMENTS_DIR) implements \Stringable { - public function __construct(private string $directory) - { - } - + $class = new class implements \Stringable { public function __toString(): string { - return $this->directory.'/document.pdf'; + return 'pdf/simple_pdf.pdf'; } }; - $builder = $this->getConvertPdfBuilder(); - $builder - ->files($stringable) + $this->getBuilder() + ->files($class) ->pdfUniversalAccess() + ->generate() ; - $data = $builder->getMultipartFormData(); - - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $dataPart = $data[0]['files']); - self::assertSame(basename((string) $stringable), $dataPart->getFilename()); + $this->assertGotenbergEndpoint('/forms/pdfengines/convert'); + $this->assertGotenbergFormDataFile('files', 'application/pdf', self::FIXTURE_DIR.'/pdf/simple_pdf.pdf'); } - public function testSplFileInfoObject(): void + public function testRequiredConfiguration(): void { - $splFileInfo = new \SplFileInfo(self::PDF_DOCUMENTS_DIR.'/document.pdf'); + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('At least "pdfa" or "pdfua" must be provided.'); - $builder = $this->getConvertPdfBuilder(); - $builder - ->files($splFileInfo) - ->pdfUniversalAccess() + $this->getBuilder() + ->generate() ; - - $data = $builder->getMultipartFormData(); - - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $dataPart = $data[0]['files']); - self::assertSame(basename((string) $splFileInfo), $dataPart->getFilename()); } - public function testRequiredPdfFile(): void + public function testRequiredFileContent(): void { - $builder = $this->getConvertPdfBuilder(); - $builder->pdfUniversalAccess(); - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('At least one PDF file is required'); + $this->expectExceptionMessage('At least one PDF file is required.'); - $builder->getMultipartFormData(); + $this->getBuilder() + ->pdfUniversalAccess() + ->generate() + ; } - private function getConvertPdfBuilder(): ConvertPdfBuilder + public function testFilesExtensionRequirement(): void { - return (new ConvertPdfBuilder($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry)) - ->processor(new NullProcessor()) + $this->expectException(InvalidBuilderConfiguration::class); + $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); + + $this->getBuilder() + ->files('b.png') + ->generate() ; } } diff --git a/tests/Builder/Pdf/FlattenPdfBuilderTest.php b/tests/Builder/Pdf/FlattenPdfBuilderTest.php new file mode 100644 index 00000000..1c04dd91 --- /dev/null +++ b/tests/Builder/Pdf/FlattenPdfBuilderTest.php @@ -0,0 +1,72 @@ + + */ +final class FlattenPdfBuilderTest extends GotenbergBuilderTestCase +{ + /** @use DownloadFromTestCaseTrait */ + use DownloadFromTestCaseTrait; + + /** @use WebhookTestCaseTrait */ + use WebhookTestCaseTrait; + + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): FlattenPdfBuilder + { + return new FlattenPdfBuilder($client, $dependencies); + } + + /** + * @param FlattenPdfBuilder $builder + */ + protected function initializeBuilder(BuilderInterface $builder, Container $container): FlattenPdfBuilder + { + return $builder + ->files('pdf/simple_pdf.pdf') + ; + } + + public function testAddFilesAsContent(): void + { + $this->getBuilder() + ->files('pdf/simple_pdf.pdf') + ->generate() + ; + + $this->assertGotenbergEndpoint('/forms/pdfengines/flatten'); + $this->assertGotenbergFormDataFile('files', 'application/pdf', self::FIXTURE_DIR.'/pdf/simple_pdf.pdf'); + } + + public function testFilesExtensionRequirement(): void + { + $this->expectException(InvalidBuilderConfiguration::class); + $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); + + $this->getBuilder() + ->files('b.png') + ->generate() + ; + } + + public function testRequiredFileContent(): void + { + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('At least one PDF file is required.'); + + $this->getBuilder() + ->generate() + ; + } +} diff --git a/tests/Builder/Pdf/HtmlPdfBuilderTest.php b/tests/Builder/Pdf/HtmlPdfBuilderTest.php index 9d801824..4cdbac2e 100644 --- a/tests/Builder/Pdf/HtmlPdfBuilderTest.php +++ b/tests/Builder/Pdf/HtmlPdfBuilderTest.php @@ -2,59 +2,107 @@ namespace Sensiolabs\GotenbergBundle\Tests\Builder\Pdf; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractChromiumPdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; +use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; +use Sensiolabs\GotenbergBundle\Exception\PdfPartRenderingException; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\Processor\NullProcessor; -use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; -use Sensiolabs\GotenbergBundle\Twig\GotenbergExtension; -use Symfony\Component\HttpFoundation\RequestStack; - -#[CoversClass(HtmlPdfBuilder::class)] -#[UsesClass(AbstractChromiumPdfBuilder::class)] -#[UsesClass(AbstractPdfBuilder::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(GotenbergExtension::class)] -#[UsesClass(GotenbergFileResult::class)] -final class HtmlPdfBuilderTest extends AbstractBuilderTestCase +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\ChromiumPdfTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; +use Sensiolabs\GotenbergBundle\Twig\GotenbergRuntime; +use Symfony\Component\DependencyInjection\Container; +use Twig\Environment; +use Twig\Loader\FilesystemLoader; +use Twig\RuntimeLoader\RuntimeLoaderInterface; + +/** + * @extends GotenbergBuilderTestCase + */ +final class HtmlPdfBuilderTest extends GotenbergBuilderTestCase { - public function testEndpointIsCorrect(): void + /** @use ChromiumPdfTestCaseTrait */ + use ChromiumPdfTestCaseTrait; + + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): HtmlPdfBuilder + { + return new HtmlPdfBuilder($client, $dependencies); + } + + /** + * @param HtmlPdfBuilder $builder + */ + protected function initializeBuilder(BuilderInterface $builder, Container $container): HtmlPdfBuilder + { + return $builder + ->contentFile('files/content.html') + ; + } + + public function testRequiredFormData(): void { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/chromium/convert/html'), - $this->anything(), - $this->anything(), - ) + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('Content is required'); + + $this->getBuilder() + ->generate() ; + } - $this->getHtmlPdfBuilder() + public function testOutputFilename(): void + { + $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + + $this->getBuilder() ->contentFile('files/content.html') + ->filename('test') ->generate() ; + + $this->assertGotenbergEndpoint('/forms/chromium/convert/html'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'test'); } - public static function withPlainContentFileProvider(): \Generator + public function testWidth(): void { - yield 'with twig' => [true]; - yield 'without twig' => [false]; + $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + + $this->getBuilder() + ->contentFile('files/content.html') + ->filename('test') + ->paperWidth(200) + ->paperHeight(150) + ->generate() + ; + + $this->assertGotenbergFormData('paperWidth', '200in'); + $this->assertGotenbergFormData('paperHeight', '150in'); + + $this->assertGotenbergEndpoint('/forms/chromium/convert/html'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'test'); } - #[DataProvider('withPlainContentFileProvider')] - public function testWithPlainContentFile(bool $withTwig): void + public function testWithTwigContentFile(): void { - $builder = $this->getHtmlPdfBuilder($withTwig); - $builder->contentFile('files/content.html'); + $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); - $data = $builder->getMultipartFormData()[0]; + $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ + 'strict_variables' => true, + ]); + + $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { + public function load(string $class): object|null + { + return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + } + }); + + $this->dependencies->set('twig', $twig); + + $this->getBuilder() + ->content('templates/content.html.twig', ['name' => 'world']) + ->generate() + ; $expected = << @@ -71,17 +119,48 @@ public function testWithPlainContentFile(bool $withTwig): void HTML; - self::assertFile($data, 'index.html', expectedContent: $expected); + $this->assertContentFile('index.html', 'text/html', $expected); } - public function testWithTwigContentFile(): void + public function testWithTwigAndHeaderFooterParts(): void { - $builder = $this->getHtmlPdfBuilder(); - $builder->content('templates/content.html.twig', ['name' => 'world']); + $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); - $data = $builder->getMultipartFormData()[0]; + $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ + 'strict_variables' => true, + ]); - $expected = <<addRuntimeLoader(new class implements RuntimeLoaderInterface { + public function load(string $class): object|null + { + return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + } + }); + + $this->dependencies->set('twig', $twig); + + $this->getBuilder() + ->header('templates/header.html.twig', ['name' => 'header']) + ->content('templates/content.html.twig', ['name' => 'world']) + ->footer('templates/footer.html.twig', ['name' => 'footer']) + ->generate() + ; + + $expectedHeader = << + + + + My Header + + +

Hello header!

+ + + + HTML; + + $expectedContent = << @@ -96,23 +175,79 @@ public function testWithTwigContentFile(): void HTML; - self::assertFile($data, 'index.html', expectedContent: $expected); + $expectedFooter = << + + + + My Footer + + +

Hello footer!

+ + + + HTML; + + $this->assertContentFile('header.html', 'text/html', $expectedHeader); + $this->assertContentFile('index.html', 'text/html', $expectedContent); + $this->assertContentFile('footer.html', 'text/html', $expectedFooter); } - public function testRequiredFormData(): void + public function testFilesAsHeaderAndFooter(): void { - $builder = $this->getHtmlPdfBuilder(); + $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('Content is required'); + $this->getBuilder() + ->headerFile('files/header.html') + ->contentFile('files/content.html') + ->footerFile('files/footer.html') + ->filename('test') + ->generate() + ; + + $this->assertGotenbergEndpoint('/forms/chromium/convert/html'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'test'); - $builder->getMultipartFormData(); + $this->assertContentFile('header.html'); + $this->assertContentFile('index.html'); + $this->assertContentFile('footer.html'); } - private function getHtmlPdfBuilder(bool $twig = true): HtmlPdfBuilder + public function testWithInvalidTwigTemplate(): void { - return (new HtmlPdfBuilder($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry, new RequestStack(), true === $twig ? self::$twig : null)) - ->processor(new NullProcessor()) + $this->expectException(PdfPartRenderingException::class); + $this->expectExceptionMessage('Could not render template "templates/invalid.html.twig" into PDF part "index.html". Unexpected character "!".'); + + $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + + $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ + 'strict_variables' => true, + ]); + + $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { + public function load(string $class): object|null + { + return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + } + }); + + $this->dependencies->set('twig', $twig); + + $this->getBuilder() + ->content('templates/invalid.html.twig', ['name' => 'world']) + ->generate() + ; + } + + public function testTwigDependencyRequirement(): void + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Twig is required to use "Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies\TwigAwareTrait::getTwig" method. Try to run "composer require symfony/twig-bundle".'); + + $this->getBuilder() + ->content('templates/content.html.twig', ['name' => 'world']) + ->generate() ; } } diff --git a/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php b/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php index 918bbf06..99e8ba4b 100644 --- a/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php +++ b/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php @@ -2,218 +2,99 @@ namespace Sensiolabs\GotenbergBundle\Tests\Builder\Pdf; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder; +use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; +use Sensiolabs\GotenbergBundle\Enumeration\SplitMode; +use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\Processor\NullProcessor; -use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; -use Symfony\Component\Mime\Part\DataPart; - -#[CoversClass(LibreOfficePdfBuilder::class)] -#[UsesClass(AbstractPdfBuilder::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(GotenbergFileResult::class)] -final class LibreOfficePdfBuilderTest extends AbstractBuilderTestCase +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\LibreOfficeTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; +use Symfony\Component\DependencyInjection\Container; + +/** + * @extends GotenbergBuilderTestCase + */ +class LibreOfficePdfBuilderTest extends GotenbergBuilderTestCase { - private const OFFICE_DOCUMENTS_DIR = 'assets/office'; + /** @use LibreOfficeTestCaseTrait */ + use LibreOfficeTestCaseTrait; - public function testEndpointIsCorrect(): void + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): LibreOfficePdfBuilder { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/libreoffice/convert'), - $this->anything(), - $this->anything(), - ) - ; - - $this->getLibreOfficePdfBuilder() - ->files(new \SplFileInfo(self::OFFICE_DOCUMENTS_DIR.'/document_1.docx')) - ->generate() - ; + return new LibreOfficePdfBuilder($client, $dependencies); } - public function testStringableObject(): void - { - $supportedFilePath = new class(self::OFFICE_DOCUMENTS_DIR) implements \Stringable { - public function __construct(private readonly string $directory) - { - } - - public function __toString(): string - { - return $this->directory.'/document_1.docx'; - } - }; - - $builder = $this->getLibreOfficePdfBuilder(); - $builder - ->files($supportedFilePath) - ->pdfUniversalAccess() - ; - - $data = $builder->getMultipartFormData(); - - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $dataPart = $data[0]['files']); - self::assertSame(basename((string) $supportedFilePath), $dataPart->getFilename()); - } - - public function testSplFileInfoObject(): void + /** + * @param LibreOfficePdfBuilder $builder + */ + protected function initializeBuilder(BuilderInterface $builder, Container $container): LibreOfficePdfBuilder { - $supportedFilePath = new \SplFileInfo(self::OFFICE_DOCUMENTS_DIR.'/document_1.docx'); - - $builder = $this->getLibreOfficePdfBuilder(); - $builder - ->files($supportedFilePath) - ->pdfUniversalAccess() + return $builder + ->files('assets/office/document.odt') ; - - $data = $builder->getMultipartFormData(); - - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $dataPart = $data[0]['files']); - self::assertSame(basename((string) $supportedFilePath), $dataPart->getFilename()); } - public static function configurationIsCorrectlySetProvider(): \Generator + public static function provideValidOfficeFiles(): \Generator { - yield 'pdf_format' => ['pdf_format', 'PDF/A-1b', [ - 'pdfa' => 'PDF/A-1b', - ]]; - yield 'pdf_universal_access' => ['pdf_universal_access', false, [ - 'pdfua' => 'false', - ]]; - yield 'landscape' => ['landscape', false, [ - 'landscape' => 'false', - ]]; - yield 'native_page_ranges' => ['native_page_ranges', '1-10', [ - 'nativePageRanges' => '1-10', - ]]; - yield 'do_not_export_form_fields' => ['do_not_export_form_fields', true, [ - 'exportFormFields' => 'true', - ]]; - yield 'single_page_sheets' => ['single_page_sheets', false, [ - 'singlePageSheets' => 'false', - ]]; - yield 'merge' => ['merge', false, [ - 'merge' => 'false', - ]]; - yield 'metadata' => ['metadata', ['Author' => 'SensioLabs'], [ - 'metadata' => '{"Author":"SensioLabs"}', - ]]; - yield 'allow_duplicate_field_names' => ['allow_duplicate_field_names', false, [ - 'allowDuplicateFieldNames' => 'false', - ]]; - yield 'do_not_export_bookmarks' => ['do_not_export_bookmarks', true, [ - 'exportBookmarks' => 'true', - ]]; - yield 'export_bookmarks_to_pdf_destination' => ['export_bookmarks_to_pdf_destination', false, [ - 'exportBookmarksToPdfDestination' => 'false', - ]]; - yield 'export_placeholders' => ['export_placeholders', false, [ - 'exportPlaceholders' => 'false', - ]]; - yield 'export_notes' => ['export_notes', false, [ - 'exportNotes' => 'false', - ]]; - yield 'export_notes_pages' => ['export_notes_pages', false, [ - 'exportNotesPages' => 'false', - ]]; - yield 'export_only_notes_pages' => ['export_only_notes_pages', false, [ - 'exportOnlyNotesPages' => 'false', - ]]; - yield 'export_notes_in_margin' => ['export_notes_in_margin', false, [ - 'exportNotesInMargin' => 'false', - ]]; - yield 'convert_ooo_target_to_pdf_target' => ['convert_ooo_target_to_pdf_target', false, [ - 'convertOooTargetToPdfTarget' => 'false', - ]]; - yield 'export_links_relative_fsys' => ['export_links_relative_fsys', false, [ - 'exportLinksRelativeFsys' => 'false', - ]]; - yield 'export_hidden_slides' => ['export_hidden_slides', false, [ - 'exportHiddenSlides' => 'false', - ]]; - yield 'skip_empty_pages' => ['skip_empty_pages', false, [ - 'skipEmptyPages' => 'false', - ]]; - yield 'add_original_document_as_stream' => ['add_original_document_as_stream', false, [ - 'addOriginalDocumentAsStream' => 'false', - ]]; - yield 'lossless_image_compression' => ['lossless_image_compression', false, [ - 'losslessImageCompression' => 'false', - ]]; - yield 'quality' => ['quality', 90, [ - 'quality' => 90, - ]]; - yield 'reduce_image_resolution' => ['reduce_image_resolution', false, [ - 'reduceImageResolution' => 'false', - ]]; - yield 'max_image_resolution' => ['max_image_resolution', 300, [ - 'maxImageResolution' => 300, - ]]; - yield 'password' => ['password', 'My password', [ - 'password' => 'My password', - ]]; + yield 'odt' => ['assets/office/document.odt', 'application/vnd.oasis.opendocument.text']; + yield 'docx' => ['assets/office/document_1.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']; + yield 'html' => ['assets/office/document_2.html', 'text/html']; + yield 'xslx' => ['assets/office/document_3.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']; + yield 'pptx' => ['assets/office/document_4.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation']; } - /** - * @param array $expected - */ - #[DataProvider('configurationIsCorrectlySetProvider')] - public function testConfigurationIsCorrectlySet(string $key, mixed $value, array $expected): void + #[DataProvider('provideValidOfficeFiles')] + public function testOfficeFiles(string $filePath, string $contentType): void { - $builder = $this->getLibreOfficePdfBuilder(); - $builder->setConfigurations([ - $key => $value, - ]); - $builder->files(self::OFFICE_DOCUMENTS_DIR.'/document_1.docx'); - - self::assertEquals($expected, $builder->getMultipartFormData()[0]); - } + $this->getBuilder() + ->files($filePath) + ->generate() + ; - public static function provideValidOfficeFiles(): \Generator - { - yield 'odt' => [self::OFFICE_DOCUMENTS_DIR.'/document.odt', 'application/vnd.oasis.opendocument.text', 'document.odt']; - yield 'docx' => [self::OFFICE_DOCUMENTS_DIR.'/document_1.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'document_1.docx']; - yield 'html' => [self::OFFICE_DOCUMENTS_DIR.'/document_2.html', 'text/html', 'document_2.html']; - yield 'xslx' => [self::OFFICE_DOCUMENTS_DIR.'/document_3.xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'document_3.xlsx']; - yield 'pptx' => [self::OFFICE_DOCUMENTS_DIR.'/document_4.pptx', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'document_4.pptx']; + $this->assertGotenbergEndpoint('/forms/libreoffice/convert'); + $this->assertGotenbergFormDataFile('files', $contentType, self::FIXTURE_DIR.'/'.$filePath); } - #[DataProvider('provideValidOfficeFiles')] - public function testOfficeFiles(string $filePath, string $contentType, string $filename): void + public function testWithStringableObject(): void { - $builder = $this->getLibreOfficePdfBuilder(); - $builder->files($filePath); + $class = new class implements \Stringable { + public function __toString(): string + { + return 'assets/office/document.odt'; + } + }; - $data = $builder->getMultipartFormData()[0]; + $this->getBuilder() + ->files($class) + ->generate() + ; - self::assertFile($data, $filename, $contentType); + $this->assertGotenbergEndpoint('/forms/libreoffice/convert'); + $this->assertGotenbergFormDataFile('files', 'application/vnd.oasis.opendocument.text', self::FIXTURE_DIR.'/assets/office/document.odt'); } - public function testRequiredFormData(): void + public function testRequiredFileContent(): void { - $builder = $this->getLibreOfficePdfBuilder(); - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('At least one office file is required'); + $this->expectExceptionMessage('At least one office file is required.'); - $builder->getMultipartFormData(); + $this->getBuilder() + ->generate() + ; } - private function getLibreOfficePdfBuilder(): LibreOfficePdfBuilder + public function testSplitConfigurationRequirement(): void { - return (new LibreOfficePdfBuilder($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry)) - ->processor(new NullProcessor()) + $this->expectException(InvalidBuilderConfiguration::class); + $this->expectExceptionMessage('"splitUnify" can only be at "true" with "pages" mode for "splitMode".'); + + $this->getBuilder() + ->files('assets/office/document.odt') + ->splitMode(SplitMode::Intervals) + ->splitUnify() + ->generate() ; } } diff --git a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php index 668fddef..b7d9b9db 100644 --- a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php +++ b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php @@ -2,74 +2,148 @@ namespace Sensiolabs\GotenbergBundle\Tests\Builder\Pdf; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractChromiumPdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder; +use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; +use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\Processor\NullProcessor; -use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; -use Symfony\Component\HttpFoundation\RequestStack; - -#[CoversClass(MarkdownPdfBuilder::class)] -#[UsesClass(AbstractChromiumPdfBuilder::class)] -#[UsesClass(AbstractPdfBuilder::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(GotenbergFileResult::class)] -final class MarkdownPdfBuilderTest extends AbstractBuilderTestCase +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\ChromiumPdfTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; +use Sensiolabs\GotenbergBundle\Twig\GotenbergRuntime; +use Symfony\Component\DependencyInjection\Container; +use Twig\Environment; +use Twig\Loader\FilesystemLoader; +use Twig\RuntimeLoader\RuntimeLoaderInterface; + +/** + * @extends GotenbergBuilderTestCase + */ +final class MarkdownPdfBuilderTest extends GotenbergBuilderTestCase { - public function testEndpointIsCorrect(): void + /** @use ChromiumPdfTestCaseTrait */ + use ChromiumPdfTestCaseTrait; + + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): MarkdownPdfBuilder { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/chromium/convert/markdown'), - $this->anything(), - $this->anything(), - ) - ; + return new MarkdownPdfBuilder($client, $dependencies); + } - $this->getMarkdownPdfBuilder() + /** + * @param MarkdownPdfBuilder $builder + */ + protected function initializeBuilder(BuilderInterface $builder, Container $container): MarkdownPdfBuilder + { + return $builder ->wrapperFile('files/wrapper.html') ->files('assets/file.md') + ; + } + + public function testFileWithContentFile(): void + { + $this->getBuilder() + ->files('assets/file.md') + ->wrapperFile('files/wrapper.html') ->generate() ; + + $this->assertGotenbergEndpoint('/forms/chromium/convert/markdown'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); } - public function testRequiredWrapperTemplate(): void + public function testFileWithContent(): void { - $builder = $this->getMarkdownPdfBuilder(); - $builder + $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ + 'strict_variables' => true, + ]); + + $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { + public function load(string $class): object|null + { + return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + } + }); + + $this->dependencies->set('twig', $twig); + + $this->getBuilder() ->files('assets/file.md') + ->wrapper('templates/wrapper.html.twig', ['name' => 'John Doe']) + ->generate() ; + $this->assertGotenbergEndpoint('/forms/chromium/convert/markdown'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); + } + + public function testWithStringableObject(): void + { + $class = new class implements \Stringable { + public function __toString(): string + { + return 'assets/file.md'; + } + }; + + $this->getBuilder() + ->files($class) + ->wrapperFile('files/wrapper.html') + ->generate() + ; + + $this->assertGotenbergEndpoint('/forms/chromium/convert/markdown'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); + } + + public function testRequiredFileContent(): void + { $this->expectException(MissingRequiredFieldException::class); $this->expectExceptionMessage('HTML template is required'); - $builder->getMultipartFormData(); + $this->getBuilder() + ->generate() + ; } public function testRequiredMarkdownFile(): void { - $builder = $this->getMarkdownPdfBuilder(); - $builder + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('At least one markdown file is required.'); + + $this->getBuilder() ->wrapperFile('files/wrapper.html') + ->generate() ; + } - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('At least one markdown file is required'); + public function testFilesExtensionRequirement(): void + { + $this->expectException(InvalidBuilderConfiguration::class); + $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); + + $this->getBuilder() + ->files('b.png') + ->generate() + ; + } + + public function testToWrapWithContent(): void + { + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Use wrapper() instead of content().'); - $builder->getMultipartFormData(); + $this->getBuilder() + ->content('templates/wrapper.html.twig', ['name' => 'John Doe']) + ; } - private function getMarkdownPdfBuilder(bool $twig = true): MarkdownPdfBuilder + public function testToWrapWithContentFile(): void { - return (new MarkdownPdfBuilder($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry, new RequestStack(), true === $twig ? self::$twig : null)) - ->processor(new NullProcessor()) + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Use wrapperFile() instead of contentFile().'); + + $this->getBuilder() + ->contentFile('files/wrapper.html') ; } } diff --git a/tests/Builder/Pdf/MergePdfBuilderTest.php b/tests/Builder/Pdf/MergePdfBuilderTest.php index 790aea5d..c72c15f3 100644 --- a/tests/Builder/Pdf/MergePdfBuilderTest.php +++ b/tests/Builder/Pdf/MergePdfBuilderTest.php @@ -2,131 +2,103 @@ namespace Sensiolabs\GotenbergBundle\Tests\Builder\Pdf; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder; +use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; +use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\Processor\NullProcessor; -use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; -use Symfony\Component\Mime\Part\DataPart; - -#[CoversClass(MergePdfBuilder::class)] -#[UsesClass(AbstractPdfBuilder::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(GotenbergFileResult::class)] -final class MergePdfBuilderTest extends AbstractBuilderTestCase +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\DownloadFromTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\FlattenTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\MetadataTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\PdfFormatTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\WebhookTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; +use Symfony\Component\DependencyInjection\Container; + +/** + * @extends GotenbergBuilderTestCase + */ +final class MergePdfBuilderTest extends GotenbergBuilderTestCase { - private const PDF_DOCUMENTS_DIR = 'pdf'; + /** @use DownloadFromTestCaseTrait */ + use DownloadFromTestCaseTrait; - public function testEndpointIsCorrect(): void - { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/pdfengines/merge'), - $this->anything(), - $this->anything(), - ) - ; + /** @use FlattenTestCaseTrait */ + use FlattenTestCaseTrait; - $this->getMergePdfBuilder() - ->files( - self::PDF_DOCUMENTS_DIR.'/simple_pdf.pdf', - self::PDF_DOCUMENTS_DIR.'/simple_pdf_1.pdf', - ) - ->generate() - ; - } + /** @use MetadataTestCaseTrait */ + use MetadataTestCaseTrait; + + /** @use PdfFormatTestCaseTrait */ + use PdfFormatTestCaseTrait; + + /** @use WebhookTestCaseTrait */ + use WebhookTestCaseTrait; - public static function configurationIsCorrectlySetProvider(): \Generator + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): MergePdfBuilder { - yield 'pdf_format' => ['pdf_format', 'PDF/A-1b', [ - 'pdfa' => 'PDF/A-1b', - ]]; - yield 'pdf_universal_access' => ['pdf_universal_access', false, [ - 'pdfua' => 'false', - ]]; - yield 'metadata' => ['metadata', ['Author' => 'SensioLabs'], [ - 'metadata' => '{"Author":"SensioLabs"}', - ]]; + return new MergePdfBuilder($client, $dependencies); } /** - * @param array $expected + * @param MergePdfBuilder $builder */ - #[DataProvider('configurationIsCorrectlySetProvider')] - public function testConfigurationIsCorrectlySet(string $key, mixed $value, array $expected): void + protected function initializeBuilder(BuilderInterface $builder, Container $container): MergePdfBuilder { - $builder = $this->getMergePdfBuilder(); - $builder->setConfigurations([ - $key => $value, - ]); - $builder->files( - self::PDF_DOCUMENTS_DIR.'/simple_pdf.pdf', - self::PDF_DOCUMENTS_DIR.'/simple_pdf_1.pdf', - ); - - self::assertEquals($expected, $builder->getMultipartFormData()[0]); + return $builder + ->files('pdf/simple_pdf.pdf', 'pdf/simple_pdf_1.pdf') + ; } - public function testRequiredFormData(): void + public function testAddFilesAsContent(): void { - $builder = $this->getMergePdfBuilder(); - - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('At least one PDF file is required'); + $this->getBuilder() + ->files('pdf/simple_pdf.pdf', 'pdf/simple_pdf_1.pdf') + ->generate() + ; - $builder->getMultipartFormData(); + $this->assertGotenbergEndpoint('/forms/pdfengines/merge'); + $this->assertGotenbergFormDataFile('files', 'application/pdf', self::FIXTURE_DIR.'/pdf/simple_pdf.pdf'); + $this->assertGotenbergFormDataFile('files', 'application/pdf', self::FIXTURE_DIR.'/pdf/simple_pdf_1.pdf'); } - public function testStringableObject(): void + public function testWithStringableObject(): void { - $stringable = new class(self::PDF_DOCUMENTS_DIR) implements \Stringable { - public function __construct(private string $directory) - { - } - + $class = new class implements \Stringable { public function __toString(): string { - return $this->directory.'/simple_pdf.pdf'; + return 'pdf/simple_pdf.pdf'; } }; - $builder = $this->getMergePdfBuilder(); - $builder - ->files($stringable) - ; - $data = $builder->getMultipartFormData(); + $this->getBuilder() + ->files($class, 'pdf/simple_pdf_1.pdf') + ->generate() + ; - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $dataPart = $data[0]['files']); - self::assertSame(basename((string) $stringable), $dataPart->getFilename()); + $this->assertGotenbergEndpoint('/forms/pdfengines/merge'); + $this->assertGotenbergFormDataFile('files', 'application/pdf', self::FIXTURE_DIR.'/pdf/simple_pdf.pdf'); + $this->assertGotenbergFormDataFile('files', 'application/pdf', self::FIXTURE_DIR.'/pdf/simple_pdf_1.pdf'); } - public function testSplFileInfoObject(): void + public function testFilesExtensionRequirement(): void { - $splFileInfo = new \SplFileInfo(self::PDF_DOCUMENTS_DIR.'/simple_pdf.pdf'); - $builder = $this->getMergePdfBuilder(); - $builder - ->files($splFileInfo) - ; + $this->expectException(InvalidBuilderConfiguration::class); + $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); - $data = $builder->getMultipartFormData(); - - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $dataPart = $data[0]['files']); - self::assertSame(basename((string) $splFileInfo), $dataPart->getFilename()); + $this->getBuilder() + ->files('simple_pdf.pdf', 'b.png') + ->generate() + ; } - private function getMergePdfBuilder(): MergePdfBuilder + public function testRequirementMissingFile(): void { - return (new MergePdfBuilder($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry)) - ->processor(new NullProcessor()) + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('At least one PDF file is required.'); + + $this->getBuilder() + ->generate() ; } } diff --git a/tests/Builder/Pdf/SplitPdfBuilderTest.php b/tests/Builder/Pdf/SplitPdfBuilderTest.php index c29f044d..27c588e0 100644 --- a/tests/Builder/Pdf/SplitPdfBuilderTest.php +++ b/tests/Builder/Pdf/SplitPdfBuilderTest.php @@ -2,165 +2,150 @@ namespace Sensiolabs\GotenbergBundle\Tests\Builder\Pdf; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\SplitPdfBuilder; +use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Enumeration\SplitMode; +use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\Processor\NullProcessor; -use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; -use Symfony\Component\Mime\Part\DataPart; - -#[CoversClass(SplitPdfBuilder::class)] -#[UsesClass(AbstractPdfBuilder::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(GotenbergFileResult::class)] -final class SplitPdfBuilderTest extends AbstractBuilderTestCase +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\DownloadFromTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\FlattenTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\MetadataTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\PdfFormatTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\SplitTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\WebhookTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; +use Symfony\Component\DependencyInjection\Container; + +/** + * @extends GotenbergBuilderTestCase + */ +final class SplitPdfBuilderTest extends GotenbergBuilderTestCase { - private const PDF_DOCUMENTS_DIR = 'pdf'; + /** @use DownloadFromTestCaseTrait */ + use DownloadFromTestCaseTrait; - public function testEndpointIsCorrect(): void - { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/pdfengines/split'), - $this->anything(), - $this->anything(), - ) - ; + /** @use FlattenTestCaseTrait */ + use FlattenTestCaseTrait; - $this->getSplitPdfBuilder() - ->files(self::PDF_DOCUMENTS_DIR.'/multi_page.pdf') - ->splitMode(SplitMode::Pages) - ->splitSpan('1') - ->generate() - ; - } + /** @use MetadataTestCaseTrait */ + use MetadataTestCaseTrait; + + /** @use PdfFormatTestCaseTrait */ + use PdfFormatTestCaseTrait; - public static function configurationIsCorrectlySetProvider(): \Generator + /** @use SplitTestCaseTrait */ + use SplitTestCaseTrait; + + /** @use WebhookTestCaseTrait */ + use WebhookTestCaseTrait; + + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): SplitPdfBuilder { - yield 'split_mode' => [ - [ - 'split_mode' => 'pages', - 'split_span' => '1', - ], - [ - 'splitMode' => 'pages', - ], - ]; - yield 'split_span' => [ - [ - 'split_span' => '1', - 'split_mode' => 'pages', - ], - [ - 'splitSpan' => '1', - ], - ]; - yield 'split_unify' => [ - [ - 'split_unify' => true, - 'split_span' => '1', - 'split_mode' => 'pages', - ], - [ - 'splitUnify' => true, - ], - ]; + return new SplitPdfBuilder($client, $dependencies); } /** - * @param array $configurations - * @param array $expected + * @param SplitPdfBuilder $builder */ - #[DataProvider('configurationIsCorrectlySetProvider')] - public function testConfigurationIsCorrectlySet(array $configurations, array $expected): void - { - $builder = $this->getSplitPdfBuilder(); - $builder->setConfigurations($configurations); - $builder->files(self::PDF_DOCUMENTS_DIR.'/multi_page.pdf'); - - self::assertEquals($expected, $builder->getMultipartFormData()[0]); - } - - public function testRequiredFormData(): void + protected function initializeBuilder(BuilderInterface $builder, Container $container): SplitPdfBuilder { - $builder = $this->getSplitPdfBuilder(); - - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('"splitMode" and "splitSpan" must be provided.'); - - $builder->getMultipartFormData(); + return $builder + ->files('pdf/simple_pdf.pdf') + ->splitMode(SplitMode::Pages) + ->splitSpan('1-2') + ; } - public function testRequiredFile(): void + public function testAddFilesAsContent(): void { - $builder = $this->getSplitPdfBuilder() + $this->getBuilder() + ->files('pdf/simple_pdf.pdf') ->splitMode(SplitMode::Pages) - ->splitSpan('1') + ->splitSpan('1-2') + ->generate() ; - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('At least one PDF file is required'); - - $builder->getMultipartFormData(); + $this->assertGotenbergEndpoint('/forms/pdfengines/split'); + $this->assertGotenbergFormDataFile('files', 'application/pdf', self::FIXTURE_DIR.'/pdf/simple_pdf.pdf'); } - public function testStringableObject(): void + public function testWithStringableObject(): void { - $supportedFilePath = new class(self::PDF_DOCUMENTS_DIR) implements \Stringable { - public function __construct(private string $directory) - { - } - + $class = new class implements \Stringable { public function __toString(): string { - return $this->directory.'/simple_pdf.pdf'; + return 'pdf/simple_pdf.pdf'; } }; - $builder = $this->getSplitPdfBuilder(); - $builder - ->files($supportedFilePath) + $this->getBuilder() + ->files($class) ->splitMode(SplitMode::Pages) - ->splitSpan('1') + ->splitSpan('1-2') + ->generate() ; - $data = $builder->getMultipartFormData(); + $this->assertGotenbergEndpoint('/forms/pdfengines/split'); + $this->assertGotenbergFormDataFile('files', 'application/pdf', self::FIXTURE_DIR.'/pdf/simple_pdf.pdf'); + } + + public function testFilesExtensionRequirement(): void + { + $this->expectException(InvalidBuilderConfiguration::class); + $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); + + $this->getBuilder() + ->files('b.png') + ->splitMode(SplitMode::Pages) + ->splitSpan('1-2') + ->generate() + ; + } + + public function testRequiredSplitModeField(): void + { + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('Field "splitMode" must be provided.'); - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $dataPart = $data[0]['files']); - self::assertSame(basename((string) $supportedFilePath), $dataPart->getFilename()); + $this->getBuilder() + ->files('pdf/simple_pdf.pdf') + ->splitSpan('1-2') + ->generate() + ; } - public function testSplFileInfoObject(): void + public function testRequiredSplitSpanField(): void { - $supportedFilePath = new \SplFileInfo(self::PDF_DOCUMENTS_DIR.'/simple_pdf.pdf'); + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('Field "splitSpan" must be provided.'); - $builder = $this->getSplitPdfBuilder(); - $builder - ->files($supportedFilePath) + $this->getBuilder() + ->files('pdf/simple_pdf.pdf') ->splitMode(SplitMode::Pages) - ->splitSpan('1') + ->generate() ; + } - $data = $builder->getMultipartFormData(); + public function testRequiredFileContent(): void + { + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('At least one PDF file is required.'); - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $dataPart = $data[0]['files']); - self::assertSame(basename((string) $supportedFilePath), $dataPart->getFilename()); + $this->getBuilder() + ->splitMode(SplitMode::Pages) + ->splitSpan('1-2') + ->generate() + ; } - private function getSplitPdfBuilder(): SplitPdfBuilder + public function testRequirementMissingFile(): void { - return (new SplitPdfBuilder($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry)) - ->processor(new NullProcessor()) + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('At least one PDF file is required.'); + + $this->getBuilder() + ->generate() ; } } diff --git a/tests/Builder/Pdf/UrlPdfBuilderTest.php b/tests/Builder/Pdf/UrlPdfBuilderTest.php index b4fa54ca..d36f3b50 100644 --- a/tests/Builder/Pdf/UrlPdfBuilderTest.php +++ b/tests/Builder/Pdf/UrlPdfBuilderTest.php @@ -2,145 +2,135 @@ namespace Sensiolabs\GotenbergBundle\Tests\Builder\Pdf; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractChromiumPdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder; +use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Sensiolabs\GotenbergBundle\Processor\NullProcessor; -use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; -use Symfony\Component\HttpFoundation\RequestStack; +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\ChromiumPdfTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; +use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Generator\UrlGenerator; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; -#[CoversClass(UrlPdfBuilder::class)] -#[UsesClass(AbstractChromiumPdfBuilder::class)] -#[UsesClass(AbstractPdfBuilder::class)] -#[UsesClass(GotenbergFileResult::class)] -final class UrlPdfBuilderTest extends AbstractBuilderTestCase +/** + * @extends GotenbergBuilderTestCase + */ +final class UrlPdfBuilderTest extends GotenbergBuilderTestCase { - public function testEndpointIsCorrect(): void + /** @use ChromiumPdfTestCaseTrait */ + use ChromiumPdfTestCaseTrait; + + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): UrlPdfBuilder { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/chromium/convert/url'), - $this->anything(), - $this->anything(), - ) - ; + return new UrlPdfBuilder($client, $dependencies); + } - $this->getUrlPdfBuilder() - ->url('https://google.com') - ->generate() + /** + * @param UrlPdfBuilder $builder + */ + protected function initializeBuilder(BuilderInterface $builder, Container $container): UrlPdfBuilder + { + if (!$this->dependencies->has('router')) { + $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); + } + + return $builder + ->url('https://example.com') ; } - public function testCanProvideUrl(): void + public function testRequiredFormData(): void { - $builder = $this->getUrlPdfBuilder(); - $builder->url('https://google.com'); - - $multipartFormData = $builder->getMultipartFormData(); + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('"url" (or "route") is required'); - self::assertCount(1, $multipartFormData); - self::assertArrayHasKey(0, $multipartFormData); - self::assertSame(['url' => 'https://google.com'], $multipartFormData[0]); + $this->getBuilder() + ->generate() + ; } - public function testCanProvideRoute(): void + public function testOutputFilename(): void { - $routeCollection = new RouteCollection(); - $routeCollection->add('fake_route', new Route('/route')); - $urlGenerator = new UrlGenerator($routeCollection, new RequestContext()); - - $builder = $this->getUrlPdfBuilder(urlGenerator: $urlGenerator); - $builder->route('fake_route'); + $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); - $multipartFormData = $builder->getMultipartFormData(); + $this->getBuilder() + ->url('https://example.com') + ->filename('test') + ->generate() + ; - self::assertCount(1, $multipartFormData); - self::assertArrayHasKey(0, $multipartFormData); - self::assertSame(['url' => 'http://localhost/route'], $multipartFormData[0]); + $this->assertGotenbergEndpoint('/forms/chromium/convert/url'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'test'); + $this->assertGotenbergFormData('url', 'https://example.com'); } - public function testCanProvideRouteWithCustomContext(): void + public function testToGenerateWithRequestContext(): void { - $requestContext = new RequestContext(); - $requestContext->setHost('sensiolabs.com'); - $routeCollection = new RouteCollection(); - $routeCollection->add('fake_route', new Route('/route')); - $urlGenerator = new UrlGenerator($routeCollection, new RequestContext()); - - $originalRequestContext = $urlGenerator->getContext(); + $routeCollection->add('article_read', new Route('/article/{id}', methods: Request::METHOD_GET)); - $builder = $this->getUrlPdfBuilder(urlGenerator: $urlGenerator); - $builder->setRequestContext($requestContext); + $requestContext = new RequestContext(); + $this->dependencies->set('router', new UrlGenerator($routeCollection, $requestContext)); - $builder->route('fake_route'); + $requestContext->setHost('example'); - $multipartFormData = $builder->getMultipartFormData(); + $this->getBuilder() + ->route('article_read', ['id' => 1]) + ->setRequestContext($requestContext) + ->filename('article') + ->generate() + ; - self::assertCount(1, $multipartFormData); - self::assertArrayHasKey(0, $multipartFormData); - self::assertSame(['url' => 'http://sensiolabs.com/route'], $multipartFormData[0]); - self::assertSame($originalRequestContext, $urlGenerator->getContext()); + $this->assertGotenbergEndpoint('/forms/chromium/convert/url'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'article'); + $this->assertGotenbergFormData('url', 'http://example/article/1'); } - public function testRouterIsRequired(): void + public function testPdfGenerationFromAGivenRoute(): void { - $builder = $this->getUrlPdfBuilder(); - - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Router is required to use "Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder::route" method. Try to run "composer require symfony/routing".'); - - $builder->route('fake_route'); - } + $routeCollection = new RouteCollection(); + $routeCollection->add('article_read', new Route('/article/{id}', methods: Request::METHOD_GET)); - public function testRequiredEitherUrlOrRoute(): void - { - $builder = $this->getUrlPdfBuilder(); + $this->dependencies->set('router', new UrlGenerator($routeCollection, new RequestContext())); - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('URL (or route) is required'); + $this->getBuilder() + ->route('article_read', ['id' => 1]) + ->filename('article') + ->generate() + ; - $builder->getMultipartFormData(); + $this->assertGotenbergEndpoint('/forms/chromium/convert/url'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'article'); + $this->assertGotenbergFormData('url', 'http://localhost/article/1'); } - public function testRequiredEitherUrlOrRouteNotBoth(): void + public function testRequirementAboutRouteAndUrlProvided(): void { - $routeCollection = new RouteCollection(); - $routeCollection->add('fake_route', new Route('/route')); - $urlGenerator = new UrlGenerator($routeCollection, new RequestContext()); - - $builder = $this->getUrlPdfBuilder(urlGenerator: $urlGenerator); - $builder->url('https://sensiolabs.com'); - $builder->route('fake_route'); - $this->expectException(MissingRequiredFieldException::class); $this->expectExceptionMessage('Provide only one of ["route", "url"] parameter. Not both.'); - $builder->getMultipartFormData(); + $this->getBuilder() + ->url('https://example.com') + ->route('article_read', ['id' => 1]) + ->filename('test') + ->generate() + ; } - private function getUrlPdfBuilder(UrlGeneratorInterface|null $urlGenerator = null): UrlPdfBuilder + public function testUrlGeneratorDependencyRequirement(): void { - return (new UrlPdfBuilder( - $this->gotenbergClient, - self::$assetBaseDirFormatter, - $this->webhookConfigurationRegistry, - new RequestStack(), - null, - $urlGenerator) - ) - ->processor(new NullProcessor()) + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('UrlGenerator is required to use "Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies\UrlGeneratorAwareTrait::getUrlGenerator" method. Try to run "composer require symfony/routing".'); + + $routeCollection = new RouteCollection(); + $routeCollection->add('article_read', new Route('/article/{id}', methods: Request::METHOD_GET)); + + $this->getBuilder() + ->route('article_read', ['id' => 1]) + ->generate() ; } } diff --git a/tests/Builder/Screenshot/AbstractChromiumScreenshotBuilderTest.php b/tests/Builder/Screenshot/AbstractChromiumScreenshotBuilderTest.php deleted file mode 100644 index ea46afa9..00000000 --- a/tests/Builder/Screenshot/AbstractChromiumScreenshotBuilderTest.php +++ /dev/null @@ -1,101 +0,0 @@ - ['width', 10, [ - 'width' => '10', - ]]; - yield 'height' => ['height', 10, [ - 'height' => '10', - ]]; - yield 'clip' => ['clip', false, [ - 'clip' => 'false', - ]]; - yield 'format' => ['format', 'png', [ - 'format' => 'png', - ]]; - yield 'quality' => ['quality', 50, [ - 'quality' => 50, - ]]; - yield 'omit_background' => ['omit_background', false, [ - 'omitBackground' => 'false', - ]]; - yield 'optimize_for_speed' => ['optimize_for_speed', false, [ - 'optimizeForSpeed' => 'false', - ]]; - yield 'wait_delay' => ['wait_delay', '3ms', [ - 'waitDelay' => '3ms', - ]]; - yield 'wait_for_expression' => ['wait_for_expression', "window.status === 'ready'", [ - 'waitForExpression' => "window.status === 'ready'", - ]]; - yield 'emulated_media_type' => ['emulated_media_type', EmulatedMediaType::Screen, [ - 'emulatedMediaType' => 'screen', - ]]; - yield 'cookies' => ['cookies', [['name' => 'MyCookie', 'value' => 'raspberry']], [ - 'cookies' => '[{"name":"MyCookie","value":"raspberry"}]', - ]]; - yield 'user_agent' => ['user_agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)', [ - 'userAgent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)', - ]]; - yield 'extra_http_headers' => ['extra_http_headers', ['MyHeader' => 'SomeValue'], [ - 'extraHttpHeaders' => '{"MyHeader":"SomeValue"}', - ]]; - yield 'fail_on_http_status_codes' => ['fail_on_http_status_codes', [499, 500], [ - 'failOnHttpStatusCodes' => '[499,500]', - ]]; - yield 'fail_on_resource_http_status_codes' => ['fail_on_resource_http_status_codes', [499, 500], [ - 'failOnResourceHttpStatusCodes' => '[499,500]', - ]]; - yield 'fail_on_resource_loading_failed' => ['fail_on_resource_loading_failed', false, [ - 'failOnResourceLoadingFailed' => 'false', - ]]; - yield 'fail_on_console_exceptions' => ['fail_on_console_exceptions', false, [ - 'failOnConsoleExceptions' => 'false', - ]]; - yield 'skip_network_idle_event' => ['skip_network_idle_event', false, [ - 'skipNetworkIdleEvent' => 'false', - ]]; - } - - /** - * @param array $expected - */ - #[DataProvider('configurationIsCorrectlySetProvider')] - #[TestDox('Configuration "$_dataName" is correctly set')] - public function testConfigurationIsCorrectlySet(string $key, mixed $value, array $expected): void - { - $builder = $this->getChromiumScreenshotBuilder(); - $builder->setConfigurations([ - $key => $value, - ]); - - self::assertEquals($expected, $builder->getMultipartFormData()[0]); - } - - private function getChromiumScreenshotBuilder(bool $twig = true): AbstractChromiumScreenshotBuilder - { - return new class($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry, new RequestStack(), true === $twig ? self::$twig : null) extends AbstractChromiumScreenshotBuilder { - protected function getEndpoint(): string - { - return '/fake/endpoint'; - } - }; - } -} diff --git a/tests/Builder/Screenshot/AbstractScreenshotBuilderTest.php b/tests/Builder/Screenshot/AbstractScreenshotBuilderTest.php deleted file mode 100644 index c47f2911..00000000 --- a/tests/Builder/Screenshot/AbstractScreenshotBuilderTest.php +++ /dev/null @@ -1,101 +0,0 @@ -gotenbergClient = new GotenbergClient(new MockHttpClient([ - new MockResponse(), - ])); - - $response = $this->getScreenshotBuilder() - ->fileName('some_file.png', HeaderUtils::DISPOSITION_ATTACHMENT) - ->generate() - ->stream() - ; - - self::assertSame('attachment; filename=some_file.png', $response->headers->get('Content-Disposition')); - } - - public static function nativeNormalizersProvider(): \Generator - { - yield 'boolean (true)' => ['boolean', true, 'true']; - yield 'boolean (false)' => ['boolean', false, 'false']; - - yield 'int' => ['int', 12, '12']; - yield 'float (.0)' => ['float', 12.0, '12.0']; - yield 'float (.5)' => ['float', 12.5, '12.5']; - } - - #[DataProvider('nativeNormalizersProvider')] - #[TestDox('Native "$_dataName" is correctly normalized')] - public function testNativeNormalizers(string $key, mixed $raw, mixed $expected): void - { - $builder = $this->getScreenshotBuilder([$key => $raw]); - $data = $builder->getMultipartFormData()[0]; - - self::assertArrayHasKey($key, $data); - self::assertSame($expected, $data[$key]); - } - - /** - * @param array{ - * 'extraHttpHeaders'?: array, - * 'assets'?: array, - * 'index.html'?: DataPart, - * 'failOnHttpStatusCodes'?: list, - * 'cookies'?: list, - * 'metadata'?: array - * } $formFields - */ - private function getScreenshotBuilder(array $formFields = []): AbstractScreenshotBuilder - { - return (new class($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry, $formFields) extends AbstractScreenshotBuilder { - /** - * @param array $formFields - */ - public function __construct(GotenbergClientInterface $gotenbergClient, AssetBaseDirFormatter $asset, WebhookConfigurationRegistryInterface $webhookConfigurationRegistry, array $formFields = []) - { - parent::__construct($gotenbergClient, $asset, $webhookConfigurationRegistry); - $this->formFields = $formFields; - } - - public function setConfigurations(array $configurations): static - { - return $this; - } - - protected function getEndpoint(): string - { - return '/fake/endpoint'; - } - }) - ->processor(new NullProcessor()) - ; - } -} diff --git a/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php b/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php index dee58fff..41e4c7c1 100644 --- a/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php @@ -2,84 +2,77 @@ namespace Sensiolabs\GotenbergBundle\Tests\Builder\Screenshot; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractChromiumScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\Processor\NullProcessor; -use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; -use Sensiolabs\GotenbergBundle\Twig\GotenbergExtension; -use Symfony\Component\HttpFoundation\RequestStack; - -#[CoversClass(HtmlScreenshotBuilder::class)] -#[UsesClass(AbstractChromiumScreenshotBuilder::class)] -#[UsesClass(AbstractScreenshotBuilder::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(GotenbergExtension::class)] -#[UsesClass(GotenbergFileResult::class)] -final class HtmlScreenshotBuilderTest extends AbstractBuilderTestCase +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\ChromiumScreenshotTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; +use Sensiolabs\GotenbergBundle\Twig\GotenbergRuntime; +use Symfony\Component\DependencyInjection\Container; +use Twig\Environment; +use Twig\Loader\FilesystemLoader; +use Twig\RuntimeLoader\RuntimeLoaderInterface; + +/** + * @extends GotenbergBuilderTestCase + */ +final class HtmlScreenshotBuilderTest extends GotenbergBuilderTestCase { - public function testEndpointIsCorrect(): void - { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/chromium/screenshot/html'), - $this->anything(), - $this->anything(), - ) - ; + /** @use ChromiumScreenshotTestCaseTrait */ + use ChromiumScreenshotTestCaseTrait; - $this->getHtmlScreenshotBuilder() - ->contentFile('files/content.html') - ->generate() - ; + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): HtmlScreenshotBuilder + { + return new HtmlScreenshotBuilder($client, $dependencies); } - public static function withPlainContentFileProvider(): \Generator + /** + * @param HtmlScreenshotBuilder $builder + */ + protected function initializeBuilder(BuilderInterface $builder, Container $container): HtmlScreenshotBuilder { - yield 'with twig' => [true]; - yield 'without twig' => [false]; + return $builder + ->contentFile('files/content.html') + ; } - #[DataProvider('withPlainContentFileProvider')] - public function testWithPlainContentFile(bool $withTwig): void + public function testOutputFilename(): void { - $builder = $this->getHtmlScreenshotBuilder($withTwig); - $builder->contentFile('files/content.html'); - - $data = $builder->getMultipartFormData()[0]; - - $expected = << - - - - My PDF - - -

Hello world!

- - - + $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); - HTML; + $this->getBuilder() + ->contentFile('files/content.html') + ->filename('test') + ->generate() + ; - self::assertFile($data, 'index.html', expectedContent: $expected); + $this->assertGotenbergEndpoint('/forms/chromium/screenshot/html'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'test'); } public function testWithTwigContentFile(): void { - $builder = $this->getHtmlScreenshotBuilder(); - $builder->content('templates/content.html.twig', ['name' => 'world']); + $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ + 'strict_variables' => true, + ]); + + $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { + public function load(string $class): object|null + { + return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + } + }); - $data = $builder->getMultipartFormData()[0]; + $this->dependencies->set('twig', $twig); + + $this->getBuilder() + ->content('templates/content.html.twig', ['name' => 'world']) + ->generate() + ; + + $this->assertGotenbergEndpoint('/forms/chromium/screenshot/html'); $expected = << @@ -96,23 +89,16 @@ public function testWithTwigContentFile(): void HTML; - self::assertFile($data, 'index.html', expectedContent: $expected); + $this->assertContentFile('index.html', 'text/html', $expected); } public function testRequiredFormData(): void { - $builder = $this->getHtmlScreenshotBuilder(); - $this->expectException(MissingRequiredFieldException::class); $this->expectExceptionMessage('Content is required'); - $builder->getMultipartFormData(); - } - - private function getHtmlScreenshotBuilder(bool $twig = true): HtmlScreenshotBuilder - { - return (new HtmlScreenshotBuilder($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry, new RequestStack(), true === $twig ? self::$twig : null)) - ->processor(new NullProcessor()) + $this->getBuilder() + ->generate() ; } } diff --git a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php index 0e6a4286..ab2c9c9e 100644 --- a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php @@ -2,138 +2,164 @@ namespace Sensiolabs\GotenbergBundle\Tests\Builder\Screenshot; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractChromiumScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; +use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\Processor\NullProcessor; -use Sensiolabs\GotenbergBundle\Tests\Builder\AbstractBuilderTestCase; -use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\Mime\Part\DataPart; - -#[CoversClass(MarkdownScreenshotBuilder::class)] -#[UsesClass(AbstractChromiumScreenshotBuilder::class)] -#[UsesClass(AbstractScreenshotBuilder::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(GotenbergFileResult::class)] -final class MarkdownScreenshotBuilderTest extends AbstractBuilderTestCase +use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\ChromiumScreenshotTestCaseTrait; +use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; +use Sensiolabs\GotenbergBundle\Twig\GotenbergRuntime; +use Symfony\Component\DependencyInjection\Container; +use Twig\Environment; +use Twig\Loader\FilesystemLoader; +use Twig\RuntimeLoader\RuntimeLoaderInterface; + +/** + * @extends GotenbergBuilderTestCase + */ +final class MarkdownScreenshotBuilderTest extends GotenbergBuilderTestCase { - public function testEndpointIsCorrect(): void + /** @use ChromiumScreenshotTestCaseTrait */ + use ChromiumScreenshotTestCaseTrait; + + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): MarkdownScreenshotBuilder { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/chromium/screenshot/markdown'), - $this->anything(), - $this->anything(), - ) - ; + return new MarkdownScreenshotBuilder($client, $dependencies); + } - $this->getMarkdownScreenshotBuilder() - ->wrapperFile('files/wrapper.html') + /** + * @param MarkdownScreenshotBuilder $builder + */ + protected function initializeBuilder(BuilderInterface $builder, Container $container): MarkdownScreenshotBuilder + { + return $builder + ->wrapperFile('files/content.html') ->files('assets/file.md') - ->generate() ; } - public function testMarkdownFile(): void + public function testOutputFilename(): void { - $builder = $this->getMarkdownScreenshotBuilder(); - $builder - ->wrapperFile('files/wrapper.html') + $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + + $this->getBuilder() + ->wrapperFile('files/content.html') ->files('assets/file.md') + ->filename('test') + ->generate() ; - $data = $builder->getMultipartFormData()[0]; - - $expected = << - - - - My PDF - - -

Hello world!

- - - - - HTML; - - self::assertFile($data, 'index.html', expectedContent: $expected); + $this->assertGotenbergEndpoint('/forms/chromium/screenshot/markdown'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'test'); } - public function testRequiredWrapperTemplate(): void + public function testFileWithContentFile(): void { - $builder = $this->getMarkdownScreenshotBuilder(); - $builder - ->files(new \SplFileInfo('assets/file.md')) + $this->getBuilder() + ->files('assets/file.md') + ->wrapperFile('files/wrapper.html') + ->generate() ; - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('HTML template is required'); - - $builder->getMultipartFormData(); + $this->assertGotenbergEndpoint('/forms/chromium/screenshot/markdown'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); } - public function testRequiredMarkdownFile(): void + public function testFileWithContent(): void { - $builder = $this->getMarkdownScreenshotBuilder(); - $builder - ->wrapperFile('files/wrapper.html') - ; + $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ + 'strict_variables' => true, + ]); - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('At least one markdown file is required'); + $twig->addRuntimeLoader(new class implements RuntimeLoaderInterface { + public function load(string $class): object|null + { + return GotenbergRuntime::class === $class ? new GotenbergRuntime() : null; + } + }); + + $this->dependencies->set('twig', $twig); + + $this->getBuilder() + ->files('assets/file.md') + ->wrapper('templates/wrapper.html.twig', ['name' => 'John Doe']) + ->generate() + ; - $builder->getMultipartFormData(); + $this->assertGotenbergEndpoint('/forms/chromium/screenshot/markdown'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); } - public function testStringableObject(): void + public function testWithStringableObject(): void { - $stringable = new class implements \Stringable { + $class = new class implements \Stringable { public function __toString(): string { return 'assets/file.md'; } }; - $builder = $this->getMarkdownScreenshotBuilder(); - $builder + + $this->getBuilder() + ->files($class) ->wrapperFile('files/wrapper.html') - ->files($stringable) + ->generate() ; - $data = $builder->getMultipartFormData(); + $this->assertGotenbergEndpoint('/forms/chromium/screenshot/markdown'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); + } - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $data[0]['files']); + public function testRequiredFileContent(): void + { + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('HTML template is required'); + + $this->getBuilder() + ->generate() + ; } - public function testSplFileInfoObject(): void + public function testRequiredMarkdownFile(): void { - $splFileInfo = new \SplFileInfo('assets/file.md'); - $builder = $this->getMarkdownScreenshotBuilder(); - $builder + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('At least one markdown file is required.'); + + $this->getBuilder() ->wrapperFile('files/wrapper.html') - ->files($splFileInfo) + ->generate() ; + } - $data = $builder->getMultipartFormData(); + public function testFilesExtensionRequirement(): void + { + $this->expectException(InvalidBuilderConfiguration::class); + $this->expectExceptionMessage('The file extension "png" is not valid in this context.'); - /* @var DataPart $dataPart */ - self::assertInstanceOf(DataPart::class, $data[0]['files']); + $this->getBuilder() + ->files('b.png') + ->generate() + ; } - private function getMarkdownScreenshotBuilder(bool $twig = true): MarkdownScreenshotBuilder + public function testToWrapWithContent(): void { - return (new MarkdownScreenshotBuilder($this->gotenbergClient, self::$assetBaseDirFormatter, $this->webhookConfigurationRegistry, new RequestStack(), true === $twig ? self::$twig : null)) - ->processor(new NullProcessor()) + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Use wrapper() instead of content().'); + + $this->getBuilder() + ->content('templates/wrapper.html.twig', ['name' => 'John Doe']) + ; + } + + public function testToWrapWithContentFile(): void + { + $this->expectException(\BadMethodCallException::class); + $this->expectExceptionMessage('Use wrapperFile() instead of contentFile().'); + + $this->getBuilder() + ->contentFile('files/wrapper.html') ; } } diff --git a/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php b/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php index 0f70d257..23869712 100644 --- a/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php @@ -1,88 +1,125 @@ + */ +final class UrlScreenshotBuilderTest extends GotenbergBuilderTestCase { - /** - * @var MockObject&RouterInterface - */ - protected RouterInterface $router; + /** @use ChromiumScreenshotTestCaseTrait */ + use ChromiumScreenshotTestCaseTrait; protected function setUp(): void { parent::setUp(); - $this->router = $this->createMock(RouterInterface::class); + + $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); } - public function testEndpointIsCorrect(): void + protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): UrlScreenshotBuilder { - $this->gotenbergClient - ->expects($this->once()) - ->method('call') - ->with( - $this->equalTo('/forms/chromium/screenshot/url'), - $this->anything(), - $this->anything(), - ) + return new UrlScreenshotBuilder($client, $dependencies); + } + + /** + * @param UrlScreenshotBuilder $builder + */ + protected function initializeBuilder(BuilderInterface $builder, Container $container): UrlScreenshotBuilder + { + return $builder + ->url('https://example.com') + ; + } + + public function testRequiredFormData(): void + { + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('"url" (or "route") is required'); + + $this->getBuilder() + ->generate() ; + } - $this->getUrlScreenshotBuilder() - ->url('https://google.com') + public function testOutputFilename(): void + { + $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); + + $this->getBuilder() + ->url('https://example.com') + ->filename('test') ->generate() ; + + $this->assertGotenbergEndpoint('/forms/chromium/screenshot/url'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'test'); + $this->assertGotenbergFormData('url', 'https://example.com'); } - public function testUrl(): void + public function testPdfGenerationFromAGivenRoute(): void { - $builder = $this->getUrlScreenshotBuilder(); - $builder->url('https://google.com'); + $routeCollection = new RouteCollection(); + $routeCollection->add('article_read', new Route('/article/{id}', methods: Request::METHOD_GET)); - $multipartFormData = $builder->getMultipartFormData(); + $this->dependencies->set('router', new UrlGenerator($routeCollection, new RequestContext())); - self::assertCount(1, $multipartFormData); - self::assertArrayHasKey(0, $multipartFormData); - self::assertSame(['url' => 'https://google.com'], $multipartFormData[0]); + $this->getBuilder() + ->route('article_read', ['id' => 1]) + ->filename('article') + ->generate() + ; + + $this->assertGotenbergEndpoint('/forms/chromium/screenshot/url'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'article'); + $this->assertGotenbergFormData('url', 'http://localhost/article/1'); } - public function testRequiredFormData(): void + public function testToGenerateWithRequestContext(): void { - $builder = $this->getUrlScreenshotBuilder(); + $routeCollection = new RouteCollection(); + $routeCollection->add('article_read', new Route('/article/{id}', methods: Request::METHOD_GET)); - $this->expectException(MissingRequiredFieldException::class); - $this->expectExceptionMessage('URL (or route) is required'); + $requestContext = new RequestContext(); + $this->dependencies->set('router', new UrlGenerator($routeCollection, new RequestContext())); + + $requestContext->setHost('example'); + + $this->getBuilder() + ->route('article_read', ['id' => 1]) + ->setRequestContext($requestContext) + ->filename('article') + ->generate() + ; - $builder->getMultipartFormData(); + $this->assertGotenbergEndpoint('/forms/chromium/screenshot/url'); + $this->assertGotenbergHeader('Gotenberg-Output-Filename', 'article'); + $this->assertGotenbergFormData('url', 'http://example/article/1'); } - private function getUrlScreenshotBuilder(bool $twig = true): UrlScreenshotBuilder + public function testRequirementAboutRouteAndUrlProvided(): void { - return (new UrlScreenshotBuilder( - $this->gotenbergClient, - self::$assetBaseDirFormatter, - $this->webhookConfigurationRegistry, - new RequestStack(), - true === $twig ? self::$twig : null, - $this->router, - )) - ->processor(new NullProcessor()) + $this->expectException(MissingRequiredFieldException::class); + $this->expectExceptionMessage('Provide only one of ["route", "url"] parameter. Not both.'); + + $this->getBuilder() + ->url('https://example.com') + ->route('article_read', ['id' => 1]) + ->filename('test') + ->generate() ; } } diff --git a/tests/Client/GotenbergClientTest.php b/tests/Client/GotenbergClientTest.php index 5755be4b..1d6c82a8 100644 --- a/tests/Client/GotenbergClientTest.php +++ b/tests/Client/GotenbergClientTest.php @@ -2,17 +2,13 @@ namespace Sensiolabs\GotenbergBundle\Tests\Client; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; +use Sensiolabs\GotenbergBundle\Builder\Payload; use Sensiolabs\GotenbergBundle\Client\GotenbergClient; -use Sensiolabs\GotenbergBundle\Client\GotenbergResponse; use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\Response\MockResponse; use Symfony\Component\HttpFoundation\Response; -#[CoversClass(GotenbergClient::class)] -#[UsesClass(GotenbergResponse::class)] final class GotenbergClientTest extends TestCase { public function testCallIsCorrectlyFormatted(): void @@ -31,14 +27,13 @@ public function testCallIsCorrectlyFormatted(): void $mockClient = new MockHttpClient([$mockResponse], baseUri: 'http://localhost:3000'); - $multipartFormData = [ - [ - 'url' => 'https://google.com', - ], - ]; + $payload = new Payload( + [['url' => 'https://google.com']], + ['SomeHeader' => 'SomeValue'], + ); $gotenbergClient = new GotenbergClient($mockClient); - $response = $gotenbergClient->call('/some/url', $multipartFormData, ['SomeHeader' => 'SomeValue']); + $response = $gotenbergClient->call('/some/url', $payload); self::assertSame(1, $mockClient->getRequestsCount()); self::assertSame('POST', $mockResponse->getRequestMethod()); @@ -56,24 +51,15 @@ public function testCallIsCorrectlyFormatted(): void self::assertArrayHasKey('SomeHeader', $requestHeaders); self::assertSame('SomeValue', $requestHeaders['SomeHeader'][0]); - self::assertArrayHasKey('content-type', $requestHeaders); - $requestContentType = $requestHeaders['content-type'][0]; + self::assertArrayHasKey('Content-Type', $requestHeaders); + $requestContentType = $requestHeaders['Content-Type'][0]; self::assertMatchesRegularExpression('#^multipart/form-data; boundary=(?P.*)$#', $requestContentType); - /* @see https://onlinephp.io/c/e8233 */ - preg_match('#^multipart/form-data; boundary=(?P.*)$#', $requestContentType, $matches); - $boundary = $matches['boundary'] ?? ''; - - $requestBody = $mockResponse->getRequestOptions()['body']; - self::assertSame( - "--{$boundary}\r\nContent-Type: text/plain; charset=utf-8\r\nContent-Transfer-Encoding: 8bit\r\nContent-Disposition: form-data; name=\"url\"\r\n\r\nhttps://google.com\r\n--{$boundary}--\r\n", - $requestBody, - ); - + $responseHeaders = $response->getHeaders(); self::assertSame(Response::HTTP_OK, $response->getStatusCode()); - self::assertSame('application/pdf', $response->getHeaders()->get('content-type')); - self::assertSame('simple_pdf.pdf', $response->getFileName()); - self::assertSame(13624, $response->getContentLength()); + self::assertSame('application/pdf', $responseHeaders['content-type'][0]); + self::assertSame('attachment; filename="simple_pdf.pdf"', $responseHeaders['content-disposition'][0]); + self::assertSame('13624', $responseHeaders['content-length'][0]); } } diff --git a/tests/DependencyInjection/CompilerPass/GotenbergPassTest.php b/tests/DependencyInjection/CompilerPass/GotenbergPassTest.php index 566be4f5..f1eb6090 100644 --- a/tests/DependencyInjection/CompilerPass/GotenbergPassTest.php +++ b/tests/DependencyInjection/CompilerPass/GotenbergPassTest.php @@ -2,18 +2,17 @@ namespace Sensiolabs\GotenbergBundle\Tests\DependencyInjection\CompilerPass; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -use Sensiolabs\GotenbergBundle\Builder\Pdf\PdfBuilderInterface; -use Sensiolabs\GotenbergBundle\Debug\Builder\TraceablePdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; +use Sensiolabs\GotenbergBundle\DependencyInjection\BuilderStack; use Sensiolabs\GotenbergBundle\DependencyInjection\CompilerPass\GotenbergPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\DependencyInjection\Reference; -#[CoversClass(GotenbergPass::class)] class GotenbergPassTest extends TestCase { + private const BUILDER = HtmlPdfBuilder::class; + private function getContainerBuilder(bool $withDataCollector = false): ContainerBuilder { $container = new ContainerBuilder(); @@ -24,9 +23,9 @@ private function getContainerBuilder(bool $withDataCollector = false): Container $container->setDefinition('sensiolabs_gotenberg.data_collector', $dataCollector); } - $pdfTaggedService = new Definition(PdfBuilderInterface::class); - $pdfTaggedService->addTag('sensiolabs_gotenberg.pdf_builder'); - $container->setDefinition('.service.pdf_tagged', $pdfTaggedService); + $htmlPdfBuilderService = new Definition(self::BUILDER); + $htmlPdfBuilderService->addTag('sensiolabs_gotenberg.builder'); + $container->setDefinition('.sensiolabs_gotenberg.pdf_builder.html', $htmlPdfBuilderService); $someRandomService = new Definition(\stdClass::class); $container->setDefinition('.service.random', $someRandomService); @@ -34,50 +33,25 @@ private function getContainerBuilder(bool $withDataCollector = false): Container return $container; } - public function testItDoesNothingIfDataCollectorNotRegistered(): void + private function getBuilderStack(): BuilderStack { - $container = $this->getContainerBuilder(); - - $serviceIds = $container->getServiceIds(); - - self::assertNotContains('sensiolabs_gotenberg.data_collector', $serviceIds); - - $compilerPass = new GotenbergPass(); - $compilerPass->process($container); + $builderStack = new BuilderStack(); + $builderStack->push(self::BUILDER); - self::assertSame($serviceIds, $container->getServiceIds()); + return $builderStack; } - public function testItDecoratesPdfBuildersWithTraceableWhenDataCollectorIsPresent(): void + public function testItDoesNothingIfDataCollectorNotRegistered(): void { - $container = $this->getContainerBuilder(withDataCollector: true); + $container = $this->getContainerBuilder(); $serviceIds = $container->getServiceIds(); - self::assertContains('sensiolabs_gotenberg.data_collector', $serviceIds); + self::assertNotContains('sensiolabs_gotenberg.data_collector', $serviceIds); - $compilerPass = new GotenbergPass(); + $compilerPass = new GotenbergPass($this->getBuilderStack()); $compilerPass->process($container); - $newServiceIds = $container->getServiceIds(); - self::assertNotSame($serviceIds, $newServiceIds); - self::assertContains('.service.pdf_tagged', $newServiceIds); - self::assertContains('.debug.service.pdf_tagged', $newServiceIds); - self::assertNotContains('.debug.service.random', $newServiceIds); - - $traceablePdfTaggedService = $container->getDefinition('.debug.service.pdf_tagged'); - self::assertNotNull($traceablePdfTaggedService); - self::assertSame(TraceablePdfBuilder::class, $traceablePdfTaggedService->getClass()); - - $traceablePdfTaggedServiceArguments = $traceablePdfTaggedService->getArguments(); - self::assertCount(2, $traceablePdfTaggedServiceArguments); - - self::assertArrayHasKey('$inner', $traceablePdfTaggedServiceArguments); - self::assertInstanceOf(Reference::class, $traceablePdfTaggedServiceArguments['$inner']); - self::assertSame('.inner', (string) $traceablePdfTaggedServiceArguments['$inner']); - - self::assertArrayHasKey('$stopwatch', $traceablePdfTaggedServiceArguments); - self::assertInstanceOf(Reference::class, $traceablePdfTaggedServiceArguments['$stopwatch']); - self::assertSame('debug.stopwatch', (string) $traceablePdfTaggedServiceArguments['$stopwatch']); + self::assertSame($serviceIds, $container->getServiceIds()); } } diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 1b6b7c2f..bc9ef32f 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -2,21 +2,62 @@ namespace Sensiolabs\GotenbergBundle\Tests\DependencyInjection; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; +use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; +use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\SplitPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder; +use Sensiolabs\GotenbergBundle\DependencyInjection\BuilderStack; use Sensiolabs\GotenbergBundle\DependencyInjection\Configuration; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\Definition\Processor; -#[CoversClass(Configuration::class)] final class ConfigurationTest extends TestCase { + /** + * @param array<'pdf'|'screenshot', list>> $builders + */ + public static function getWithBuilders(array $builders): Configuration + { + $builderStack = new BuilderStack(); + + foreach ($builders as $type => $builderList) { + foreach ($builderList as $builderClass) { + $builderStack->push($builderClass); + } + } + + return new Configuration($builderStack->getConfigNode()); + } + public function testDefaultConfigIsCorrect(): void { $processor = new Processor(); $config = $processor->processConfiguration( - new Configuration(), + self::getWithBuilders([ + 'pdf' => [ + ConvertPdfBuilder::class, + HtmlPdfBuilder::class, + LibreOfficePdfBuilder::class, + MarkdownPdfBuilder::class, + MergePdfBuilder::class, + UrlPdfBuilder::class, + SplitPdfBuilder::class, + ], + 'screenshot' => [ + HtmlScreenshotBuilder::class, + MarkdownScreenshotBuilder::class, + UrlScreenshotBuilder::class, + ], + ]), [[ 'http_client' => 'http_client', ]], @@ -32,7 +73,7 @@ public function testHttpClientIsRequired(): void $processor = new Processor(); $processor->processConfiguration( - new Configuration(), + new Configuration([]), [], ); } @@ -55,7 +96,7 @@ public function testInvalidNativePageRange(mixed $range): void $this->expectException(InvalidConfigurationException::class); $processor = new Processor(); $processor->processConfiguration( - new Configuration(), + self::getWithBuilders(['pdf' => [HtmlPdfBuilder::class]]), [['default_options' => ['pdf' => ['html' => ['native_page_ranges' => $range]]]]], ); } @@ -81,7 +122,7 @@ public function testWithExtraHeadersConfiguration(array $configuration): void { $processor = new Processor(); /** @var array{'default_options': array} $config */ - $config = $processor->processConfiguration(new Configuration(), [ + $config = $processor->processConfiguration(self::getWithBuilders(['pdf' => [HtmlPdfBuilder::class]]), [ [ 'http_client' => 'http_client', 'default_options' => [ @@ -95,7 +136,6 @@ public function testWithExtraHeadersConfiguration(array $configuration): void $config = $this->cleanOptions($config['default_options']['pdf']['html']); self::assertEquals([ 'extra_http_headers' => ['MyHeader' => 'MyValue', 'User-Agent' => 'MyAgent'], - 'fail_on_http_status_codes' => ['499', '599'], ], $config); } @@ -103,7 +143,7 @@ public function testWithDownloadFromConfiguration(): void { $processor = new Processor(); /** @var array{'default_options': array} $config */ - $config = $processor->processConfiguration(new Configuration(), [ + $config = $processor->processConfiguration(self::getWithBuilders(['pdf' => [HtmlPdfBuilder::class]]), [ [ 'http_client' => 'http_client', 'default_options' => [ @@ -129,57 +169,9 @@ public function testWithDownloadFromConfiguration(): void 'extraHttpHeaders' => ['MyHeader' => 'MyValue', 'User-Agent' => 'MyValue'], ], ], - 'fail_on_http_status_codes' => ['499', '599'], ], $config); } - /** - * @return iterable>> - */ - public static function providePaperSizesConfigurations(): iterable - { - yield 'with paper_width' => [ - [ - 'paper_standard_size' => 'A4', - 'paper_width' => '21cm', - ], - ]; - yield 'with paper_height' => [ - [ - 'paper_standard_size' => 'A4', - 'paper_height' => '29.7cm', - ], - ]; - yield 'with paper_width and paper_height' => [ - [ - 'paper_standard_size' => 'A4', - 'paper_width' => '21cm', - 'paper_height' => '29.7cm', - ], - ]; - } - - /** - * @param array $configuration - */ - #[DataProvider('providePaperSizesConfigurations')] - public function testExceptionOnPaperSizesConfigurations(array $configuration): void - { - $this->expectException(InvalidConfigurationException::class); - - $processor = new Processor(); - $processor->processConfiguration(new Configuration(), [ - [ - 'http_client' => 'http_client', - 'default_options' => [ - 'pdf' => [ - 'html' => $configuration, - ], - ], - ], - ]); - } - /** * @return \Generator>}}> */ @@ -219,7 +211,7 @@ public function testInvalidWebhookConfiguration(array $config): void $this->expectException(InvalidConfigurationException::class); $processor = new Processor(); $processor->processConfiguration( - new Configuration(), + new Configuration([]), $config, ); } @@ -272,17 +264,51 @@ private static function getBundleDefaultConfig(): array 'cookies' => [], 'user_agent' => null, 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [499, 599], + 'fail_on_http_status_codes' => [], 'fail_on_resource_http_status_codes' => [], 'fail_on_resource_loading_failed' => null, 'fail_on_console_exceptions' => null, 'skip_network_idle_event' => null, 'pdf_format' => null, 'pdf_universal_access' => null, - 'download_from' => [], 'split_mode' => null, 'split_span' => null, 'split_unify' => null, + 'download_from' => [], + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], + 'metadata' => [ + 'Author' => null, + 'Copyright' => null, + 'CreationDate' => null, + 'Creator' => null, + 'Keywords' => null, + 'Marked' => null, + 'ModDate' => null, + 'PDFVersion' => null, + 'Producer' => null, + 'Subject' => null, + 'Title' => null, + 'Trapped' => null, + ], + 'footer' => [ + 'template' => null, + 'context' => [], + ], + 'header' => [ + 'template' => null, + 'context' => [], + ], ], 'url' => [ 'single_page' => null, @@ -306,7 +332,7 @@ private static function getBundleDefaultConfig(): array 'cookies' => [], 'user_agent' => null, 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [499, 599], + 'fail_on_http_status_codes' => [], 'fail_on_resource_http_status_codes' => [], 'fail_on_resource_loading_failed' => null, 'fail_on_console_exceptions' => null, @@ -317,6 +343,40 @@ private static function getBundleDefaultConfig(): array 'split_mode' => null, 'split_span' => null, 'split_unify' => null, + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], + 'metadata' => [ + 'Author' => null, + 'Copyright' => null, + 'CreationDate' => null, + 'Creator' => null, + 'Keywords' => null, + 'Marked' => null, + 'ModDate' => null, + 'PDFVersion' => null, + 'Producer' => null, + 'Subject' => null, + 'Title' => null, + 'Trapped' => null, + ], + 'footer' => [ + 'template' => null, + 'context' => [], + ], + 'header' => [ + 'template' => null, + 'context' => [], + ], ], 'markdown' => [ 'single_page' => null, @@ -340,7 +400,7 @@ private static function getBundleDefaultConfig(): array 'cookies' => [], 'user_agent' => null, 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [499, 599], + 'fail_on_http_status_codes' => [], 'fail_on_resource_http_status_codes' => [], 'fail_on_resource_loading_failed' => null, 'fail_on_console_exceptions' => null, @@ -351,6 +411,40 @@ private static function getBundleDefaultConfig(): array 'split_mode' => null, 'split_span' => null, 'split_unify' => null, + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], + 'metadata' => [ + 'Author' => null, + 'Copyright' => null, + 'CreationDate' => null, + 'Creator' => null, + 'Keywords' => null, + 'Marked' => null, + 'ModDate' => null, + 'PDFVersion' => null, + 'Producer' => null, + 'Subject' => null, + 'Title' => null, + 'Trapped' => null, + ], + 'footer' => [ + 'template' => null, + 'context' => [], + ], + 'header' => [ + 'template' => null, + 'context' => [], + ], ], 'office' => [ 'password' => null, @@ -382,21 +476,118 @@ private static function getBundleDefaultConfig(): array 'split_mode' => null, 'split_span' => null, 'split_unify' => null, + 'flatten' => null, + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], + 'metadata' => [ + 'Author' => null, + 'Copyright' => null, + 'CreationDate' => null, + 'Creator' => null, + 'Keywords' => null, + 'Marked' => null, + 'ModDate' => null, + 'PDFVersion' => null, + 'Producer' => null, + 'Subject' => null, + 'Title' => null, + 'Trapped' => null, + ], + 'update_indexes' => null, ], 'merge' => [ 'pdf_format' => null, 'pdf_universal_access' => null, 'download_from' => [], + 'flatten' => null, + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], + 'metadata' => [ + 'Author' => null, + 'Copyright' => null, + 'CreationDate' => null, + 'Creator' => null, + 'Keywords' => null, + 'Marked' => null, + 'ModDate' => null, + 'PDFVersion' => null, + 'Producer' => null, + 'Subject' => null, + 'Title' => null, + 'Trapped' => null, + ], ], 'convert' => [ 'pdf_format' => null, 'pdf_universal_access' => null, 'download_from' => [], + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], ], 'split' => [ 'split_mode' => null, 'split_span' => null, 'split_unify' => null, + 'pdf_universal_access' => null, + 'pdf_format' => null, + 'download_from' => [], + 'flatten' => null, + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], + 'metadata' => [ + 'Author' => null, + 'Copyright' => null, + 'CreationDate' => null, + 'Creator' => null, + 'Keywords' => null, + 'Marked' => null, + 'ModDate' => null, + 'PDFVersion' => null, + 'Producer' => null, + 'Subject' => null, + 'Title' => null, + 'Trapped' => null, + ], ], ], 'screenshot' => [ @@ -414,12 +605,32 @@ private static function getBundleDefaultConfig(): array 'cookies' => [], 'user_agent' => null, 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [499, 599], + 'fail_on_http_status_codes' => [], 'fail_on_resource_http_status_codes' => [], 'fail_on_resource_loading_failed' => null, 'fail_on_console_exceptions' => null, 'skip_network_idle_event' => null, 'download_from' => [], + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], + 'footer' => [ + 'template' => null, + 'context' => [], + ], + 'header' => [ + 'template' => null, + 'context' => [], + ], ], 'url' => [ 'width' => null, @@ -435,12 +646,32 @@ private static function getBundleDefaultConfig(): array 'cookies' => [], 'user_agent' => null, 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [499, 599], + 'fail_on_http_status_codes' => [], 'fail_on_resource_http_status_codes' => [], 'fail_on_resource_loading_failed' => null, 'fail_on_console_exceptions' => null, 'skip_network_idle_event' => null, 'download_from' => [], + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], + 'footer' => [ + 'template' => null, + 'context' => [], + ], + 'header' => [ + 'template' => null, + 'context' => [], + ], ], 'markdown' => [ 'width' => null, @@ -456,12 +687,32 @@ private static function getBundleDefaultConfig(): array 'cookies' => [], 'user_agent' => null, 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [499, 599], + 'fail_on_http_status_codes' => [], 'fail_on_resource_http_status_codes' => [], 'fail_on_resource_loading_failed' => null, 'fail_on_console_exceptions' => null, 'skip_network_idle_event' => null, 'download_from' => [], + 'webhook' => [ + 'config_name' => null, + 'success' => [ + 'url' => null, + 'method' => null, + ], + 'error' => [ + 'url' => null, + 'method' => null, + ], + 'extra_http_headers' => [], + ], + 'footer' => [ + 'template' => null, + 'context' => [], + ], + 'header' => [ + 'template' => null, + 'context' => [], + ], ], ], ], @@ -475,12 +726,18 @@ private static function getBundleDefaultConfig(): array */ private function cleanOptions(array $userConfigurations): array { - return array_filter($userConfigurations, static function ($config): bool { - if (\is_array($config)) { - return 0 !== \count($config); + foreach ($userConfigurations as $key => $value) { + if (\is_array($value)) { + $userConfigurations[$key] = $this->cleanOptions($value); + + if ([] === $userConfigurations[$key]) { + unset($userConfigurations[$key]); + } + } elseif (null === $value) { + unset($userConfigurations[$key]); } + } - return null !== $config; - }); + return $userConfigurations; } } diff --git a/tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php b/tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php index 2b3070a5..70257a9b 100644 --- a/tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php +++ b/tests/DependencyInjection/SensiolabsGotenbergExtensionTest.php @@ -2,20 +2,30 @@ namespace Sensiolabs\GotenbergBundle\Tests\DependencyInjection; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\UsesClass; -use PHPUnit\Framework\TestCase; -use Sensiolabs\GotenbergBundle\DependencyInjection\Configuration; +use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\SplitPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder; +use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder; +use Sensiolabs\GotenbergBundle\DependencyInjection\BuilderStack; +use Sensiolabs\GotenbergBundle\DependencyInjection\CompilerPass\GotenbergPass; use Sensiolabs\GotenbergBundle\DependencyInjection\SensiolabsGotenbergExtension; +use Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType; +use Sensiolabs\GotenbergBundle\Enumeration\ImageResolutionDPI; +use Sensiolabs\GotenbergBundle\Enumeration\PaperSize; use Sensiolabs\GotenbergBundle\Enumeration\PdfFormat; +use Sensiolabs\GotenbergBundle\Enumeration\SplitMode; +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -#[CoversClass(SensiolabsGotenbergExtension::class)] -#[UsesClass(ContainerBuilder::class)] -#[UsesClass(Configuration::class)] -final class SensiolabsGotenbergExtensionTest extends TestCase +final class SensiolabsGotenbergExtensionTest extends KernelTestCase { private function getContainerBuilder(bool $kernelDebug = false): ContainerBuilder { @@ -24,9 +34,33 @@ private function getContainerBuilder(bool $kernelDebug = false): ContainerBuilde ])); } - public function testGotenbergConfiguredWithValidConfig(): void + private function getExtension(): SensiolabsGotenbergExtension { + $builderStack = new BuilderStack(); + $extension = new SensiolabsGotenbergExtension(); + $extension->setBuilderStack($builderStack); + + $extension->registerBuilder(ConvertPdfBuilder::class); + $extension->registerBuilder(HtmlPdfBuilder::class); + $extension->registerBuilder(LibreOfficePdfBuilder::class); + $extension->registerBuilder(MarkdownPdfBuilder::class); + $extension->registerBuilder(MergePdfBuilder::class); + $extension->registerBuilder(SplitPdfBuilder::class); + $extension->registerBuilder(UrlPdfBuilder::class); + + $extension->registerBuilder(HtmlScreenshotBuilder::class); + $extension->registerBuilder(MarkdownScreenshotBuilder::class); + $extension->registerBuilder(UrlScreenshotBuilder::class); + + $this->getContainerBuilder()->addCompilerPass(new GotenbergPass($builderStack)); + + return $extension; + } + + public function testGotenbergConfiguredWithValidConfig(): void + { + $extension = $this->getExtension(); $containerBuilder = $this->getContainerBuilder(); $validConfig = self::getValidConfig(); @@ -35,7 +69,7 @@ public function testGotenbergConfiguredWithValidConfig(): void $list = [ 'pdf' => [ 'html' => [ - 'paper_standard_size' => 'A4', + 'paper_standard_size' => PaperSize::A4, 'margin_top' => 1, 'margin_bottom' => 1, 'margin_left' => 1, @@ -49,7 +83,7 @@ public function testGotenbergConfiguredWithValidConfig(): void 'native_page_ranges' => '1-5', 'wait_delay' => '10s', 'wait_for_expression' => 'window.globalVar === "ready"', - 'emulated_media_type' => 'screen', + 'emulated_media_type' => EmulatedMediaType::Screen, 'cookies' => [[ 'name' => 'cook_me', 'value' => 'sensio', @@ -57,7 +91,6 @@ public function testGotenbergConfiguredWithValidConfig(): void 'secure' => true, 'httpOnly' => true, 'sameSite' => 'Lax', - 'path' => null, ]], 'extra_http_headers' => ['MyHeader' => 'MyValue', 'User-Agent' => 'MyValue'], 'fail_on_http_status_codes' => [401], @@ -65,9 +98,16 @@ public function testGotenbergConfiguredWithValidConfig(): void 'fail_on_resource_loading_failed' => true, 'fail_on_console_exceptions' => true, 'skip_network_idle_event' => true, - 'pdf_format' => 'PDF/A-1b', + 'pdf_format' => PdfFormat::Pdf1b, 'pdf_universal_access' => true, - 'download_from' => [], + 'download_from' => [ + [ + 'url' => 'http://example.com', + 'extraHttpHeaders' => [ + 'MyHeader' => 'MyValue', + ], + ], + ], ], 'url' => [ 'paper_width' => 21, @@ -85,17 +125,31 @@ public function testGotenbergConfiguredWithValidConfig(): void 'native_page_ranges' => '1-10', 'wait_delay' => '5s', 'wait_for_expression' => 'window.globalVar === "ready"', - 'emulated_media_type' => 'screen', + 'emulated_media_type' => EmulatedMediaType::Screen, 'extra_http_headers' => ['MyHeader' => 'MyValue', 'User-Agent' => 'MyValue'], 'fail_on_http_status_codes' => [401, 403], 'fail_on_resource_http_status_codes' => [401, 403], 'fail_on_resource_loading_failed' => false, 'fail_on_console_exceptions' => false, 'skip_network_idle_event' => false, - 'pdf_format' => PdfFormat::Pdf2b->value, + 'pdf_format' => PdfFormat::Pdf2b, 'pdf_universal_access' => false, - 'cookies' => [], - 'download_from' => [], + 'cookies' => [[ + 'name' => 'cook_me', + 'value' => 'sensio', + 'domain' => 'sensiolabs.com', + 'secure' => true, + 'httpOnly' => true, + 'sameSite' => 'Lax', + ]], + 'download_from' => [ + [ + 'url' => 'http://example.com', + 'extraHttpHeaders' => [ + 'MyHeader' => 'MyValue', + ], + ], + ], ], 'markdown' => [ 'paper_width' => 30, @@ -126,23 +180,71 @@ public function testGotenbergConfiguredWithValidConfig(): void 'download_from' => [], ], 'office' => [ + 'password' => 'secret', + 'pdf_format' => PdfFormat::Pdf1b, + 'pdf_universal_access' => true, 'landscape' => false, 'native_page_ranges' => '1-2', + 'do_not_export_form_fields' => false, + 'single_page_sheets' => true, 'merge' => true, - 'pdf_format' => 'PDF/A-1b', - 'pdf_universal_access' => true, - 'download_from' => [], + 'metadata' => [ + 'Author' => 'SensioLabs HTML', + ], + 'allow_duplicate_field_names' => true, + 'do_not_export_bookmarks' => false, + 'export_bookmarks_to_pdf_destination' => true, + 'export_placeholders' => true, + 'export_notes' => true, + 'export_notes_pages' => true, + 'export_only_notes_pages' => true, + 'export_notes_in_margin' => true, + 'convert_ooo_target_to_pdf_target' => true, + 'export_links_relative_fsys' => true, + 'export_hidden_slides' => true, + 'skip_empty_pages' => true, + 'add_original_document_as_stream' => true, + 'lossless_image_compression' => true, + 'quality' => 80, + 'reduce_image_resolution' => true, + 'max_image_resolution' => ImageResolutionDPI::DPI150, + 'download_from' => [ + [ + 'url' => 'http://example.com', + 'extraHttpHeaders' => [ + 'MyHeader' => 'MyValue', + ], + ], + ], + 'split_mode' => SplitMode::Pages, + 'split_span' => '1-2', + 'split_unify' => true, + 'update_indexes' => false, ], 'merge' => [ - 'pdf_format' => 'PDF/A-3b', + 'pdf_format' => PdfFormat::Pdf3b, 'pdf_universal_access' => true, - 'download_from' => [], + 'metadata' => [ + 'Author' => 'SensioLabs HTML', + ], + 'download_from' => [ + [ + 'url' => 'http://example.com', + 'extraHttpHeaders' => [ + 'MyHeader' => 'MyValue', + ], + ], + ], ], 'convert' => [ - 'pdf_format' => 'PDF/A-2b', + 'pdf_format' => PdfFormat::Pdf2b, 'pdf_universal_access' => true, 'download_from' => [], ], + 'split' => [ + 'split_mode' => SplitMode::Intervals, + 'split_span' => 1, + ], ], 'screenshot' => [ 'html' => [ @@ -232,22 +334,11 @@ public function testGotenbergConfiguredWithValidConfig(): void foreach ($list as $builderType => $builder) { foreach ($builder as $builderName => $expectedConfig) { - $gotenbergDefinition = $containerBuilder->getDefinition(".sensiolabs_gotenberg.{$builderType}_builder.{$builderName}"); - $methodCalls = $gotenbergDefinition->getMethodCalls(); - - $indexedMethodCalls = []; - foreach ($methodCalls as $methodCall) { - [$name, $arguments] = $methodCall; - $indexedMethodCalls[$name] ??= []; - $indexedMethodCalls[$name][] = $arguments; - } - - self::assertArrayHasKey('setConfigurations', $indexedMethodCalls); - self::assertCount(1, $indexedMethodCalls['setConfigurations']); + $definition = $containerBuilder->getDefinition(".sensiolabs_gotenberg.{$builderType}_builder.{$builderName}"); - $config = $indexedMethodCalls['setConfigurations'][0]; - - self::assertSame([$expectedConfig], $config); + /** @var array $configurator */ + $configurator = $definition->getConfigurator(); + self::assertSame('sensiolabs_gotenberg.builder_configurator', (string) $configurator[0]); } } } @@ -261,7 +352,7 @@ public static function urlBuildersCanChangeTheirRequestContextProvider(): \Gener #[DataProvider('urlBuildersCanChangeTheirRequestContextProvider')] public function testUrlBuildersCanChangeTheirRequestContext(string $serviceName): void { - $extension = new SensiolabsGotenbergExtension(); + $extension = $this->getExtension(); $containerBuilder = $this->getContainerBuilder(); self::assertNotContains('.sensiolabs_gotenberg.request_context', $containerBuilder->getServiceIds()); @@ -279,7 +370,6 @@ public function testUrlBuildersCanChangeTheirRequestContext(string $serviceName) self::assertSame('https://sensiolabs.com', $requestContextDefinition->getArgument(0)); $urlBuilderDefinition = $containerBuilder->getDefinition($serviceName); - self::assertCount(3, $urlBuilderDefinition->getMethodCalls()); $indexedMethodCalls = []; foreach ($urlBuilderDefinition->getMethodCalls() as $methodCall) { @@ -294,7 +384,7 @@ public function testUrlBuildersCanChangeTheirRequestContext(string $serviceName) public function testDataCollectorIsNotEnabledWhenKernelDebugIsFalse(): void { - $extension = new SensiolabsGotenbergExtension(); + $extension = $this->getExtension(); $containerBuilder = $this->getContainerBuilder(kernelDebug: false); $extension->load([[ @@ -306,7 +396,7 @@ public function testDataCollectorIsNotEnabledWhenKernelDebugIsFalse(): void public function testDataCollectorIsEnabledWhenKernelDebugIsTrue(): void { - $extension = new SensiolabsGotenbergExtension(); + $extension = $this->getExtension(); $containerBuilder = $this->getContainerBuilder(kernelDebug: true); $extension->load([[ @@ -318,7 +408,7 @@ public function testDataCollectorIsEnabledWhenKernelDebugIsTrue(): void public function testDataCollectorIsProperlyConfiguredIfEnabled(): void { - $extension = new SensiolabsGotenbergExtension(); + $extension = $this->getExtension(); $containerBuilder = $this->getContainerBuilder(kernelDebug: true); $extension->load([[ @@ -329,47 +419,34 @@ public function testDataCollectorIsProperlyConfiguredIfEnabled(): void 'metadata' => [ 'Author' => 'SensioLabs HTML', ], - 'cookies' => [], - 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [], - 'fail_on_resource_http_status_codes' => [], - 'download_from' => [], ], 'url' => [ 'metadata' => [ 'Author' => 'SensioLabs URL', ], - 'cookies' => [], - 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [], - 'fail_on_resource_http_status_codes' => [], - 'download_from' => [], ], 'markdown' => [ 'metadata' => [ 'Author' => 'SensioLabs MARKDOWN', ], - 'cookies' => [], - 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [], - 'fail_on_resource_http_status_codes' => [], - 'download_from' => [], ], 'office' => [ 'metadata' => [ 'Author' => 'SensioLabs OFFICE', ], - 'download_from' => [], ], 'merge' => [ 'metadata' => [ 'Author' => 'SensioLabs MERGE', ], - 'download_from' => [], ], 'convert' => [ 'pdf_format' => 'PDF/A-2b', - 'download_from' => [], + ], + 'split' => [ + 'metadata' => [ + 'Author' => 'SensioLabs SPLIT', + ], ], ], ], @@ -378,87 +455,138 @@ public function testDataCollectorIsProperlyConfiguredIfEnabled(): void $dataCollector = $containerBuilder->getDefinition('sensiolabs_gotenberg.data_collector'); self::assertNotNull($dataCollector); - $dataCollectorOptions = $dataCollector->getArguments()[3]; + $dataCollectorOptions = $dataCollector->getArguments()[4]; self::assertEquals([ - 'html' => [ - 'metadata' => [ - 'Author' => 'SensioLabs HTML', + 'pdf' => [ + 'html' => [ + 'metadata' => [ + 'Author' => 'SensioLabs HTML', + ], ], - 'cookies' => [], - 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [], - 'fail_on_resource_http_status_codes' => [], - 'download_from' => [], - ], - 'url' => [ - 'metadata' => [ - 'Author' => 'SensioLabs URL', + 'url' => [ + 'metadata' => [ + 'Author' => 'SensioLabs URL', + ], ], - 'cookies' => [], - 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [], - 'fail_on_resource_http_status_codes' => [], - 'download_from' => [], - ], - 'markdown' => [ - 'metadata' => [ - 'Author' => 'SensioLabs MARKDOWN', + 'markdown' => [ + 'metadata' => [ + 'Author' => 'SensioLabs MARKDOWN', + ], ], - 'cookies' => [], - 'extra_http_headers' => [], - 'fail_on_http_status_codes' => [], - 'fail_on_resource_http_status_codes' => [], - 'download_from' => [], - ], - 'office' => [ - 'metadata' => [ - 'Author' => 'SensioLabs OFFICE', + 'office' => [ + 'metadata' => [ + 'Author' => 'SensioLabs OFFICE', + ], ], - 'download_from' => [], - ], - 'merge' => [ - 'metadata' => [ - 'Author' => 'SensioLabs MERGE', + 'merge' => [ + 'metadata' => [ + 'Author' => 'SensioLabs MERGE', + ], + ], + 'convert' => [ + 'pdf_format' => 'PDF/A-2b', + ], + 'split' => [ + 'metadata' => [ + 'Author' => 'SensioLabs SPLIT', + ], ], - 'download_from' => [], ], - 'convert' => [ - 'pdf_format' => 'PDF/A-2b', - 'download_from' => [], + 'screenshot' => [ + 'html' => [], + 'url' => [], + 'markdown' => [], ], - 'split' => [], ], $dataCollectorOptions); } - public function testBuilderWebhookConfiguredWithDefaultConfiguration(): void + /** + * @return iterable>> + */ + public static function provideExpectedWebhookConfiguration(): iterable { - $extension = new SensiolabsGotenbergExtension(); - - $containerBuilder = $this->getContainerBuilder(); - $extension->load([['http_client' => 'http_client']], $containerBuilder); - - self::assertEmpty($containerBuilder->getDefinition('.sensiolabs_gotenberg.webhook_configuration_registry')->getMethodCalls()); - - $buildersIds = [ + yield 'for HtmlPdfBuilder' => [ '.sensiolabs_gotenberg.pdf_builder.html', + [ + 'webhook' => [ + 'config_name' => 'bar', + ], + ], + ]; + yield 'for UrlPdfBuilder' => [ '.sensiolabs_gotenberg.pdf_builder.url', + [ + 'webhook' => [ + 'config_name' => 'baz', + 'success' => [ + 'route' => [ + 'array_route', [ + 'param1', 'param2', + ], + ], + ], + ], + ], + ]; + yield 'for MarkdownPdfBuilder' => [ '.sensiolabs_gotenberg.pdf_builder.markdown', - '.sensiolabs_gotenberg.pdf_builder.office', + [ + 'webhook' => [ + 'success' => [ + 'url' => 'https://sensiolabs.com/webhook-on-the-fly', + ], + 'error' => ['route' => ['simple_route']], + ], + ], + ]; + yield 'for HtmlScreenshotBuilder' => [ '.sensiolabs_gotenberg.screenshot_builder.html', + [ + 'webhook' => [ + 'config_name' => 'foo', + 'success' => [ + 'url' => 'https://sensiolabs.com/webhook', + ], + 'error' => [ + 'route' => [ + 'simple_route', + ], + ], + ], + ], + ]; + yield 'for UrlScreenshotBuilder' => [ '.sensiolabs_gotenberg.screenshot_builder.url', + [ + 'webhook' => [ + 'config_name' => 'bar', + ], + ], + ]; + yield 'for MarkdownScreenshotBuilder' => [ '.sensiolabs_gotenberg.screenshot_builder.markdown', + [ + 'webhook' => [ + 'config_name' => 'baz', + 'success' => [ + 'route' => [ + 'array_route', [ + 'param1', 'param2', + ], + ], + ], + ], + ], ]; - - foreach ($buildersIds as $builderId) { - $builderDefinition = $containerBuilder->getDefinition($builderId); - $methodCalls = $builderDefinition->getMethodCalls(); - self::assertNotContains('webhookConfiguration', $methodCalls); - } } - public function testBuilderWebhookConfiguredWithValidConfiguration(): void + /** + * @param array $expectedConfig + */ + #[DataProvider('provideExpectedWebhookConfiguration')] + public function testBuilderWebhookConfiguredWithValidConfiguration(string $builderId, array $expectedConfig): void { - $extension = new SensiolabsGotenbergExtension(); + $extension = $this->getExtension(); $containerBuilder = $this->getContainerBuilder(); $extension->load([[ @@ -470,90 +598,34 @@ public function testBuilderWebhookConfiguredWithValidConfiguration(): void 'default_options' => [ 'webhook' => 'foo', 'pdf' => [ - 'html' => ['webhook' => 'bar'], - 'url' => ['webhook' => 'baz'], + 'html' => ['webhook' => ['config_name' => 'bar']], + 'url' => ['webhook' => ['config_name' => 'baz']], 'markdown' => ['webhook' => ['success' => ['url' => 'https://sensiolabs.com/webhook-on-the-fly']]], ], 'screenshot' => [ - 'html' => ['webhook' => 'foo'], - 'url' => ['webhook' => 'bar'], - 'markdown' => ['webhook' => 'baz'], + 'html' => ['webhook' => ['config_name' => 'foo']], + 'url' => ['webhook' => ['config_name' => 'bar']], + 'markdown' => ['webhook' => ['config_name' => 'baz']], ], ], ]], $containerBuilder); - $expectedConfigurationMapping = [ - '.sensiolabs_gotenberg.pdf_builder.html' => 'bar', - '.sensiolabs_gotenberg.pdf_builder.url' => 'baz', - '.sensiolabs_gotenberg.pdf_builder.markdown' => '.sensiolabs_gotenberg.pdf_builder.markdown.webhook_configuration', - '.sensiolabs_gotenberg.pdf_builder.office' => 'foo', - '.sensiolabs_gotenberg.screenshot_builder.html' => 'foo', - '.sensiolabs_gotenberg.screenshot_builder.url' => 'bar', - '.sensiolabs_gotenberg.screenshot_builder.markdown' => 'baz', - ]; - array_map(static function (string $builderId, string $expectedConfigurationName) use ($containerBuilder): void { - foreach ($containerBuilder->getDefinition($builderId)->getMethodCalls() as $methodCall) { - [$name, $arguments] = $methodCall; - if ('webhookConfiguration' === $name) { - self::assertSame($expectedConfigurationName, $arguments[0], "Wrong expected configuration for builder '{$builderId}'."); - - return; - } - } - }, array_keys($expectedConfigurationMapping), array_values($expectedConfigurationMapping)); + $definition = $containerBuilder->getDefinition($builderId); - $webhookConfigurationRegistryDefinition = $containerBuilder->getDefinition('.sensiolabs_gotenberg.webhook_configuration_registry'); - $methodCalls = $webhookConfigurationRegistryDefinition->getMethodCalls(); - self::assertCount(3, $methodCalls); - foreach ($methodCalls as $methodCall) { - [$name, $arguments] = $methodCall; - self::assertSame('add', $name); - self::assertContains($arguments[0], ['foo', 'baz', '.sensiolabs_gotenberg.pdf_builder.markdown.webhook_configuration']); - self::assertSame(match ($arguments[0]) { - 'foo' => [ - 'success' => [ - 'url' => 'https://sensiolabs.com/webhook', - 'route' => [], - 'method' => null, - ], - 'error' => [ - 'route' => ['simple_route', []], - 'method' => null, - ], - 'extra_http_headers' => [], - ], - 'baz' => [ - 'success' => [ - 'route' => ['array_route', ['param1', 'param2']], - 'method' => null, - ], - 'extra_http_headers' => [], - ], - '.sensiolabs_gotenberg.pdf_builder.markdown.webhook_configuration' => [ - 'success' => [ - 'url' => 'https://sensiolabs.com/webhook-on-the-fly', - 'route' => [], - 'method' => null, - ], - 'error' => [ - 'route' => ['simple_route', []], - 'method' => null, - ], - 'extra_http_headers' => [], - ], - default => self::fail('Unexpected webhook configuration'), - }, $arguments[1], "Configuration mismatch for webhook '{$arguments[0]}'."); - } + /** @var array $configurator */ + $configurator = $definition->getConfigurator(); + self::assertSame('sensiolabs_gotenberg.builder_configurator', (string) $configurator[0]); + + $configuratorDefinition = $containerBuilder->getDefinition('sensiolabs_gotenberg.builder_configurator'); + $values = $configuratorDefinition->getArguments()[1]; + + self::assertEquals($values[$definition->getClass()], $expectedConfig); } /** * @return array}, 'webhook'?: string}, - * 'error'?: array{'url'?: string, 'route'?: string|array{0: string, 1: list}, 'webhook'?: string} - * }>, + * 'http_client': string, * 'default_options': array{ - * 'webhook': string, * 'pdf': array{ * 'html': array, * 'url': array, @@ -561,6 +633,7 @@ public function testBuilderWebhookConfiguredWithValidConfiguration(): void * 'office': array, * 'merge': array, * 'convert': array, + * 'split': array, * }, * 'screenshot': array{ * 'html': array, @@ -575,12 +648,7 @@ private static function getValidConfig(): array return [ [ 'http_client' => 'http_client', - 'webhook' => [ - 'foo' => ['success' => ['url' => 'https://sensiolabs.com/webhook'], 'error' => ['route' => 'simple_route']], - 'baz' => ['success' => ['url' => 'https://sensiolabs.com/single-url-webhook']], - ], 'default_options' => [ - 'webhook' => 'foo', 'pdf' => [ 'html' => [ 'paper_standard_size' => 'A4', @@ -614,7 +682,17 @@ private static function getValidConfig(): array 'skip_network_idle_event' => true, 'pdf_format' => PdfFormat::Pdf1b->value, 'pdf_universal_access' => true, - 'webhook' => 'bar', + 'download_from' => [ + [ + 'url' => 'http://example.com', + 'extraHttpHeaders' => [ + [ + 'name' => 'MyHeader', + 'value' => 'MyValue', + ], + ], + ], + ], ], 'url' => [ 'paper_width' => 21, @@ -641,7 +719,25 @@ private static function getValidConfig(): array 'skip_network_idle_event' => false, 'pdf_format' => PdfFormat::Pdf2b->value, 'pdf_universal_access' => false, - // 'webhook' => ['success' => ''] + 'cookies' => [[ + 'name' => 'cook_me', + 'value' => 'sensio', + 'domain' => 'sensiolabs.com', + 'secure' => true, + 'httpOnly' => true, + 'sameSite' => 'Lax', + ]], + 'download_from' => [ + [ + 'url' => 'http://example.com', + 'extraHttpHeaders' => [ + [ + 'name' => 'MyHeader', + 'value' => 'MyValue', + ], + ], + ], + ], ], 'markdown' => [ 'paper_width' => 30, @@ -670,20 +766,75 @@ private static function getValidConfig(): array 'pdf_universal_access' => true, ], 'office' => [ + 'password' => 'secret', + 'pdf_format' => PdfFormat::Pdf1b->value, + 'pdf_universal_access' => true, 'landscape' => false, 'native_page_ranges' => '1-2', + 'do_not_export_form_fields' => false, + 'single_page_sheets' => true, 'merge' => true, - 'pdf_format' => PdfFormat::Pdf1b->value, - 'pdf_universal_access' => true, + 'metadata' => [ + 'Author' => 'SensioLabs HTML', + ], + 'allow_duplicate_field_names' => true, + 'do_not_export_bookmarks' => false, + 'export_bookmarks_to_pdf_destination' => true, + 'export_placeholders' => true, + 'export_notes' => true, + 'export_notes_pages' => true, + 'export_only_notes_pages' => true, + 'export_notes_in_margin' => true, + 'convert_ooo_target_to_pdf_target' => true, + 'export_links_relative_fsys' => true, + 'export_hidden_slides' => true, + 'skip_empty_pages' => true, + 'add_original_document_as_stream' => true, + 'lossless_image_compression' => true, + 'quality' => 80, + 'reduce_image_resolution' => true, + 'max_image_resolution' => ImageResolutionDPI::DPI150->value, + 'download_from' => [ + [ + 'url' => 'http://example.com', + 'extraHttpHeaders' => [ + [ + 'name' => 'MyHeader', + 'value' => 'MyValue', + ], + ], + ], + ], + 'split_mode' => SplitMode::Pages->value, + 'split_span' => '1-2', + 'split_unify' => true, ], 'merge' => [ 'pdf_format' => PdfFormat::Pdf3b->value, 'pdf_universal_access' => true, + 'metadata' => [ + 'Author' => 'SensioLabs HTML', + ], + 'download_from' => [ + [ + 'url' => 'http://example.com', + 'extraHttpHeaders' => [ + [ + 'name' => 'MyHeader', + 'value' => 'MyValue', + ], + ], + ], + ], ], 'convert' => [ 'pdf_format' => PdfFormat::Pdf2b->value, 'pdf_universal_access' => true, ], + 'split' => [ + 'split_mode' => SplitMode::Intervals->value, + 'split_span' => 1, + ], ], 'screenshot' => [ 'html' => [ @@ -763,7 +914,7 @@ private static function getValidConfig(): array public function testControllerListenerIsEnabledByDefault(): void { - $extension = new SensiolabsGotenbergExtension(); + $extension = $this->getExtension(); $containerBuilder = $this->getContainerBuilder(kernelDebug: false); $extension->load([[ @@ -775,7 +926,7 @@ public function testControllerListenerIsEnabledByDefault(): void public function testControllerListenerCanBeDisabled(): void { - $extension = new SensiolabsGotenbergExtension(); + $extension = $this->getExtension(); $containerBuilder = $this->getContainerBuilder(kernelDebug: false); $extension->load([[ diff --git a/tests/DependencyInjection/WebhookConfigurationRegistryTest.php b/tests/DependencyInjection/WebhookConfigurationRegistryTest.php deleted file mode 100644 index 7ad4c678..00000000 --- a/tests/DependencyInjection/WebhookConfigurationRegistryTest.php +++ /dev/null @@ -1,114 +0,0 @@ -}} - */ -#[CoversClass(WebhookConfigurationRegistry::class)] -final class WebhookConfigurationRegistryTest extends TestCase -{ - public function testGetUndefinedConfiguration(): void - { - $this->expectException(WebhookConfigurationException::class); - $this->expectExceptionMessage('Webhook configuration "undefined" not found.'); - - $registry = new WebhookConfigurationRegistry($this->createMock(UrlGeneratorInterface::class), null); - $registry->get('undefined'); - } - - public function testAddConfigurationUsingCustomContext(): void - { - $requestContext = $this->createMock(RequestContext::class); - $urlGenerator = $this->getUrlGenerator($requestContext); - $registry = new WebhookConfigurationRegistry($urlGenerator, $requestContext); - $registry->add('test', ['success' => ['url' => 'http://example.com/success']]); - } - - public function testOverrideConfiguration(): void - { - $registry = new WebhookConfigurationRegistry($this->createMock(UrlGeneratorInterface::class), null); - $registry->add('test', ['success' => ['url' => 'http://example.com/success']]); - $this->assertSame(['success' => ['url' => 'http://example.com/success', 'method' => null], 'error' => ['url' => 'http://example.com/success', 'method' => null]], $registry->get('test')); - $registry->add('test', ['success' => ['url' => 'http://example.com/override']]); - $this->assertSame(['success' => ['url' => 'http://example.com/override', 'method' => null], 'error' => ['url' => 'http://example.com/override', 'method' => null]], $registry->get('test')); - } - - /** - * @return \Generator - */ - public static function configurationProvider(): \Generator - { - yield 'full definition with urls' => [ - ['success' => ['url' => 'http://example.com/success'], 'error' => ['url' => 'http://example.com/error']], - ['success' => ['url' => 'http://example.com/success', 'method' => null], 'error' => ['url' => 'http://example.com/error', 'method' => null]], - ]; - yield 'full definition with routes' => [ - ['success' => ['route' => ['test_route_success', ['param' => 'value']]], 'error' => ['route' => ['test_route_error', ['param' => 'value']]]], - ['success' => ['url' => 'http://localhost/test_route?param=value', 'method' => null], 'error' => ['url' => 'http://localhost/test_route?param=value', 'method' => null]], - ]; - yield 'partial definition with urls' => [ - ['success' => ['url' => 'http://example.com/success']], - ['success' => ['url' => 'http://example.com/success', 'method' => null], 'error' => ['url' => 'http://example.com/success', 'method' => null]], - ]; - yield 'partial definition with routes' => [ - ['success' => ['route' => ['test_route_success', ['param' => 'value']]], - 'error' => ['route' => ['test_route_error', ['param' => 'value']]], - ], - ['success' => ['url' => 'http://localhost/test_route?param=value', 'method' => null], 'error' => ['url' => 'http://localhost/test_route?param=value', 'method' => null]], - ]; - yield 'mixed definition with url and route' => [ - ['success' => ['url' => 'http://example.com/success'], 'error' => ['route' => ['test_route_error', ['param' => 'value']]], - ], - ['success' => ['url' => 'http://example.com/success', 'method' => null], 'error' => ['url' => 'http://localhost/test_route?param=value', 'method' => null]], - ]; - } - - /** - * @param array{success: WebhookDefinition, error?: WebhookDefinition} $configuration - * @param array{success: string, error: string} $expectedUrls - * - * @throws Exception - */ - #[DataProvider('configurationProvider')] - public function testAddConfiguration(array $configuration, array $expectedUrls): void - { - $registry = new WebhookConfigurationRegistry($this->getUrlGenerator(), null); - $registry->add('test', $configuration); - - $this->assertSame($expectedUrls, $registry->get('test')); - } - - private function getUrlGenerator(RequestContext|null $requestContext = null): UrlGeneratorInterface&MockObject - { - $urlGenerator = $this->createMock(UrlGeneratorInterface::class); - $originalContext = $this->createMock(RequestContext::class); - $urlGenerator->expects(self::once())->method('getContext')->willReturn($originalContext); - $urlGenerator->expects(self::exactly(null !== $requestContext ? 2 : 1)) - ->method('setContext') - ->willReturnCallback(function (RequestContext $context) use ($originalContext, $requestContext): void { - match ($context) { - $requestContext, $originalContext => null, - default => self::fail('setContext was called with an unexpected context.'), - }; - }); - $urlGenerator->method('generate')->willReturnMap([ - ['test_route_success', ['param' => 'value'], UrlGeneratorInterface::ABSOLUTE_URL, 'http://localhost/test_route?param=value'], - ['test_route_error', ['param' => 'value'], UrlGeneratorInterface::ABSOLUTE_URL, 'http://localhost/test_route?param=value'], - ['_webhook_controller', ['type' => 'my_success_webhook'], UrlGeneratorInterface::ABSOLUTE_URL, 'http://localhost/webhook/success'], - ['_webhook_controller', ['type' => 'my_error_webhook'], UrlGeneratorInterface::ABSOLUTE_URL, 'http://localhost/webhook/error'], - ]); - - return $urlGenerator; - } -} diff --git a/tests/Enumeration/EmulatedMediaTypeTest.php b/tests/Enumeration/EmulatedMediaTypeTest.php new file mode 100644 index 00000000..c2aa8976 --- /dev/null +++ b/tests/Enumeration/EmulatedMediaTypeTest.php @@ -0,0 +1,20 @@ +assertEquals( + ['print', 'screen'], + array_map( + static fn (EmulatedMediaType $case): string => $case->value, + EmulatedMediaType::cases(), + ), + ); + } +} diff --git a/tests/Enumeration/ImageResolutionDPITest.php b/tests/Enumeration/ImageResolutionDPITest.php new file mode 100644 index 00000000..35c9190d --- /dev/null +++ b/tests/Enumeration/ImageResolutionDPITest.php @@ -0,0 +1,20 @@ +assertEquals( + [75, 150, 300, 600, 1200], + array_map( + static fn (ImageResolutionDPI $case): int => $case->value, + ImageResolutionDPI::cases(), + ), + ); + } +} diff --git a/tests/Enumeration/NodeTypeTest.php b/tests/Enumeration/NodeTypeTest.php new file mode 100644 index 00000000..d2a4bf03 --- /dev/null +++ b/tests/Enumeration/NodeTypeTest.php @@ -0,0 +1,20 @@ +assertEquals( + ['scalar', 'boolean', 'integer', 'float', 'enum', 'array', 'variable'], + array_map( + static fn (NodeType $case): string => $case->value, + NodeType::cases(), + ), + ); + } +} diff --git a/tests/Enumeration/PaperSizeTest.php b/tests/Enumeration/PaperSizeTest.php index 4912a11a..3541380c 100644 --- a/tests/Enumeration/PaperSizeTest.php +++ b/tests/Enumeration/PaperSizeTest.php @@ -2,14 +2,29 @@ namespace Sensiolabs\GotenbergBundle\Tests\Enumeration; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sensiolabs\GotenbergBundle\Enumeration\PaperSize; +use Sensiolabs\GotenbergBundle\Enumeration\PaperSizeInterface; use Sensiolabs\GotenbergBundle\Enumeration\Unit; -#[CoversClass(PaperSize::class)] final class PaperSizeTest extends TestCase { + public function testCaseListIsCorrect(): void + { + $this->assertEquals( + ['letter', 'legal', 'tabloid', 'ledger', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6'], + array_map( + static fn (PaperSize $case): string => $case->value, + PaperSize::cases(), + ), + ); + } + + public function testItImplementsPaperSizeInterface(): void + { + $this->assertTrue(is_a(PaperSize::class, PaperSizeInterface::class, true)); + } + public function testUnitIsAlwaysInches(): void { foreach (PaperSize::cases() as $size) { @@ -17,7 +32,7 @@ public function testUnitIsAlwaysInches(): void } } - public function testWidth(): void + public function testEveryCasesHasWidth(): void { foreach (PaperSize::cases() as $size) { $size->width(); @@ -25,7 +40,7 @@ public function testWidth(): void } } - public function testHeight(): void + public function testEveryCasesHasHeight(): void { foreach (PaperSize::cases() as $size) { $size->height(); diff --git a/tests/Enumeration/PartTest.php b/tests/Enumeration/PartTest.php new file mode 100644 index 00000000..46c3adcb --- /dev/null +++ b/tests/Enumeration/PartTest.php @@ -0,0 +1,20 @@ +assertEquals( + ['header.html', 'index.html', 'footer.html'], + array_map( + static fn (Part $case): string => $case->value, + Part::cases(), + ), + ); + } +} diff --git a/tests/Enumeration/PdfFormatTest.php b/tests/Enumeration/PdfFormatTest.php new file mode 100644 index 00000000..bfc3f44b --- /dev/null +++ b/tests/Enumeration/PdfFormatTest.php @@ -0,0 +1,20 @@ +assertEquals( + ['PDF/A-1b', 'PDF/A-2b', 'PDF/A-3b'], + array_map( + static fn (PdfFormat $case): string => $case->value, + PdfFormat::cases(), + ), + ); + } +} diff --git a/tests/Enumeration/UnitTest.php b/tests/Enumeration/UnitTest.php index ae618aef..601fa4bf 100644 --- a/tests/Enumeration/UnitTest.php +++ b/tests/Enumeration/UnitTest.php @@ -2,12 +2,10 @@ namespace Sensiolabs\GotenbergBundle\Tests\Enumeration; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Sensiolabs\GotenbergBundle\Enumeration\Unit; -#[CoversClass(Unit::class)] final class UnitTest extends TestCase { public static function itCanBeParsedCorrectlyProvider(): \Generator diff --git a/tests/Fixtures/assets/pdf/other_document.pdf b/tests/Fixtures/assets/pdf/other_document.pdf new file mode 100644 index 0000000000000000000000000000000000000000..09763fa6cc63e9a8feb39c0036237e98576e3646 GIT binary patch literal 13624 zcma)j1yq!47p}B`fV6n7J#Lm3EG=C%z`!$T{}w~ z0Ii_0jiou%-kc7NS=PqVz+N8$6DpWOb(vwd0COOa1NP*XHq_EWNY@SmpcUcjVP8aT6mOp!k z+6_9KJV(PrHU5bEkGg>VN?Fm_3Ibr3)ir`;Di5)>w71cR*aBe9gEdND0b&Qx_|+q3 zMTnCffLY8OrYP{oUGR^)m?j#tu#=srg55*sV5XvAz(eKbVKrtJv9z#zkcqGYSbxhN zq*4$AsIGve6F`FnCS(VK032K(*fN4JZHR@PE#RRk@@UKob~g6`22bc zVE<$JKk|9__y^|x%E$I$IeVCQSl=a}2DSi=hqUE2|LQ#O!TEpL{q`qp1~G^Eet?R_ zZwbsXfa}2;wiG}Emdhu7`lI@=?)}62?=C6YKwzMfwl{~Bo(1sB{J*OIx9OCGnnPh-*Z6zQ zKy?2oAuK#;U2_;Z|Ecz?R{y2UN%y;5|0U$21N;&BU(EnMfbx&Z{RRo}7j*xIl7}Mw zUuyf1oxG(btfUfuHtVmnrD4+|0danS-d{q%uR_5PBPR4<4EW{yVMzY0vts?QnhveFzRl z@8s;{M7z9eC`RZE<-i)by}w?*Ug$f>S+Xr2E>b8cmS)s`{FIV{k3SC)mHZbqzat42Bqa7Q#L|1lrvT%OXAXFqJG)8S}#N2w3U0A^*WW5?l zA!)l=JK{ktbxwBDlEtUTgr?UgdP{n_-ETCc*?9B)$MO-EP%9z?oq!>IYRSoIT;Xt2 zzWM-3hk8P}R zDDJK6b4aRWZlqsgz89gsEt9)o4wP(L&LRiCmIvJUzfjun6W*!<%2(k+(Lll8Ux``L60 zBB?cw(eC?q<*6%J0zX6b-|Vp7l$75g1;YWyS+Rq-e^9apatwjRb9e+>y_H&Q12+RZ zkpx@AtBV{0zsAJa1UMmZX49!op<{m@G=@KkW)V5%Sa`H|ENoStb-u0l?0#c;Cmw2^EnzY4yYA?4;Vob_o*bqj4 zTo8VFs|vPyA2a(t2WqEPUNXFj_ECA)`m_cbll*B}b{A@mbT08x?%0&t5-uY>9Ic#t zb3t7tvaV^z`;>m;Y_e{u^L+(Zb*}>WC5Sn}h4PEemlbbJ86##}MbKy3@aAAG1|WJW z8jZ8bu6Izn`ZxYaqv^U4Om-=g@)9X&8OzUu7}d#Y=}G*@p&077@_r@;V17ZVQQ8#i zFSu=4yYJhY5O}_x&l?-2@R`&bIb5G?04y!B&ATtgEX+r%Oe%i%F@(;WCRcFDB@emo zr2c$QF+X7&M&IZm|1)UZ&Wn+;(yLkA&|O1@C;20p&x}<(dKsNc9V^PLlJPjT3xx~* z{_=B~G+Jm&2Y%>b=;_d2QznK&%p`8^XZi_2F)^<%b7bPhwx^QNvs{#tXdcGBI=VLN zNw70STdyO|shWzp;VS_y+02sh?o(U{S5%Vidm64HrbhqIeWLNG5pPzppYnfYAbbNo z%ann@Z^X)tl!6MsL3Io9Q^Sao2tx~@yH!eoHgbH0Bel-&c>*3|ugu<0eWu;I!AHm#ir;b9-?zAjlCRiUBJH`SWK5rK}YNom3lUR79R}%#M7lY zab@=kffYAN=R9}AYDpLzBZxdH&Gck>nsl(K1Ek>AmS8R-puJf$*>{G(fGU&$Vfu{vjwsgX> z(tPC%pf7U#nlyLM3}i?4Ig+2oRr@yW_|(^1>zV~g%JB7w-_G&NNko&EU^Eex9%iJH z+sofkooBmnKA(1u^QW6|aiNfjp3+Cz*)BS7+;N?AnY*srPa;eBGEtLcbX1x?++42@ zo~tl#V&YQubVug~CMd0KTT&@`=1bDu7>f6rUkFmU;Tm5fkBo+IZN?ZK!kc47^pLVq zruwH#Hb;Yu$rlA=6zJQst%~(88=*UiF*stn>ysU3YXF{*Zn4czx0ylTt@ST_)vT7e z!#?Vq)+R%~ms`JVvhJkTIk?9!Gb%96m@sh(`H~|lcdbj1$-o^GHsLTqWip=rmP9CL zOIf`yTg;Ct+PPMrls633K>@rHyqJjZmbf$;}Uy_cxzc@77q^_l$`nFEkS zcKr19DN3DEV}eoElEF^a^>)Ms&Lz(D&Me+Xt4i^d4?Q}aVI`Q1nqn#w`p=q-4te`Z z8PdW6*7>S6e+YgI^h6uP8uQ?mT&^->kI*bvq*K`n2``@}d&%tb>_ga*9p>=#GME{? z(pK(VdYxk3CNISDJNZ_%JxVQTPi>(LEz=c=$J?V#+H&l5Vuj0e|6TU`;p-C>(}a#? z_|!qo!%et3$$-Rk;YwP9zW1exVL~HJx(Gi6sg;gszqrvXXSQo;6fJ(J2!9ef^n9}Q zg9pFL7;bGEZ#FZOPeR}e{A8(~)DPr(f1U!f&CSE@8v@O@jv@PUi{NI;t7o@hAIm5E zp9;}m`!&X~cB-S4b*i4Py2mf+r&8CjsuFh%f5;;$_0b%du3oOZp7Almb@kfQ$*4j2 zkrAxWq}8N0TYMunTmECEXra&aa`8qClfRA0OCCU*I(brIpaj zPJ^VjMcXsv#&q_buAgwtK7T`#36#9Uy(ehl*p zZCQfPqX7RoX^A3H>HwM`lA$p;CATee%~)G+%Co;b`~31e@V3Ydo<0+0TYu5VyNs3kCA=gP8)B&tnZI>o%%t`iVvB3U4~zku6g z5z2GH{zFNRJS-n05b+0vjj*R!1&~AJh_TDHHhg-NfJ`Ro1};xy>>`Al@HYAE5InX6 znaPk>MP*>@#>lW^+MD=vt@{n$4L7bT$&C1;AOS`2M6KW94gU{eIP+$QmXE>*1z%^A z7}C>w_t(2=m$DiU%a#Pl>`i(@Bayxov9 zjH$P{4WZ@&+dV{~tH)56;bW#JV7gE5bWQJ8u`9%yvx|V1(T!xPlFIFKtKWnvm9jFf z@|{^Kh*00Lm27t#F7-vl1izvF#5UbrP~2(`uODUbX3A9A8jn}JXAhpzJ2M>P>sA**rz{LQm2ay@jbiaK zxhy$Bg{;_-hOoKt?bN+s&!&qTI3)-B*`T~Mh77#<7)HIq8Y-eF_31OOKcg3+^2sV~ zPfd^_w-firX0jfw>0Hl8FV=-jz@jT)&AZWUy!1d_1LQ8*OmFHVTPBL5n5x2iz3ce? z{(H1*fBmyEIXT*ijO5!wT?3j4>+Ad%*N3TQ_dRF&4DkvLmP8^1K!asKz?hvR&$LO8 zS!(v}maajRU`$SeM@o26-@F+uI6c{Yo&{vPW_`W!V4PajxJ4{I=JA6C6v8DLW|M3n za>K&F#Y+b1LRvzVxnTkAj;^JwH42g1zMT5TX@4EAYrsC(J{uuuLrs%Ct#AT#9FK{XUi28ZIxFkj>+>xjAb)mYEG8v9OE)J&Dnh`A_de=7%I>#!xce95 z6TtZ{q%%~RD;7|ntd;O*>x3lM+?ywEAB5FpzIgPqRChP7o{@elirdG7KwdcLOMmg0 zW~q+#WvT0D3FO-tew=|-W6sBR{ZZGTXqcsLz&e45SzcI+Y`|Y5@#P!muKxFepZt=f zh=N(Ivr6gc_}^kQSV=pH`$s|Y{pjA?2NV!wbPHkNYw>(wQlW;=;+fjf=qV{>2057v4&l)(E)5{l zUxV}I8(jaWxOIOznufr&<(Dh+A)?rP?&Bf)Uit@QEpoae#G$tfc!AVy`)blrB8xSl zI8w;BHE5pEN(zWfDGHyr8%W9A?M@Kq8*)e@!t-Ap)>D3%K%3AX*9XBp5k0~tB>g1yJ6t_B7k{cD9c_b~N7ueD5vDUaf{P#qTqWJ8gYHhmvIbDn zy|Qq_LBg5Baq+M6FbC+MjAWOJnM6m&nuf{e#1?uGkOVr-bvy|wdfo8)_OPhV+H-eF z*|n)%r+vBJ)4R+6o$-H_-T~@ zV#Z$%EXmcmB3d=Xi_32`H5@7|O0p)KZ#`K$Pk-HV)Jn8EvT(F?{E5SGQe2GWW5O+` z$m)sFcT7$E%CC()vHR6c@=_KJU>yz>F2CI|N`>NnsBO8UO#=PYY(?v}Z%cpNj%^FQ zFDHQuKHQcn{bVo(zFR4M9Xxl+f{5-Xrv>jZ!}peJLvbc}1aE-liUIR6wnGBpwUId+ zX8qsDR7^1K;5VIvHH+3QB3|>fAd>_JkGM$IGr#QHwxh*gU#E!~Tg$4duNs&cpfCk? zWf1k0UVw^COBCSkrR;Ziz3rR16XJ>*PgQyY+dni^(U8<=D!(=qcIr-G5C+tSTh!Ju zak(-0R91e&$Z2zf!ohbR7?pY4KTYqjN%3HywkdjcSG{*zVF=e`}L-UF|sv8 zPdmFrm2&b_-UcdqFqn64@5f5QT|bsX%|5xUX!%W4U*F?wm+X2Km4GIhoHzBaR+_#X zS3+vmgAmgedB=sI^{hQv8^VdH=fzOZW7V)?IpA4M1xK|j#;Ziz43^7^&|px~lm|Oy zzI02pJQ&G4Sp_} zyWjJWT=JODx)q(tQs#^3MGPbRqAo*Usz%iBaLrIfl$0*nqjPR(v~ED>za{Bd$`Rs5 z@YYb$1@6uKVmGSigw6mxN$cTB&#Aj@!H~O~#g_#+ zY&k#u3NC$*d~i)B)kxIh8-C9XtO}-33CHbm63cY;rn_MC1~OG8`7hBMFLU!R!nNG> zQ(ZQB+9I6vT|4DEG%jm6z229yj+#|+bl3GVhNqD5^)-Qp6NxS(k6VxBhe!rU+zKE@ zH_Mlf@%`ma8<^d_36kriZdKP5OY3(??c7)BgC8#*XNXDYWxSD z0PK>h8g4gV95iEQjKYp4h>1_$wxi<46Aadr%E@i?WsN6@N$q`p^ug-=#Z5^ST%ed% z=lJ?$=(BB3b}xsajH>Pw>H;R-^aipiiu|d%h;+3L-Wt#K@JodVUYk`CZCB7L5A}A= zOco>ha52}*Z{btBDtxy{A@?^+u1v~%J&cY{o!2$dUTh{gUT=fjUiZpP85;4wuGu*f zGg3HZ_xWPTVpND+#k$BKIECJe8<#cLfr#^_5IQOiaP>&*hld-=VO#WVHcHVo%q$Fx&yB^9?RrUS1u5G+ zI{(I*3)LQ-Lz)7rJgR&vpDDc&0cM2>RRLd~u+-j31_E6Cw4QM%JK~TqyIi^8r6}R! zwWEM@>WpP(hy00ZH7=5o-g#w_?bjHZa+>wS-43cv-Gp(QQ~gYoXH2FEwqaHC zJ$wXCOUhRQ*ymZ8+~z7G8Xl; zc2$Og;uCR9UxlYUXPb&Q90XQgAiBx7SSx?_TXE8oibMYtleH1(7r7I}P>nn;qN0XC zM_E$3x!W}Sj?2Gx@|`KYu!S!8U7z8bs_DkA#=d^*R&&%uy1pG*(%`O5>wp}w$d8@T zIASrH(a7I_pi(1POm7>m)i>dvyM9D93engY74HzZIGdloy*77Uw|QE%a=sd|Op8Tb z#oj;SuN=0_d=`I!{jDXfal+5>X;lDcX8>Y+gengwQKg5LN!!Qf(tPfAJ8$54baE{2 zfnIN+cQya&vv#_1jehd0pB09aN>izFC19$?k~wC#g3^Wf)P6ANWW5B>T|q!Rnitm= zFK2Hm;6gCAB(-Kt8pzO~ea&Zqw%f&S&;%S@Xb?W_rb z@C-%l<211_tM29%H8by>!)B0@Wu~^q7-1K_N_#y6i%j181U`-iE&HCLV)}TB{>)c) z>B;_P$>E|_y(1x2Jw4qsl|<3<`A^lPzbzo3;qUH~YuUJey>m%~FOl(p& z^1La&rv`~pU&2|tWyuWqyTwNwc$K1S zHojapN2~3z>!k&1sF5|%exJFe$)*=EyZe@1Bi zRZP75C~oada;(!N7r)0dUk>7`p1{gZeaG0EXRgl9yEsYPGKxh@9~{OWl(HYKY<>K>L@K$yV1z+tS^uQvt%0Po zH(mLH7nS2H&yaL$EKwGtZ~MCh8j@zEp(`g&f}9-LwFb1N25uE1e6cq*4D?lrdkjNX znywH7buGAg&G>ki^&YXMCvOcbfV zez!^$UO>D;q=;^o$-R<<@Qe)JA)A@on$4A#_)@a5UkE7Y|@*S<_~PDG4ITGE3bG;5#F zND-R2LfOh5Y4H=ndA>LjZ+_;4UpCI0U$Tv}!iM81mH=OoH&`1{7{G+0C92u6TSVf7 zP&Un*OF~_qMgPHcTYRNr>ydVo#^WLa`JkGAV_0dZjaO@+5>Ar#Pbm^^%2zN3Flk>74jmLYjhsU zBQ-R*j2zyTj1QI*KTkLhk>(KHqS7CIq&kAQUECyTWifWBKfszm z6*@S!pnFm-F~}Y5!k&otMnRSn;J3BNZUJ|Q3#e{BOL?1K2V>|R=i9<7C@0bNK6m2G z2##a)9g8^Uqa__!+xAj7cYO{keK_aim@6+&kPj7H6kOAIa~eKeZ;f<}Y@4qTc6{BE zxI#aqpF>@cIe>4Eclxk2p_S)z!h2|W0(VGqRdR-Qo95tkAMfD9M|H&F{`dyP9q}fd zcUmjoQ~W0V4Bj(S=7Z>#!iwCLq-zi|lw3Av#Eb7>`}cK!eRlHNb7=y0-G4pUZn{T5 zKSB88>GH%q%KrAj&H3JTN*x^OK}iWc+KJEAPihRvCY~5SEnS{*N;rLk{!c}@4gu89 z@&Z{^`T>d95Z(Nd1eMwrZh29=M`B}9;kq?(byw9tLoj*6-mLlb zB7N_?KF%QO-ql31iA>LvzG6THyR#d~DcC>1e{|Q{z1;1UbsX__;;r^0DJ1vw_P{R5 z3un)aDdowqvwfc{cQ@)`%s9Rdm2a%Fmt8kDsWJk4i?Vi&X^w)kAG3Gf-92qrEM{1h zuu?5_gUcX)C9kP*d3(s((Y_PHf`0!IZT5Re{n5y!+w-7T%jk>&CX2mZU%M@-H$xMh=Rrkj;$mpMFR~#r#O|B?jE;O;8kFnt=~tQ1o+|C zI$HKCGQ7*6ZZ^*3_FhJZMtb^S-;30rnP)VV1{Sy7xV#dQXDKB2xmLZYvASd9d`|Z+ zB&s=bUj+2@=r;04fHd5)aN3Q#dWao|6RBkR6J10O2^z{4V{m(@c5qasdCv?mR%?k6 zoAFHxt3gDZNy3@1Frkw9>cOZG71Hp*4_nR<0?T!df%4KlTbd9wPfTGU-7O~65u{h; zIJT8xjz8(w-j&8vK6OJ=6H&fHS5w;!38vfW{2{~d0JOpw$IL}|$6YAJPo6*egbMRC z|D&;Kls$b04SfWbFk#931*e^R>hm(|ET@K(%M)IfnEGR6#Lq&!FIYAFd}0I&8FF#2 z23`fDH5{W>ci{>YzkL5ZSSnW1otEPH8#ebSV0M#w(H2%xHl)hac+py0J2mH>FpF|O z6Ml#%La(S^xQO13s2&h+5Sw|YW)}N2<{fqK&=?2+mI%m^bCJza)07wh zQX$Z|LwbP2ai-?uA0lWJdm`hy0yf`7nG78EvvX)V87m~3cw|2{7lzo=X|_sy%{!>J z?@5HuOKKAKLPuOf??(hi32F${(H@=UYEk#we~VRLWzbz~nx z*k^oUN~6l2(vUJ;?l}C)SL{*ShKD_^Ar;@a;|LF5b$ge8S%B`d{}iz8STNXNuNf>Y zWvk#o`GT-PYUn=7qBEmAqt9tP%0V>uB+cKVOTEj*ho6n$SxG3I&%Ta**fB4%Jr7G@ zt}KUD*_xR==+VN9pQezH7&CM~;dElw-gF3jdf}|I%d=&V@Rb6UC+hqWx-i*iAI2Na zSbO-d6m$bEUU-hWA^^cENFxYuKnDdp6CTP#B+jA_5F{!rmvsnm!5n^<-y-pbx*6tJlI<)9e5R6j+Tfo{V^5D%=_kNY~vzkwlBM8TWg_QVf*RrC-{oiCoQTt!; zryF<{U?LgLEDMl2etL85UG1lKM&ukP%6}~wrZnn7vA{k5E{*}W=LOnh=9vRQUd}!; z%*$$iGPFz3Te2rH*8;rwYw5D0y#1P4;VExDNOoq>tC?ck-p;h7Rp+J6_tS4z%j$!= zB?Q7c1&j)-9vN5{R^b_V6dtohI%f^EW$#>;CcJ1?L%GZ?*vrDqxLB;t3a^!~$CD|L zhhCn@<~)mb(aoLf-0|m@A2jJkiU@q4#-{f~PP@$2;}46w!;Y zjLzww)O~eKEn3?6S<>Kg?T6Lwf6SJR@vM2ELB6fCMZN85R%Ppvx_uI}(%ulSOdCLh zbxn5jlBUFVEb6D6k#ygsNy`CEU74bbTlxXpX{r2dfIsGJ&QY8^OSyivIu;h75C`6g z1jLKlXAdXArgS`TBGEz;+?(`+ zCWUSe4-(9pB#9g|oSWF~`5fd_shL$S>|dmXQke0VB;LLGwkfVeEmeMOh$x0~U6Lw?hid5_1YA&c*#n|M?=xhR zM9?(qdgk$V7cpXddVX|IYo<&&EM$q82v~mG=UL4 zq7KZUx?d4vL(72D@Sb-Rk$D`X#!aOyO?Y>4ajUDTzEJ_)H#aM_9WId~Xy2#YU%rcn ztepptoLr-tXMa8J%m6Uo7zzp;&4*>Ml9{X_9Ot(qKqFeWu~uN;!cZ)WE2vwhjp%y1 zIPYjHx<)X{CmJ)q ztv-yo3*h7eG68{L5GNY*!+H-QMi7vl3CzOD#`VDTgqSM>IKfO@oUC9DHW>F=*XkVv zYGiB&U}pz00a>`fFiSBQpA@RkZ((Ex0l?VQ55WoiqG2<#v2ntb*jPCLj9?aaCU#a9 zb})<#3I;Q=bHRwJKo$@i6DJ2O2p9|Z!3;(ag@6FSe-N>O{~{tk=>E3&s|qkKJ&aQe zBf<*k+Cm-_{-4EAu-CKuMO23|tRD;>Xs;kxjxZ*zrKp&Yl&%$wi*5j`3DnN{msr8s z7FLiyS+epFBPfgk?+l>jhn)+6z_`ycHUjpnp&U?eC|#sJevd{`S4 zCNyQ|Ozl}%MG)f+eM>p@I3T0hcA-rD{=4shfOs()BIfXR*tR443o3pGGrtgt7Sgnh z^rJQ?BJl-Y%eR^iVQ{#A5w=)Tvl9PoqY}2_ckMS3#U3k!hHmWc*0a!L9+mWJno$K( z+JdO$cg~sKBHW^{1mYGWv=$G(yz#GPMJJTfkNd6;o-t|>#=A_vHM2zcRsysj_=eE= z^yX(?=REngnrqy$r*lY1*S}}>Zw&C?Z0g^T{SV|Ggs@rp|Hi7Y1?=3&1GN5wNXB=6 z&a8nhY;s`ug>l$_jmiV9U(r&@0{U>&1OWWS!vCw~PBsujG#1ztqWy7<0Coegv$28M z0EU47$bc}~_`?fe@gEs0Oyi$2AlpA>u(LH>FzWt4Y=Qq589NN>|Ih=1SYfmN4_mGW zT>nGH`LIX)L&nbaFIyl?<)3;Fo6f&wod4DXJ&^YQ+Xsx(^lup}`#)m=f>>B#0QfIk zAPD@gSb!jQ*w*+TJv$p+*#2kpaL7pk>H>La5%a@g0Kh{t9(J~0JI}*`i3fhat(~ro U-LGZ>!9Z4aG-_&L84

Hello world!

- + {{ toHTML "file.md" }} diff --git a/tests/Fixtures/templates/wrapper.html.twig b/tests/Fixtures/templates/wrapper.html.twig new file mode 100644 index 00000000..444d61e6 --- /dev/null +++ b/tests/Fixtures/templates/wrapper.html.twig @@ -0,0 +1,13 @@ + + + + + My PDF + + +

Hello {{ name }}!

+ {% verbatim %} + {{ toHTML "file.md" }} + {% endverbatim %} + + diff --git a/tests/Formatter/AssetBaseDirFormatterTest.php b/tests/Formatter/AssetBaseDirFormatterTest.php index 0fcbcc22..932a46fe 100644 --- a/tests/Formatter/AssetBaseDirFormatterTest.php +++ b/tests/Formatter/AssetBaseDirFormatterTest.php @@ -2,13 +2,11 @@ namespace Sensiolabs\GotenbergBundle\Tests\Formatter; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\TestCase; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -#[CoversClass(AssetBaseDirFormatter::class)] final class AssetBaseDirFormatterTest extends TestCase { /** diff --git a/tests/GotenbergPdfTest.php b/tests/GotenbergPdfTest.php index 5edca283..51616bd9 100644 --- a/tests/GotenbergPdfTest.php +++ b/tests/GotenbergPdfTest.php @@ -2,48 +2,12 @@ namespace Sensiolabs\GotenbergBundle\Tests; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractChromiumPdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractPdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClient; -use Sensiolabs\GotenbergBundle\Debug\Builder\TraceablePdfBuilder; -use Sensiolabs\GotenbergBundle\Debug\TraceableGotenbergPdf; -use Sensiolabs\GotenbergBundle\DependencyInjection\CompilerPass\GotenbergPass; -use Sensiolabs\GotenbergBundle\DependencyInjection\Configuration; -use Sensiolabs\GotenbergBundle\DependencyInjection\SensiolabsGotenbergExtension; -use Sensiolabs\GotenbergBundle\Enumeration\Unit; -use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\GotenbergPdf; +use PHPUnit\Framework\Attributes\DataProvider; +use Sensiolabs\GotenbergBundle\Enumeration\PdfFormat; +use Sensiolabs\GotenbergBundle\Enumeration\SplitMode; use Sensiolabs\GotenbergBundle\GotenbergPdfInterface; -use Sensiolabs\GotenbergBundle\SensiolabsGotenbergBundle; -use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistry; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Mime\Part\DataPart; - -#[CoversClass(GotenbergPdf::class)] -#[UsesClass(AbstractChromiumPdfBuilder::class)] -#[UsesClass(AbstractPdfBuilder::class)] -#[UsesClass(HtmlPdfBuilder::class)] -#[UsesClass(MarkdownPdfBuilder::class)] -#[UsesClass(LibreOfficePdfBuilder::class)] -#[UsesClass(UrlPdfBuilder::class)] -#[UsesClass(GotenbergClient::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(Filesystem::class)] -#[UsesClass(TraceablePdfBuilder::class)] -#[UsesClass(TraceableGotenbergPdf::class)] -#[UsesClass(GotenbergPass::class)] -#[UsesClass(Configuration::class)] -#[UsesClass(SensiolabsGotenbergExtension::class)] -#[UsesClass(SensiolabsGotenbergBundle::class)] -#[UsesClass(Unit::class)] -#[UsesClass(WebhookConfigurationRegistry::class)] + final class GotenbergPdfTest extends KernelTestCase { public function testUrlBuilderFactory(): void @@ -55,19 +19,14 @@ public function testUrlBuilderFactory(): void /** @var GotenbergPdfInterface $gotenberg */ $gotenberg = $container->get(GotenbergPdfInterface::class); $builder = $gotenberg->url(); - $builder - ->setConfigurations([ - 'native_page_ranges' => '1-5', - ]) - ->url('https://google.com') - ; + $builder->nativePageRanges('1-5'); + + $data = $builder->getBodyBag()->all(); + + self::assertCount(1, $data); - self::assertSame([ - ['failOnHttpStatusCodes' => '[499,599]'], - ['failOnResourceHttpStatusCodes' => '[]'], - ['nativePageRanges' => '1-5'], - ['url' => 'https://google.com'], - ], $builder->getMultipartFormData()); + self::assertArrayHasKey('nativePageRanges', $data); + self::assertSame('1-5', $data['nativePageRanges']); } public function testHtmlBuilderFactory(): void @@ -78,35 +37,21 @@ public function testHtmlBuilderFactory(): void /** @var GotenbergPdfInterface $gotenberg */ $gotenberg = $container->get(GotenbergPdfInterface::class); - $builder = $gotenberg->html() - ->setConfigurations([ - 'margin_top' => 3, - 'margin_bottom' => 1, - ]) + $builder = $gotenberg->html(); + $builder + ->marginTop(3) + ->marginBottom(1) ; - $builder->contentFile(__DIR__.'/../Fixtures/files/content.html'); - $multipartFormData = $builder->getMultipartFormData(); - - self::assertCount(5, $multipartFormData); - - self::assertArrayHasKey(0, $multipartFormData); - self::assertSame(['failOnHttpStatusCodes' => '[499,599]'], $multipartFormData[0]); - self::assertArrayHasKey(1, $multipartFormData); - self::assertSame(['failOnResourceHttpStatusCodes' => '[]'], $multipartFormData[1]); + $data = $builder->getBodyBag()->all(); - self::assertArrayHasKey(2, $multipartFormData); - self::assertSame(['marginTop' => '3in'], $multipartFormData[2]); + self::assertCount(2, $data); - self::assertArrayHasKey(3, $multipartFormData); - self::assertSame(['marginBottom' => '1in'], $multipartFormData[3]); + self::assertArrayHasKey('marginTop', $data); + self::assertSame('3in', $data['marginTop']); - self::assertArrayHasKey(4, $multipartFormData); - self::assertIsArray($multipartFormData[4]); - self::assertCount(1, $multipartFormData[4]); - self::assertArrayHasKey('files', $multipartFormData[4]); - self::assertInstanceOf(DataPart::class, $multipartFormData[4]['files']); - self::assertSame('index.html', $multipartFormData[4]['files']->getFilename()); + self::assertArrayHasKey('marginBottom', $data); + self::assertSame('1in', $data['marginBottom']); } public function testMarkdownBuilderFactory(): void @@ -121,24 +66,36 @@ public function testMarkdownBuilderFactory(): void $builder = $gotenberg->markdown(); $builder->files(__DIR__.'/Fixtures/assets/file.md'); $builder->wrapperFile(__DIR__.'/Fixtures/files/wrapper.html'); - $multipartFormData = $builder->getMultipartFormData(); + $data = $builder->getBodyBag()->all(); - self::assertCount(4, $multipartFormData); + self::assertCount(2, $data); - self::assertArrayHasKey(2, $multipartFormData); - self::assertIsArray($multipartFormData[2]); - self::assertArrayHasKey('files', $multipartFormData[2]); - self::assertInstanceOf(DataPart::class, $multipartFormData[2]['files']); - self::assertSame('file.md', $multipartFormData[2]['files']->getFilename()); + self::assertArrayHasKey('files', $data); + self::assertIsArray($data['files']); - self::assertArrayHasKey(3, $multipartFormData); - self::assertIsArray($multipartFormData[3]); - self::assertArrayHasKey('files', $multipartFormData[3]); - self::assertInstanceOf(DataPart::class, $multipartFormData[3]['files']); - self::assertSame('index.html', $multipartFormData[3]['files']->getFilename()); + $file = array_shift($data['files']); + self::assertInstanceOf(\SplFileInfo::class, $file); + self::assertSame('file.md', $file->getFilename()); + + self::assertArrayHasKey('index.html', $data); + self::assertInstanceOf(\SplFileInfo::class, $data['index.html']); + self::assertSame('wrapper.html', $data['index.html']->getFilename()); } - public function testOfficeBuilderFactory(): void + /** + * @return iterable> + */ + public static function provideFileToConvert(): iterable + { + yield 'convert odt file' => [__DIR__.'/Fixtures/assets/office/document.odt', 'document.odt']; + yield 'convert docx file' => [__DIR__.'/Fixtures/assets/office/document_1.docx', 'document_1.docx']; + yield 'convert html file' => [__DIR__.'/Fixtures/assets/office/document_2.html', 'document_2.html']; + yield 'convert xlsx file' => [__DIR__.'/Fixtures/assets/office/document_3.xlsx', 'document_3.xlsx']; + yield 'convert pptx file' => [__DIR__.'/Fixtures/assets/office/document_4.pptx', 'document_4.pptx']; + } + + #[DataProvider('provideFileToConvert')] + public function testOfficeBuilderFactory(string $path, string $filename): void { self::bootKernel(); @@ -146,23 +103,139 @@ public function testOfficeBuilderFactory(): void /** @var GotenbergPdfInterface $gotenberg */ $gotenberg = $container->get(GotenbergPdfInterface::class); - $builder = $gotenberg->office() - ->setConfigurations([ - 'native_page_ranges' => '1-5', - ]) - ; - $builder->files(__DIR__.'/Fixtures/assets/office/document.odt'); - $multipartFormData = $builder->getMultipartFormData(); - self::assertCount(2, $multipartFormData); + $builder = $gotenberg->office(); + $builder->files($path); + $data = $builder->getBodyBag()->all(); + + self::assertCount(1, $data); + + self::assertArrayHasKey('files', $data); + self::assertIsArray($data['files']); + + $firstFile = array_shift($data['files']); + self::assertInstanceOf(\SplFileInfo::class, $firstFile); + self::assertSame($filename, $firstFile->getFilename()); + } + + public function testMergeBuilderFactory(): void + { + self::bootKernel(); + + $container = static::getContainer(); + + /** @var GotenbergPdfInterface $gotenberg */ + $gotenberg = $container->get(GotenbergPdfInterface::class); + + $builder = $gotenberg->merge(); + $builder->files( + __DIR__.'/Fixtures/assets/pdf/document.pdf', + __DIR__.'/Fixtures/assets/pdf/other_document.pdf', + ); + $builder->pdfUniversalAccess(); + $data = $builder->getBodyBag()->all(); + + self::assertCount(2, $data); + + self::assertArrayHasKey('files', $data); + self::assertIsArray($data['files']); + + $firstFile = array_shift($data['files']); + self::assertInstanceOf(\SplFileInfo::class, $firstFile); + self::assertSame('document.pdf', $firstFile->getFilename()); + + $lastFile = array_pop($data['files']); + self::assertInstanceOf(\SplFileInfo::class, $lastFile); + self::assertSame('other_document.pdf', $lastFile->getFilename()); + + self::assertArrayHasKey('pdfua', $data); + self::assertTrue($data['pdfua']); + } + + public function testConvertBuilderFactory(): void + { + self::bootKernel(); + + $container = static::getContainer(); + + /** @var GotenbergPdfInterface $gotenberg */ + $gotenberg = $container->get(GotenbergPdfInterface::class); + + $builder = $gotenberg->convert(); + $builder->files(__DIR__.'/Fixtures/assets/pdf/document.pdf'); + $builder->pdfFormat(PdfFormat::Pdf1b); + $data = $builder->getBodyBag()->all(); + + self::assertCount(2, $data); + + self::assertArrayHasKey('files', $data); + self::assertIsArray($data['files']); + + $firstFile = array_shift($data['files']); + self::assertInstanceOf(\SplFileInfo::class, $firstFile); + self::assertSame('document.pdf', $firstFile->getFilename()); + + self::assertArrayHasKey('pdfa', $data); + self::assertSame(PdfFormat::Pdf1b, $data['pdfa']); + } + + public function testSplitBuilderFactory(): void + { + self::bootKernel(); + + $container = static::getContainer(); + + /** @var GotenbergPdfInterface $gotenberg */ + $gotenberg = $container->get(GotenbergPdfInterface::class); + + $builder = $gotenberg->split(); + $builder->files(__DIR__.'/Fixtures/assets/pdf/document.pdf'); + $builder->splitMode(SplitMode::Pages); + $builder->splitSpan('1-2'); + $builder->splitUnify(); + + $data = $builder->getBodyBag()->all(); + + self::assertCount(4, $data); + + self::assertArrayHasKey('files', $data); + self::assertIsArray($data['files']); + + $firstFile = array_shift($data['files']); + self::assertInstanceOf(\SplFileInfo::class, $firstFile); + self::assertSame('document.pdf', $firstFile->getFilename()); + + self::assertArrayHasKey('splitMode', $data); + self::assertSame(SplitMode::Pages, $data['splitMode']); + + self::assertArrayHasKey('splitSpan', $data); + self::assertSame('1-2', $data['splitSpan']); + + self::assertArrayHasKey('splitUnify', $data); + self::assertTrue($data['splitUnify']); + } + + public function testFlattenBuilderFactory(): void + { + self::bootKernel(); + + $container = static::getContainer(); + + /** @var GotenbergPdfInterface $gotenberg */ + $gotenberg = $container->get(GotenbergPdfInterface::class); + + $builder = $gotenberg->flatten(); + $builder->files(__DIR__.'/Fixtures/assets/pdf/document.pdf'); + + $data = $builder->getBodyBag()->all(); + + self::assertCount(1, $data); - self::assertArrayHasKey(0, $multipartFormData); - self::assertSame(['nativePageRanges' => '1-5'], $multipartFormData[0]); + self::assertArrayHasKey('files', $data); + self::assertIsArray($data['files']); - self::assertArrayHasKey(1, $multipartFormData); - self::assertIsArray($multipartFormData[1]); - self::assertArrayHasKey('files', $multipartFormData[1]); - self::assertInstanceOf(DataPart::class, $multipartFormData[1]['files']); - self::assertSame('document.odt', $multipartFormData[1]['files']->getFilename()); + $firstFile = array_shift($data['files']); + self::assertInstanceOf(\SplFileInfo::class, $firstFile); + self::assertSame('document.pdf', $firstFile->getFilename()); } } diff --git a/tests/GotenbergScreenshotTest.php b/tests/GotenbergScreenshotTest.php index bfbca3d6..16a98f88 100644 --- a/tests/GotenbergScreenshotTest.php +++ b/tests/GotenbergScreenshotTest.php @@ -2,36 +2,9 @@ namespace Sensiolabs\GotenbergBundle\Tests; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\UsesClass; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractChromiumScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClient; -use Sensiolabs\GotenbergBundle\Debug\Builder\TraceableScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Debug\TraceableGotenbergScreenshot; -use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; -use Sensiolabs\GotenbergBundle\GotenbergScreenshot; use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface; -use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistry; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Mime\Part\DataPart; - -#[CoversClass(GotenbergScreenshot::class)] -#[UsesClass(AbstractScreenshotBuilder::class)] -#[UsesClass(AbstractChromiumScreenshotBuilder::class)] -#[UsesClass(HtmlScreenshotBuilder::class)] -#[UsesClass(MarkdownScreenshotBuilder::class)] -#[UsesClass(UrlScreenshotBuilder::class)] -#[UsesClass(GotenbergClient::class)] -#[UsesClass(AssetBaseDirFormatter::class)] -#[UsesClass(Filesystem::class)] -#[UsesClass(TraceableScreenshotBuilder::class)] -#[UsesClass(TraceableGotenbergScreenshot::class)] -#[UsesClass(WebhookConfigurationRegistry::class)] + final class GotenbergScreenshotTest extends KernelTestCase { public function testUrlBuilderFactory(): void @@ -42,22 +15,20 @@ public function testUrlBuilderFactory(): void /** @var GotenbergScreenshotInterface $gotenberg */ $gotenberg = $container->get(GotenbergScreenshotInterface::class); + $builder = $gotenberg->url(); $builder - ->setConfigurations([ - 'width' => 500, - 'height' => 500, - ]) - ->url('https://google.com') + ->width(500) + ->height(200) ; - self::assertSame([ - ['failOnHttpStatusCodes' => '[499,599]'], - ['failOnResourceHttpStatusCodes' => '[]'], - ['width' => '500'], - ['height' => '500'], - ['url' => 'https://google.com'], - ], $builder->getMultipartFormData()); + $data = $builder->getBodyBag()->all(); + + self::assertArrayHasKey('width', $data); + self::assertSame(500, $data['width']); + + self::assertArrayHasKey('height', $data); + self::assertSame(200, $data['height']); } public function testHtmlBuilderFactory(): void @@ -68,29 +39,20 @@ public function testHtmlBuilderFactory(): void /** @var GotenbergScreenshotInterface $gotenberg */ $gotenberg = $container->get(GotenbergScreenshotInterface::class); - $builder = $gotenberg->html() - ->setConfigurations([ - 'format' => 'jpeg', - 'quality' => 50, - ]) - ; - $builder->contentFile(__DIR__.'/../Fixtures/files/content.html'); - $multipartFormData = $builder->getMultipartFormData(); - self::assertCount(5, $multipartFormData); + $builder = $gotenberg->html(); + $builder + ->width(500) + ->height(200) + ; - self::assertArrayHasKey(2, $multipartFormData); - self::assertSame(['format' => 'jpeg'], $multipartFormData[2]); + $data = $builder->getBodyBag()->all(); - self::assertArrayHasKey(3, $multipartFormData); - self::assertSame(['quality' => '50'], $multipartFormData[3]); + self::assertArrayHasKey('width', $data); + self::assertSame(500, $data['width']); - self::assertArrayHasKey(4, $multipartFormData); - self::assertIsArray($multipartFormData[4]); - self::assertCount(1, $multipartFormData[4]); - self::assertArrayHasKey('files', $multipartFormData[4]); - self::assertInstanceOf(DataPart::class, $multipartFormData[4]['files']); - self::assertSame('index.html', $multipartFormData[4]['files']->getFilename()); + self::assertArrayHasKey('height', $data); + self::assertSame(200, $data['height']); } public function testMarkdownBuilderFactory(): void @@ -103,22 +65,31 @@ public function testMarkdownBuilderFactory(): void $gotenberg = $container->get(GotenbergScreenshotInterface::class); $builder = $gotenberg->markdown(); - $builder->files(__DIR__.'/Fixtures/assets/file.md'); - $builder->wrapperFile(__DIR__.'/Fixtures/files/wrapper.html'); - $multipartFormData = $builder->getMultipartFormData(); - - self::assertCount(4, $multipartFormData); - - self::assertArrayHasKey(2, $multipartFormData); - self::assertIsArray($multipartFormData[2]); - self::assertArrayHasKey('files', $multipartFormData[2]); - self::assertInstanceOf(DataPart::class, $multipartFormData[2]['files']); - self::assertSame('file.md', $multipartFormData[2]['files']->getFilename()); - - self::assertArrayHasKey(3, $multipartFormData); - self::assertIsArray($multipartFormData[3]); - self::assertArrayHasKey('files', $multipartFormData[3]); - self::assertInstanceOf(DataPart::class, $multipartFormData[3]['files']); - self::assertSame('index.html', $multipartFormData[3]['files']->getFilename()); + $builder + ->files(__DIR__.'/Fixtures/assets/file.md') + ->wrapperFile(__DIR__.'/Fixtures/files/wrapper.html') + ->width(500) + ->height(200) + ; + + $data = $builder->getBodyBag()->all(); + + self::assertArrayHasKey('files', $data); + + $files = $data['files']; + self::assertArrayHasKey(__DIR__.'/Fixtures/assets/file.md', $files); + self::assertInstanceOf(\SplFileInfo::class, $files[__DIR__.'/Fixtures/assets/file.md']); + + self::assertArrayHasKey('index.html', $data); + self::assertInstanceOf(\SplFileInfo::class, $data['index.html']); + + self::assertArrayHasKey('width', $data); + self::assertSame(500, $data['width']); + + self::assertArrayHasKey('width', $data); + self::assertSame(500, $data['width']); + + self::assertArrayHasKey('height', $data); + self::assertSame(200, $data['height']); } } diff --git a/tests/PHPStanRules/AlwaysUsedMethodRule.php b/tests/PHPStanRules/AlwaysUsedMethodRule.php new file mode 100644 index 00000000..5f940344 --- /dev/null +++ b/tests/PHPStanRules/AlwaysUsedMethodRule.php @@ -0,0 +1,16 @@ +isPrivate() && str_starts_with($methodReflection->getName(), 'normalize'); + } +} diff --git a/tests/Processor/ChainProcessorTest.php b/tests/Processor/ChainProcessorTest.php index 7ce289a0..0e6c8243 100644 --- a/tests/Processor/ChainProcessorTest.php +++ b/tests/Processor/ChainProcessorTest.php @@ -2,7 +2,6 @@ namespace Sensiolabs\GotenbergBundle\Tests\Processor; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sensiolabs\GotenbergBundle\Processor\ChainProcessor; use Sensiolabs\GotenbergBundle\Processor\ProcessorInterface; @@ -10,7 +9,6 @@ use Symfony\Component\HttpClient\Chunk\FirstChunk; use Symfony\Component\HttpClient\Chunk\LastChunk; -#[CoversClass(ChainProcessor::class)] class ChainProcessorTest extends TestCase { public function testProcess(): void diff --git a/tests/Processor/FileProcessorTest.php b/tests/Processor/FileProcessorTest.php index af3ce18b..eebfb445 100644 --- a/tests/Processor/FileProcessorTest.php +++ b/tests/Processor/FileProcessorTest.php @@ -2,7 +2,6 @@ namespace Sensiolabs\GotenbergBundle\Tests\Processor; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sensiolabs\GotenbergBundle\Processor\FileProcessor; use Symfony\Component\Filesystem\Filesystem; @@ -10,7 +9,6 @@ use Symfony\Component\HttpClient\Chunk\FirstChunk; use Symfony\Component\HttpClient\Chunk\LastChunk; -#[CoversClass(FileProcessor::class)] class FileProcessorTest extends TestCase { public function testProcess(): void diff --git a/tests/Processor/NullProcessorTest.php b/tests/Processor/NullProcessorTest.php index f2925708..c1394e58 100644 --- a/tests/Processor/NullProcessorTest.php +++ b/tests/Processor/NullProcessorTest.php @@ -2,14 +2,12 @@ namespace Sensiolabs\GotenbergBundle\Tests\Processor; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sensiolabs\GotenbergBundle\Processor\NullProcessor; use Symfony\Component\HttpClient\Chunk\DataChunk; use Symfony\Component\HttpClient\Chunk\FirstChunk; use Symfony\Component\HttpClient\Chunk\LastChunk; -#[CoversClass(NullProcessor::class)] class NullProcessorTest extends TestCase { public function testProcess(): void diff --git a/tests/SensiolabsGotenbergBundleTest.php b/tests/SensiolabsGotenbergBundleTest.php index b2e4b23d..2dde2d37 100644 --- a/tests/SensiolabsGotenbergBundleTest.php +++ b/tests/SensiolabsGotenbergBundleTest.php @@ -2,13 +2,11 @@ namespace Sensiolabs\GotenbergBundle\Tests; -use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sensiolabs\GotenbergBundle\DependencyInjection\CompilerPass\GotenbergPass; use Sensiolabs\GotenbergBundle\SensiolabsGotenbergBundle; use Symfony\Component\DependencyInjection\ContainerBuilder; -#[CoversClass(SensiolabsGotenbergBundle::class)] class SensiolabsGotenbergBundleTest extends TestCase { public function testCanBeAutoDiscovered(): void @@ -31,6 +29,10 @@ public function testCompilerPassesAreAllSet(): void $originalCompilerPasses = $container->getCompilerPassConfig()->getPasses(); + $extension = $bundle->getContainerExtension(); + self::assertNotNull($extension); + + $container->registerExtension($extension); $bundle->build($container); $currentCompilerPasses = $container->getCompilerPassConfig()->getPasses(); diff --git a/tests/Twig/GotenbergRuntimeTest.php b/tests/Twig/GotenbergRuntimeTest.php index 038ddd42..4777ca52 100644 --- a/tests/Twig/GotenbergRuntimeTest.php +++ b/tests/Twig/GotenbergRuntimeTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; +use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractChromiumPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractChromiumScreenshotBuilder; use Sensiolabs\GotenbergBundle\Twig\GotenbergRuntime; @@ -11,27 +12,10 @@ #[CoversClass(GotenbergRuntime::class)] class GotenbergRuntimeTest extends TestCase { - public function testGetAssetThrowsPerDefault(): void - { - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('The gotenberg_asset function must be used in a Gotenberg context.'); - $runtime = new GotenbergRuntime(); - $runtime->getAssetUrl('foo'); - } - - public function testGetAssetThrowsWhenBuilderIsNotSet(): void - { - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('The gotenberg_asset function must be used in a Gotenberg context.'); - $runtime = new GotenbergRuntime(); - $runtime->setBuilder(null); - $runtime->getAssetUrl('foo'); - } - - public function testGetAssetCallChromiumPdfBuilder(): void + public function testGetAsset(): void { $runtime = new GotenbergRuntime(); - $builder = $this->createMock(AbstractChromiumPdfBuilder::class); + $builder = $this->createMock(BuilderAssetInterface::class); $builder ->expects($this->once()) ->method('addAsset') @@ -41,71 +25,35 @@ public function testGetAssetCallChromiumPdfBuilder(): void $this->assertSame('foo', $runtime->getAssetUrl('foo')); } - public function testGetAssetCallChromiumScreenshotBuilder(): void + public function testGetFont(): void { $runtime = new GotenbergRuntime(); - $builder = $this->createMock(AbstractChromiumScreenshotBuilder::class); + $builder = $this->createMock(BuilderAssetInterface::class); $builder ->expects($this->once()) ->method('addAsset') - ->with('foo') + ->with('foo.ttf') ; $runtime->setBuilder($builder); - $this->assertSame('foo', $runtime->getAssetUrl('foo')); + $this->assertSame( + '@font-face { font-family: "my_font"; src: url("foo.ttf"); }', + $runtime->getFont('foo.ttf', 'my_font'), + ); } - public function testgetFontThrowsPerDefault(): void + public function testGetAssetThrowsWhenBuilderIsNotSet(): void { $this->expectException(\LogicException::class); - $this->expectExceptionMessage('The gotenberg_font function must be used in a Gotenberg context.'); + $this->expectExceptionMessage('The gotenberg_asset function must be used in a Gotenberg context.'); $runtime = new GotenbergRuntime(); - $runtime->getFont('foo.ttf', 'my_font'); + $runtime->getAssetUrl('foo'); } - public function testgetFontThrowsWhenBuilderIsNotSet(): void + public function testGetFontThrowsWhenBuilderIsNotSet(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('The gotenberg_font function must be used in a Gotenberg context.'); $runtime = new GotenbergRuntime(); - $runtime->setBuilder(null); $runtime->getFont('foo.ttf', 'my_font'); } - - public function testgetFontCallChromiumPdfBuilder(): void - { - $runtime = new GotenbergRuntime(); - $builder = $this->createMock(AbstractChromiumPdfBuilder::class); - $builder - ->expects($this->once()) - ->method('addAsset') - ->with('foo.ttf') - ; - $runtime->setBuilder($builder); - $this->assertSame( - '@font-face { - font-family: "my_font"; - src: url("foo.ttf"); - }', - $runtime->getFont('foo.ttf', 'my_font'), - ); - } - - public function testgetFontCallChromiumScreenshotBuilder(): void - { - $runtime = new GotenbergRuntime(); - $builder = $this->createMock(AbstractChromiumScreenshotBuilder::class); - $builder - ->expects($this->once()) - ->method('addAsset') - ->with('foo.ttf') - ; - $runtime->setBuilder($builder); - $this->assertSame( - '@font-face { - font-family: "my_font"; - src: url("foo.ttf"); - }', - $runtime->getFont('foo.ttf', 'my_font'), - ); - } } From b2ab0ade94f09cc080999e96ecbd14b4960e2898 Mon Sep 17 00:00:00 2001 From: "hubert.lenoir" Date: Thu, 10 Apr 2025 17:57:10 +0200 Subject: [PATCH 02/30] fix(doc): annotations --- docs/pdf/builders_api/ConvertPdfBuilder.md | 30 ++++- docs/pdf/builders_api/HtmlPdfBuilder.md | 124 ++++++++++++++---- .../pdf/builders_api/LibreOfficePdfBuilder.md | 58 ++++++-- docs/pdf/builders_api/MarkdownPdfBuilder.md | 124 ++++++++++++++---- docs/pdf/builders_api/MergePdfBuilder.md | 30 ++++- docs/pdf/builders_api/SplitPdfBuilder.md | 48 ++++++- docs/pdf/builders_api/UrlPdfBuilder.md | 124 ++++++++++++++---- .../builders_api/HtmlScreenshotBuilder.md | 49 +++++-- .../builders_api/MarkdownScreenshotBuilder.md | 49 +++++-- .../builders_api/UrlScreenshotBuilder.md | 49 +++++-- src/Builder/AbstractBuilder.php | 4 +- src/Builder/Attributes/SemanticNode.php | 4 + .../Behaviors/Chromium/ContentTrait.php | 4 +- .../Chromium/CustomHttpHeadersTrait.php | 8 +- .../Behaviors/Chromium/FailOnTrait.php | 3 +- .../Chromium/PdfPagePropertiesTrait.php | 34 ++++- .../ScreenshotPagePropertiesTrait.php | 5 +- .../Chromium/WaitBeforeRenderingTrait.php | 5 +- src/Builder/Behaviors/DownloadFromTrait.php | 5 +- .../LibreOffice/PagePropertiesTrait.php | 4 + src/Builder/Behaviors/PdfFormatTrait.php | 2 +- src/Builder/Behaviors/SplitTrait.php | 16 ++- src/Builder/Behaviors/WebhookTrait.php | 20 ++- src/Builder/Pdf/ConvertPdfBuilder.php | 7 +- src/Builder/Pdf/FlattenPdfBuilder.php | 7 +- src/Builder/Pdf/HtmlPdfBuilder.php | 7 +- src/Builder/Pdf/LibreOfficePdfBuilder.php | 7 +- src/Builder/Pdf/MarkdownPdfBuilder.php | 7 +- src/Builder/Pdf/MergePdfBuilder.php | 7 +- src/Builder/Pdf/SplitPdfBuilder.php | 7 +- src/Builder/Pdf/UrlPdfBuilder.php | 11 +- .../Screenshot/HtmlScreenshotBuilder.php | 7 +- .../Screenshot/MarkdownScreenshotBuilder.php | 7 +- .../Screenshot/UrlScreenshotBuilder.php | 14 +- src/DependencyInjection/BuilderStack.php | 26 ++-- 35 files changed, 662 insertions(+), 251 deletions(-) diff --git a/docs/pdf/builders_api/ConvertPdfBuilder.md b/docs/pdf/builders_api/ConvertPdfBuilder.md index 390654b8..15967dc5 100644 --- a/docs/pdf/builders_api/ConvertPdfBuilder.md +++ b/docs/pdf/builders_api/ConvertPdfBuilder.md @@ -4,21 +4,43 @@ > See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### files(Stringable|string $paths) -### getBodyBag() -### getHeadersBag() ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index 584f0171..26f01d01 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -67,35 +70,54 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### forwardCookie(string $name) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF. +Define whether the document outline should be embedded into the PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### landscape(bool $bool) -Set the paper orientation to landscape. (Default false). +Set the paper orientation to landscape.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches. +Overrides the default margins (e.g., 0.39), in inches.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### metadata(array $metadata) Resets the metadata.
@@ -108,10 +130,16 @@ Resets the metadata.
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). +Page ranges to print, e.g., '1-5, 8, 11-13'.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### omitBackground(bool $bool) -Hide the default white background and allow generating PDFs with transparency. +Hide the default white background and allow generating PDFs with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. @@ -127,16 +155,25 @@ Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. De Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS. (Default false). +Define whether to prefer page size as defined by CSS.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### printBackground(bool $bool) -Prints the background graphics. (Default false). +Prints the background graphics.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### scale(float $scale) -The scale of the page rendering (e.g., 1.0). (Default 1.0). +The scale of the page rendering (e.g., 1.0).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### singlePage(bool $bool) @@ -144,36 +181,69 @@ Define whether to print the entire content in one single page.

If the ### skipNetworkIdleEvent(bool $bool) ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### type() ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index 9ae7749a..9f6c5a00 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -25,7 +25,10 @@ Specify whether form fields are exported as widgets or only their fixed print re Specify whether to update the indexes before conversion, keeping in mind that doing so might result in missing links in the final PDF. ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### exportBookmarksToPdfDestination(bool $bool) Specify that the bookmarks contained in the source LibreOffice file should be exported to the PDF file as Named Destination. @@ -57,10 +60,11 @@ Adds office files to convert (overrides any previous files). ### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -### getBodyBag() -### getHeadersBag() ### landscape(bool $bool) -Set the paper orientation to landscape. +Set the paper orientation to landscape.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### losslessImageCompression(bool $bool) Specify if images are exported to PDF using a lossless compression format like PNG or compressed using the JPEG format. @@ -82,7 +86,10 @@ Resets the metadata.
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-4' - empty means all pages. +Page ranges to print, e.g., '1-4' - empty means all pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### password(string $password) Set the password for opening the source file. @@ -91,7 +98,7 @@ Set the password for opening the source file. Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### quality(int $quality) Specify the quality of the JPG export. A higher value produces a higher-quality image and a larger file. Between 1 and 100.
@@ -106,18 +113,51 @@ Ignore each sheet’s paper size, print ranges and shown/hidden status and puts Specify that automatically inserted empty pages are suppressed. This option is active only if storing Writer documents. ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 88a2afe5..9703e138 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -73,35 +76,54 @@ Add Markdown into a PDF.
### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### forwardCookie(string $name) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF. +Define whether the document outline should be embedded into the PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### landscape(bool $bool) -Set the paper orientation to landscape. (Default false). +Set the paper orientation to landscape.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches. +Overrides the default margins (e.g., 0.39), in inches.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### metadata(array $metadata) Resets the metadata.
@@ -114,10 +136,16 @@ Resets the metadata.
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). +Page ranges to print, e.g., '1-5, 8, 11-13'.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### omitBackground(bool $bool) -Hide the default white background and allow generating PDFs with transparency. +Hide the default white background and allow generating PDFs with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. @@ -133,16 +161,25 @@ Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. De Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS. (Default false). +Define whether to prefer page size as defined by CSS.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### printBackground(bool $bool) -Prints the background graphics. (Default false). +Prints the background graphics.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### scale(float $scale) -The scale of the page rendering (e.g., 1.0). (Default 1.0). +The scale of the page rendering (e.g., 1.0).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### singlePage(bool $bool) @@ -150,39 +187,72 @@ Define whether to print the entire content in one single page.

If the ### skipNetworkIdleEvent(bool $bool) ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### type() ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### wrapper(string $template, array $context) ### wrapperFile(string $path) The HTML file to convert into PDF. diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index cf891c6d..bb898676 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -7,7 +7,10 @@ The metadata to write. ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### files(Stringable|string $paths) Add PDF files to merge.
@@ -18,8 +21,6 @@ Add PDF files to merge.
### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -### getBodyBag() -### getHeadersBag() ### metadata(array $metadata) Resets the metadata.
@@ -34,12 +35,33 @@ Resets the metadata.
Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index 9b691bb2..6cecf2bb 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -7,14 +7,15 @@ The metadata to write. ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### files(Stringable|string $paths) ### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -### getBodyBag() -### getHeadersBag() ### metadata(array $metadata) Resets the metadata.
@@ -29,21 +30,54 @@ Resets the metadata.
Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index 36790a61..6bda174f 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -67,35 +70,54 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### forwardCookie(string $name) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF. +Define whether the document outline should be embedded into the PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### landscape(bool $bool) -Set the paper orientation to landscape. (Default false). +Set the paper orientation to landscape.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches. +Overrides the default margins (e.g., 0.39), in inches.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### metadata(array $metadata) Resets the metadata.
@@ -108,10 +130,16 @@ Resets the metadata.
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). +Page ranges to print, e.g., '1-5, 8, 11-13'.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### omitBackground(bool $bool) -Hide the default white background and allow generating PDFs with transparency. +Hide the default white background and allow generating PDFs with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. @@ -127,17 +155,26 @@ Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. De Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS. (Default false). +Define whether to prefer page size as defined by CSS.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### printBackground(bool $bool) -Prints the background graphics. (Default false). +Prints the background graphics.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### route(string $name, array $parameters) ### scale(float $scale) -The scale of the page rendering (e.g., 1.0). (Default 1.0). +The scale of the page rendering (e.g., 1.0).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) @@ -146,39 +183,72 @@ Define whether to print the entire content in one single page.

If the ### skipNetworkIdleEvent(bool $bool) ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### type() ### url(string $url) URL of the page you want to convert into PDF. ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index 178e91cb..0e5927ad 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -67,23 +70,24 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### height(int $height) The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with
transparency. (Default false). +Hides default white background and allows generating screenshot with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). @@ -95,29 +99,50 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
### skipNetworkIdleEvent(bool $bool) ### type() ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### width(int $width) The device screen width in pixels. (Default 800). diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index ae9d0bc2..5ba67e61 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -73,23 +76,24 @@ Add Markdown into a PDF.
### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### height(int $height) The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with
transparency. (Default false). +Hides default white background and allows generating screenshot with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). @@ -101,29 +105,50 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
### skipNetworkIdleEvent(bool $bool) ### type() ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### width(int $width) The device screen width in pixels. (Default 800). diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index 11cd46c4..757b09e2 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -67,23 +70,24 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### height(int $height) The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with
transparency. (Default false). +Hides default white background and allows generating screenshot with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). @@ -100,29 +104,50 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
URL of the page you want to convert into PDF. ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### width(int $width) The device screen width in pixels. (Default 800). diff --git a/src/Builder/AbstractBuilder.php b/src/Builder/AbstractBuilder.php index 18dadb1e..a6f7a96f 100644 --- a/src/Builder/AbstractBuilder.php +++ b/src/Builder/AbstractBuilder.php @@ -102,12 +102,12 @@ public function generateAsync(): GotenbergAsyncResult ); } - public function getBodyBag(): BodyBag + protected function getBodyBag(): BodyBag { return $this->bodyBag; } - public function getHeadersBag(): HeadersBag + protected function getHeadersBag(): HeadersBag { return $this->headersBag; } diff --git a/src/Builder/Attributes/SemanticNode.php b/src/Builder/Attributes/SemanticNode.php index 8ad028cb..785df9e1 100644 --- a/src/Builder/Attributes/SemanticNode.php +++ b/src/Builder/Attributes/SemanticNode.php @@ -7,6 +7,10 @@ final class SemanticNode { public function __construct( public readonly string $name, + public readonly string $type, ) { + if (!\in_array($this->type, ['pdf', 'screenshot'], true)) { + throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); + } } } diff --git a/src/Builder/Behaviors/Chromium/ContentTrait.php b/src/Builder/Behaviors/Chromium/ContentTrait.php index ab3cbefa..4508b450 100644 --- a/src/Builder/Behaviors/Chromium/ContentTrait.php +++ b/src/Builder/Behaviors/Chromium/ContentTrait.php @@ -76,7 +76,7 @@ public function footer(string $template, array $context = []): static } /** - * HTML file containing the header. (default None). + * HTML file containing the header. */ public function headerFile(string $path): static { @@ -84,7 +84,7 @@ public function headerFile(string $path): static } /** - * HTML file containing the footer. (default None). + * HTML file containing the footer. */ public function footerFile(string $path): static { diff --git a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php index f35853d1..454a090c 100644 --- a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php +++ b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php @@ -15,7 +15,7 @@ trait CustomHttpHeadersTrait abstract protected function getBodyBag(): BodyBag; /** - * Override the default User-Agent HTTP header. (default None). + * Override the default User-Agent HTTP header. * * @param UserAgent::*|string $userAgent * @@ -30,8 +30,7 @@ public function userAgent(string $userAgent): static } /** - * Sets extra HTTP headers that Chromium will send when loading the HTML - * document. (default None). (overrides any previous headers). + * Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers). * * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium * @@ -52,8 +51,7 @@ public function extraHttpHeaders(array $headers): static } /** - * Adds extra HTTP headers that Chromium will send when loading the HTML - * document. (default None). + * Adds extra HTTP headers that Chromium will send when loading the HTML document. * * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium * diff --git a/src/Builder/Behaviors/Chromium/FailOnTrait.php b/src/Builder/Behaviors/Chromium/FailOnTrait.php index 35a5b753..46dc0365 100644 --- a/src/Builder/Behaviors/Chromium/FailOnTrait.php +++ b/src/Builder/Behaviors/Chromium/FailOnTrait.php @@ -30,8 +30,7 @@ public function failOnHttpStatusCodes(array $statusCodes): static } /** - * Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. - * (default None). (overrides any previous configuration). + * Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration). * * @see https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium * diff --git a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php index 96f6cc17..18c343fa 100644 --- a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php @@ -94,6 +94,8 @@ public function paperStandardSize(PaperSizeInterface $paperSize): static /** * Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_top'))] public function marginTop(float $value, Unit $unit = Unit::Inches): static @@ -105,6 +107,8 @@ public function marginTop(float $value, Unit $unit = Unit::Inches): static /** * Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_bottom'))] public function marginBottom(float $value, Unit $unit = Unit::Inches): static @@ -116,6 +120,8 @@ public function marginBottom(float $value, Unit $unit = Unit::Inches): static /** * Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_left'))] public function marginLeft(float $value, Unit $unit = Unit::Inches): static @@ -127,6 +133,8 @@ public function marginLeft(float $value, Unit $unit = Unit::Inches): static /** * Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_right'))] public function marginRight(float $value, Unit $unit = Unit::Inches): static @@ -138,6 +146,8 @@ public function marginRight(float $value, Unit $unit = Unit::Inches): static /** * Overrides the default margins (e.g., 0.39), in inches. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ public function margins(float $top, float $bottom, float $left, float $right, Unit $unit = Unit::Inches): static { @@ -150,7 +160,9 @@ public function margins(float $top, float $bottom, float $left, float $right, Un } /** - * Define whether to prefer page size as defined by CSS. (Default false). + * Define whether to prefer page size as defined by CSS. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('prefer_css_page_size'))] public function preferCssPageSize(bool $bool): static @@ -162,6 +174,8 @@ public function preferCssPageSize(bool $bool): static /** * Define whether the document outline should be embedded into the PDF. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('generate_document_outline'))] public function generateDocumentOutline(bool $bool): static @@ -172,7 +186,9 @@ public function generateDocumentOutline(bool $bool): static } /** - * Prints the background graphics. (Default false). + * Prints the background graphics. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('print_background'))] public function printBackground(bool $bool): static @@ -184,6 +200,8 @@ public function printBackground(bool $bool): static /** * Hide the default white background and allow generating PDFs with transparency. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] public function omitBackground(bool $bool): static @@ -194,7 +212,9 @@ public function omitBackground(bool $bool): static } /** - * Set the paper orientation to landscape. (Default false). + * Set the paper orientation to landscape. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('landscape'))] public function landscape(bool $bool = true): static @@ -205,7 +225,9 @@ public function landscape(bool $bool = true): static } /** - * The scale of the page rendering (e.g., 1.0). (Default 1.0). + * The scale of the page rendering (e.g., 1.0). + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new FloatNodeBuilder('scale'))] public function scale(float $scale): static @@ -216,7 +238,9 @@ public function scale(float $scale): static } /** - * Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). + * Page ranges to print, e.g., '1-5, 8, 11-13'. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new ScalarNodeBuilder('native_page_ranges'))] public function nativePageRanges(string $ranges): static diff --git a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php index 36d92950..8a4c3729 100644 --- a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php @@ -76,8 +76,9 @@ public function quality(int $quality): static } /** - * Hides default white background and allows generating screenshot with - * transparency. (Default false). + * Hides default white background and allows generating screenshot with transparency. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] public function omitBackground(bool $bool = true): static diff --git a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php index 0da0c363..b51478e2 100644 --- a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php +++ b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php @@ -16,7 +16,7 @@ abstract protected function getBodyBag(): BodyBag; /** * Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML - * document before converting it to PDF. (default None). + * document before converting it to PDF. * * @see https://gotenberg.dev/docs/routes#wait-before-rendering-chromium */ @@ -30,8 +30,7 @@ public function waitDelay(string $delay): static } /** - * Sets the JavaScript expression to wait before converting an HTML - * document to PDF until it returns true. (default None). + * Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true. * * For instance: "window.status === 'ready'". * diff --git a/src/Builder/Behaviors/DownloadFromTrait.php b/src/Builder/Behaviors/DownloadFromTrait.php index e6b398f7..398300ed 100644 --- a/src/Builder/Behaviors/DownloadFromTrait.php +++ b/src/Builder/Behaviors/DownloadFromTrait.php @@ -18,10 +18,11 @@ trait DownloadFromTrait abstract protected function getBodyBag(): BodyBag; /** - * Sets download from to download each entry (file) in parallel (default None). - * (URLs MUST return a Content-Disposition header with a filename parameter.). + * Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.). * * @param list}> $downloadFrom + * + * @see https://gotenberg.dev/docs/routes#download-from */ #[ExposeSemantic(new ArrayNodeBuilder('download_from', prototype: 'array', children: [ new ScalarNodeBuilder('url', required: true, restrictTo: 'string'), diff --git a/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php b/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php index 1f4861a8..1bc19a41 100644 --- a/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php +++ b/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php @@ -30,6 +30,8 @@ public function password(#[\SensitiveParameter] string $password): static /** * Set the paper orientation to landscape. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('landscape'))] public function landscape(bool $bool = true): static @@ -41,6 +43,8 @@ public function landscape(bool $bool = true): static /** * Page ranges to print, e.g., '1-4' - empty means all pages. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new ScalarNodeBuilder('native_page_ranges'))] public function nativePageRanges(string $ranges): static diff --git a/src/Builder/Behaviors/PdfFormatTrait.php b/src/Builder/Behaviors/PdfFormatTrait.php index 041b55a2..70f9e589 100644 --- a/src/Builder/Behaviors/PdfFormatTrait.php +++ b/src/Builder/Behaviors/PdfFormatTrait.php @@ -33,7 +33,7 @@ public function pdfFormat(PdfFormat|null $format): self } /** - * Enable PDF for Universal Access for optimal accessibility. (default false). + * Enable PDF for Universal Access for optimal accessibility. */ #[ExposeSemantic(new BooleanNodeBuilder('pdf_universal_access'))] public function pdfUniversalAccess(bool $bool = true): self diff --git a/src/Builder/Behaviors/SplitTrait.php b/src/Builder/Behaviors/SplitTrait.php index d5deb8bf..4ef116b7 100644 --- a/src/Builder/Behaviors/SplitTrait.php +++ b/src/Builder/Behaviors/SplitTrait.php @@ -12,15 +12,15 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\NativeEnumNodeBuilder; use Sensiolabs\GotenbergBundle\NodeBuilder\ScalarNodeBuilder; -/** - * @see https://gotenberg.dev/docs/routes#split-chromium - */ trait SplitTrait { abstract protected function getBodyBag(): BodyBag; /** - * Either intervals or pages. (default None). + * Either intervals or pages. + * + * @see https://gotenberg.dev/docs/routes#split-chromium + * @see https://gotenberg.dev/docs/routes#split-libreoffice */ #[ExposeSemantic(new NativeEnumNodeBuilder('split_mode', enumClass: SplitMode::class))] public function splitMode(SplitMode|null $splitMode = null): self @@ -35,7 +35,10 @@ public function splitMode(SplitMode|null $splitMode = null): self } /** - * Either the intervals or the page ranges to extract, depending on the selected mode. (default None). + * Either the intervals or the page ranges to extract, depending on the selected mode. + * + * @see https://gotenberg.dev/docs/routes#split-chromium + * @see https://gotenberg.dev/docs/routes#split-libreoffice */ #[ExposeSemantic(new ScalarNodeBuilder('split_span'))] public function splitSpan(string $splitSpan): self @@ -48,6 +51,9 @@ public function splitSpan(string $splitSpan): self /** * Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). + * + * @see https://gotenberg.dev/docs/routes#split-chromium + * @see https://gotenberg.dev/docs/routes#split-libreoffice */ #[ExposeSemantic(new BooleanNodeBuilder('split_unify'))] public function splitUnify(bool $bool = true): self diff --git a/src/Builder/Behaviors/WebhookTrait.php b/src/Builder/Behaviors/WebhookTrait.php index 20f1db42..4c8518a9 100644 --- a/src/Builder/Behaviors/WebhookTrait.php +++ b/src/Builder/Behaviors/WebhookTrait.php @@ -106,7 +106,12 @@ public function webhook(array $webhook): static } /** + * Sets the webhook for cases of success. + * Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. + * * @param 'POST'|'PUT'|'PATCH'|null $method + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookUrl(string $url, string|null $method = null): static { @@ -119,7 +124,12 @@ public function webhookUrl(string $url, string|null $method = null): static } /** + * Sets the webhook for cases of success. + * Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. + * * @param 'POST'|'PUT'|'PATCH'|null $method + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookErrorUrl(string $url, string|null $method = null): static { @@ -132,7 +142,11 @@ public function webhookErrorUrl(string $url, string|null $method = null): static } /** + * Extra headers that will be provided to the webhook endpoint. May it either be Success or Error. + * * @param array $extraHttpHeaders + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookExtraHeaders(array $extraHttpHeaders): static { @@ -144,15 +158,19 @@ public function webhookExtraHeaders(array $extraHttpHeaders): static /** * @param array $parameters * @param 'PATCH'|'POST'|'PUT'|null $method + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookRoute(string $route, array $parameters = [], string|null $method = null): static { return $this->webhookUrl($this->getUrlGenerator()->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL), $method); } - /** + /** * * @param array $parameters * @param 'PATCH'|'POST'|'PUT'|null $method + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookErrorRoute(string $route, array $parameters = [], string|null $method = null): static { diff --git a/src/Builder/Pdf/ConvertPdfBuilder.php b/src/Builder/Pdf/ConvertPdfBuilder.php index dc878ae6..eb284750 100644 --- a/src/Builder/Pdf/ConvertPdfBuilder.php +++ b/src/Builder/Pdf/ConvertPdfBuilder.php @@ -16,7 +16,7 @@ /** * @see https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route */ -#[SemanticNode('convert')] +#[SemanticNode('convert', 'pdf')] final class ConvertPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -62,9 +62,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/FlattenPdfBuilder.php b/src/Builder/Pdf/FlattenPdfBuilder.php index 4dd02b7e..82ac04f1 100644 --- a/src/Builder/Pdf/FlattenPdfBuilder.php +++ b/src/Builder/Pdf/FlattenPdfBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#flatten-pdfs-route */ -#[SemanticNode('flatten')] +#[SemanticNode('flatten', 'pdf')] final class FlattenPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -56,9 +56,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/HtmlPdfBuilder.php b/src/Builder/Pdf/HtmlPdfBuilder.php index 78853a76..0d03f445 100644 --- a/src/Builder/Pdf/HtmlPdfBuilder.php +++ b/src/Builder/Pdf/HtmlPdfBuilder.php @@ -12,7 +12,7 @@ /** * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route */ -#[SemanticNode('html')] +#[SemanticNode('html', 'pdf')] final class HtmlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait; @@ -30,9 +30,4 @@ protected function validatePayloadBody(): void throw new MissingRequiredFieldException('Content is required'); } } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/LibreOfficePdfBuilder.php b/src/Builder/Pdf/LibreOfficePdfBuilder.php index 975c05bf..fd79131d 100644 --- a/src/Builder/Pdf/LibreOfficePdfBuilder.php +++ b/src/Builder/Pdf/LibreOfficePdfBuilder.php @@ -16,7 +16,7 @@ /** * @see https://gotenberg.dev/docs/routes#convert-with-libreoffice */ -#[SemanticNode('office')] +#[SemanticNode('office', 'pdf')] final class LibreOfficePdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -76,9 +76,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/MarkdownPdfBuilder.php b/src/Builder/Pdf/MarkdownPdfBuilder.php index a8f0c070..7f080bdd 100644 --- a/src/Builder/Pdf/MarkdownPdfBuilder.php +++ b/src/Builder/Pdf/MarkdownPdfBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ -#[SemanticNode('markdown')] +#[SemanticNode('markdown', 'pdf')] final class MarkdownPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait { @@ -79,9 +79,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/MergePdfBuilder.php b/src/Builder/Pdf/MergePdfBuilder.php index 962ddeac..a57e66e1 100644 --- a/src/Builder/Pdf/MergePdfBuilder.php +++ b/src/Builder/Pdf/MergePdfBuilder.php @@ -18,7 +18,7 @@ /** * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ -#[SemanticNode('merge')] +#[SemanticNode('merge', 'pdf')] final class MergePdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -67,9 +67,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/SplitPdfBuilder.php b/src/Builder/Pdf/SplitPdfBuilder.php index c15189d7..29a8f3ba 100644 --- a/src/Builder/Pdf/SplitPdfBuilder.php +++ b/src/Builder/Pdf/SplitPdfBuilder.php @@ -19,7 +19,7 @@ /** * @see https://gotenberg.dev/docs/routes#split-pdfs-route */ -#[SemanticNode('split')] +#[SemanticNode('split', 'pdf')] final class SplitPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -72,9 +72,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/UrlPdfBuilder.php b/src/Builder/Pdf/UrlPdfBuilder.php index d1aef4ea..0e642745 100644 --- a/src/Builder/Pdf/UrlPdfBuilder.php +++ b/src/Builder/Pdf/UrlPdfBuilder.php @@ -14,7 +14,7 @@ /** * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ -#[SemanticNode('url')] +#[SemanticNode('url', 'pdf')] final class UrlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait; @@ -25,6 +25,8 @@ final class UrlPdfBuilder extends AbstractBuilder implements BuilderAssetInterfa /** * URL of the page you want to convert into PDF. + * + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function url(string $url): self { @@ -36,6 +38,8 @@ public function url(string $url): self /** * @param string $name #Route * @param array $parameters + * + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function route(string $name, array $parameters = []): self { @@ -75,9 +79,4 @@ private function normalizeRoute(): \Generator { yield 'route' => NormalizerFactory::route($this->requestContext, $this->getUrlGenerator()); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Screenshot/HtmlScreenshotBuilder.php b/src/Builder/Screenshot/HtmlScreenshotBuilder.php index 6a0b15ec..f6aad76b 100644 --- a/src/Builder/Screenshot/HtmlScreenshotBuilder.php +++ b/src/Builder/Screenshot/HtmlScreenshotBuilder.php @@ -12,7 +12,7 @@ /** * @see https://gotenberg.dev/docs/routes#screenshots-route */ -#[SemanticNode('html')] +#[SemanticNode('html', 'screenshot')] final class HtmlScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait; @@ -30,9 +30,4 @@ protected function validatePayloadBody(): void throw new MissingRequiredFieldException('Content is required'); } } - - public static function type(): string - { - return 'screenshot'; - } } diff --git a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php index 3f92b660..e9a57ce5 100644 --- a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php +++ b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#screenshots-route */ -#[SemanticNode('markdown')] +#[SemanticNode('markdown', 'screenshot')] final class MarkdownScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait { @@ -79,9 +79,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'screenshot'; - } } diff --git a/src/Builder/Screenshot/UrlScreenshotBuilder.php b/src/Builder/Screenshot/UrlScreenshotBuilder.php index a4dabba1..b21068d3 100644 --- a/src/Builder/Screenshot/UrlScreenshotBuilder.php +++ b/src/Builder/Screenshot/UrlScreenshotBuilder.php @@ -11,10 +11,7 @@ use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Symfony\Component\Routing\RequestContext; -/** - * @see https://gotenberg.dev/docs/routes#url-into-pdf-route - */ -#[SemanticNode('url')] +#[SemanticNode('url', 'screenshot')] final class UrlScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait; @@ -25,6 +22,8 @@ final class UrlScreenshotBuilder extends AbstractBuilder implements BuilderAsset /** * URL of the page you want to convert into PDF. + * + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function url(string $url): self { @@ -36,6 +35,8 @@ public function url(string $url): self /** * @param string $name #Route * @param array $parameters + * + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function route(string $name, array $parameters = []): self { @@ -72,9 +73,4 @@ private function normalizeRoute(): \Generator { yield 'route' => NormalizerFactory::route($this->requestContext, $this->getUrlGenerator()); } - - public static function type(): string - { - return 'screenshot'; - } } diff --git a/src/DependencyInjection/BuilderStack.php b/src/DependencyInjection/BuilderStack.php index 51207a0f..5586f5fa 100644 --- a/src/DependencyInjection/BuilderStack.php +++ b/src/DependencyInjection/BuilderStack.php @@ -49,16 +49,16 @@ public function push(string $class): void throw new \LogicException("{$class} has already been added."); } - $type = 'custom'; - if (method_exists($class, 'type')) { - $type = $class::type(); - } - - if (!\in_array($type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock - throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); - } - - $this->builders[$class] = $type; +// $type = 'custom'; +// if (method_exists($class, 'type')) { +// $type = $class::type(); +// } +// +// if (!\in_array($type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock +// throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); +// } +// +// $this->builders[$class] = $type; $reflection = new \ReflectionClass($class); $nodeAttributes = $reflection->getAttributes(SemanticNode::class); @@ -70,7 +70,11 @@ public function push(string $class): void /** @var SemanticNode $semanticNode */ $semanticNode = $nodeAttributes[0]->newInstance(); - $this->typeReverseMapping[$type][$semanticNode->name] = $class; + if (!\in_array($semanticNode->type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock + throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); + } + + $this->typeReverseMapping[$semanticNode->type][$semanticNode->name] = $class; foreach (array_reverse($reflection->getMethods(\ReflectionMethod::IS_PUBLIC)) as $method) { $attributes = $method->getAttributes(ExposeSemantic::class); From 7fa23bf6a084ba6518debc7283d8fc4ff82da539 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Fri, 11 Apr 2025 10:38:29 +0200 Subject: [PATCH 03/30] Update doc generation --- docs/generate.php | 4 +++- docs/pdf/builders_api/ConvertPdfBuilder.md | 1 - docs/pdf/builders_api/HtmlPdfBuilder.md | 1 - docs/pdf/builders_api/LibreOfficePdfBuilder.md | 1 - docs/pdf/builders_api/MarkdownPdfBuilder.md | 1 - docs/pdf/builders_api/MergePdfBuilder.md | 1 - docs/pdf/builders_api/SplitPdfBuilder.md | 1 - docs/pdf/builders_api/UrlPdfBuilder.md | 9 +++++++-- .../screenshot/builders_api/HtmlScreenshotBuilder.md | 1 - .../builders_api/MarkdownScreenshotBuilder.md | 1 - docs/screenshot/builders_api/UrlScreenshotBuilder.md | 12 +++++++----- 11 files changed, 17 insertions(+), 16 deletions(-) diff --git a/docs/generate.php b/docs/generate.php index fb730c6c..fe6dc13b 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -97,9 +97,11 @@ class BuilderParser 'setConfigurations', 'generate', 'generateAsync', - 'getMultipartFormData', 'fileName', 'processor', + 'type', + 'getBodyBag', + 'getHeaderBag', ]; private string $name; diff --git a/docs/pdf/builders_api/ConvertPdfBuilder.md b/docs/pdf/builders_api/ConvertPdfBuilder.md index 15967dc5..f4210a1d 100644 --- a/docs/pdf/builders_api/ConvertPdfBuilder.md +++ b/docs/pdf/builders_api/ConvertPdfBuilder.md @@ -16,7 +16,6 @@ Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) Enable PDF for Universal Access for optimal accessibility. -### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index 26f01d01..a002c442 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -201,7 +201,6 @@ Specify whether to put extracted pages into a single file or as many files as th > See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) > See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index 9f6c5a00..2bea2aff 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -133,7 +133,6 @@ Specify whether to put extracted pages into a single file or as many files as th > See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) > See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 9703e138..9c5b80cd 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -207,7 +207,6 @@ Specify whether to put extracted pages into a single file or as many files as th > See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) > See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index bb898676..d651dae9 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -37,7 +37,6 @@ Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) Enable PDF for Universal Access for optimal accessibility. -### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index 6cecf2bb..13f4aad1 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -53,7 +53,6 @@ Specify whether to put extracted pages into a single file or as many files as th > See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) > See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index 6bda174f..bcaa55e5 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -170,6 +170,9 @@ Prints the background graphics.
> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### route(string $name, array $parameters) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) + ### scale(float $scale) The scale of the page rendering (e.g., 1.0).
@@ -203,9 +206,11 @@ Specify whether to put extracted pages into a single file or as many files as th > See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) > See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### url(string $url) -URL of the page you want to convert into PDF. +URL of the page you want to convert into PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index 0e5927ad..8922f44b 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -97,7 +97,6 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### skipNetworkIdleEvent(bool $bool) -### type() ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index 5ba67e61..959ebded 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -103,7 +103,6 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### skipNetworkIdleEvent(bool $bool) -### type() ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index 757b09e2..84746c9b 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -1,8 +1,5 @@ # UrlScreenshotBuilder -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. @@ -96,12 +93,17 @@ Define whether to optimize image encoding for speed, not for resulting size. (De The compression quality from range 0 to 100 (jpeg only). (default 100).
### route(string $name, array $parameters) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) + ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) ### skipNetworkIdleEvent(bool $bool) -### type() ### url(string $url) -URL of the page you want to convert into PDF. +URL of the page you want to convert into PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
From 0fbfcf58d3659ec44565cf58ee8d69db44c7067f Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Fri, 11 Apr 2025 10:44:50 +0200 Subject: [PATCH 04/30] Better display list of see elements --- docs/generate.php | 12 ++++++++++-- docs/pdf/builders_api/HtmlPdfBuilder.md | 14 +++++++------- docs/pdf/builders_api/LibreOfficePdfBuilder.md | 14 +++++++------- docs/pdf/builders_api/MarkdownPdfBuilder.md | 14 +++++++------- docs/pdf/builders_api/MergePdfBuilder.md | 8 ++++---- docs/pdf/builders_api/SplitPdfBuilder.md | 14 +++++++------- docs/pdf/builders_api/UrlPdfBuilder.md | 14 +++++++------- 7 files changed, 49 insertions(+), 41 deletions(-) diff --git a/docs/generate.php b/docs/generate.php index fe6dc13b..4651e7a9 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -146,12 +146,20 @@ public function extract(): string return ''; } + $lastKey = array_key_last($seeList); + $markdown = '> [!TIP]'; - foreach ($seeList as $see) { + foreach ($seeList as $key => $see) { $markdown .= "\n> See: [{$see}]({$see})"; + + $isLast = $lastKey === $key; + + if ($isLast === false) { + $markdown .= '
'; + } } - return $markdown; + return rtrim($markdown, "
"); }; /** diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index a002c442..1da1ad5d 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -123,10 +123,10 @@ Overrides the default margins (e.g., 0.39), in inches.
Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) -> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) -> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
+> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
+> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) @@ -184,21 +184,21 @@ Define whether to print the entire content in one single page.

If the Either intervals or pages.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### userAgent(string $userAgent) diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index 2bea2aff..e01e393d 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -79,10 +79,10 @@ Merge alphanumerically the resulting PDFs. Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) -> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) -> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
+> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
+> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) @@ -116,21 +116,21 @@ Specify that automatically inserted empty pages are suppressed. This option is a Either intervals or pages.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### webhook(array $webhook) diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 9c5b80cd..34a704fe 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -129,10 +129,10 @@ Overrides the default margins (e.g., 0.39), in inches.
Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) -> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) -> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
+> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
+> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) @@ -190,21 +190,21 @@ Define whether to print the entire content in one single page.

If the Either intervals or pages.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### userAgent(string $userAgent) diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index d651dae9..5a1539b8 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -25,10 +25,10 @@ Flattening a PDF combines all its contents into a single layer. (default false). Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) -> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) -> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
+> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
+> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index 13f4aad1..c29e0fdf 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -20,10 +20,10 @@ Flattening a PDF combines all its contents into a single layer. (default false). Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) -> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) -> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
+> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
+> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) @@ -36,21 +36,21 @@ Enable PDF for Universal Access for optimal accessibility. Either intervals or pages.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### webhook(array $webhook) diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index bcaa55e5..08dd28cb 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -123,10 +123,10 @@ Overrides the default margins (e.g., 0.39), in inches.
Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium) -> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice) -> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route) -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
+> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
+> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) @@ -189,21 +189,21 @@ Define whether to print the entire content in one single page.

If the Either intervals or pages.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium)
> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### url(string $url) From 7caceb82f184c109634c455a535f0e15b3ba6d01 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Fri, 11 Apr 2025 10:51:52 +0200 Subject: [PATCH 05/30] Remove file taht should not be present --- docs/generate.php | 11 ++++----- docs/pdf/builders_api/FlattenPdfBuilder.md | 27 ---------------------- 2 files changed, 5 insertions(+), 33 deletions(-) delete mode 100644 docs/pdf/builders_api/FlattenPdfBuilder.md diff --git a/docs/generate.php b/docs/generate.php index 4651e7a9..0cceba4f 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -1,17 +1,16 @@ #!/usr/bin/env php >> + * @var array>> */ private array $builders = []; @@ -32,7 +31,7 @@ class Summary private array $filenames = []; /** - * @param ReflectionClass $class + * @param ReflectionClass $class */ public function register(string $type, ReflectionClass $class): void { @@ -122,7 +121,7 @@ class BuilderParser private array $methodsSignature = []; /** - * @param class-string $builder + * @param class-string $builder */ public function prepare(Summary $summary, string $type, string $builder): void { @@ -221,7 +220,7 @@ public function extract(): string } /** - * @param ReflectionClass $class + * @param ReflectionClass $class */ private function prepareBuilder(ReflectionClass $class): void { diff --git a/docs/pdf/builders_api/FlattenPdfBuilder.md b/docs/pdf/builders_api/FlattenPdfBuilder.md deleted file mode 100644 index ea528bbc..00000000 --- a/docs/pdf/builders_api/FlattenPdfBuilder.md +++ /dev/null @@ -1,27 +0,0 @@ -# FlattenPdfBuilder - - -* `files(string $paths)`: - -* `type()`: - -* `getBodyBag()`: - -* `getHeadersBag()`: - -* `downloadFrom(array $downloadFrom)`: -Sets download from to download each entry (file) in parallel (default None). -(URLs MUST return a Content-Disposition header with a filename parameter.). - -* `webhook(array $webhook)`: - -* `webhookUrl(string $url, ?string $method)`: - -* `webhookErrorUrl(string $url, ?string $method)`: - -* `webhookExtraHeaders(array $extraHttpHeaders)`: - -* `webhookRoute(string $route, array $parameters, ?string $method)`: - -* `webhookErrorRoute(string $route, array $parameters, ?string $method)`: - From 1bdb0b41218d47a884a37ee42f41275b423ed459 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Fri, 11 Apr 2025 10:55:47 +0200 Subject: [PATCH 06/30] Add flatten in generation list --- docs/builders_api.md | 1 + docs/generate.php | 10 +++--- docs/pdf/builders_api/FlattenPdfBuilder.md | 39 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 docs/pdf/builders_api/FlattenPdfBuilder.md diff --git a/docs/builders_api.md b/docs/builders_api.md index c51b2304..a4294a51 100644 --- a/docs/builders_api.md +++ b/docs/builders_api.md @@ -3,6 +3,7 @@ ## Pdf * [ConvertPdfBuilder](./pdf/builders_api/ConvertPdfBuilder.md) +* [FlattenPdfBuilder](./pdf/builders_api/FlattenPdfBuilder.md) * [HtmlPdfBuilder](./pdf/builders_api/HtmlPdfBuilder.md) * [LibreOfficePdfBuilder](./pdf/builders_api/LibreOfficePdfBuilder.md) * [MarkdownPdfBuilder](./pdf/builders_api/MarkdownPdfBuilder.md) diff --git a/docs/generate.php b/docs/generate.php index 0cceba4f..215334f9 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -3,6 +3,7 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder; +use Sensiolabs\GotenbergBundle\Builder\Pdf\FlattenPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder; use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder; @@ -75,18 +76,19 @@ class BuilderParser */ public const BUILDERS = [ 'pdf' => [ + ConvertPdfBuilder::class, + FlattenPdfBuilder::class, HtmlPdfBuilder::class, - UrlPdfBuilder::class, - MarkdownPdfBuilder::class, LibreOfficePdfBuilder::class, + MarkdownPdfBuilder::class, MergePdfBuilder::class, - ConvertPdfBuilder::class, SplitPdfBuilder::class, + UrlPdfBuilder::class, ], 'screenshot' => [ HtmlScreenshotBuilder::class, - UrlScreenshotBuilder::class, MarkdownScreenshotBuilder::class, + UrlScreenshotBuilder::class, ], ]; diff --git a/docs/pdf/builders_api/FlattenPdfBuilder.md b/docs/pdf/builders_api/FlattenPdfBuilder.md new file mode 100644 index 00000000..fbe7d46c --- /dev/null +++ b/docs/pdf/builders_api/FlattenPdfBuilder.md @@ -0,0 +1,39 @@ +# FlattenPdfBuilder + +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) + +### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) + +### files(Stringable|string $paths) +### webhook(array $webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + From 0236d6afcfb361e4681204bb6a48be73ab19e22e Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Fri, 11 Apr 2025 11:20:33 +0200 Subject: [PATCH 07/30] Fix rebase --- config/services.php | 15 ++------ docs/generate.php | 4 +-- src/Builder/AbstractBuilder.php | 4 +-- src/Builder/Attributes/SemanticNode.php | 4 --- src/Builder/Behaviors/Chromium/AssetTrait.php | 5 ++- .../Behaviors/Chromium/ContentTrait.php | 4 +-- .../Chromium/CustomHttpHeadersTrait.php | 8 +++-- .../Behaviors/Chromium/FailOnTrait.php | 3 +- .../Chromium/PdfPagePropertiesTrait.php | 34 +++---------------- .../ScreenshotPagePropertiesTrait.php | 5 ++- .../Chromium/WaitBeforeRenderingTrait.php | 5 +-- src/Builder/Behaviors/DownloadFromTrait.php | 5 ++- .../LibreOffice/PagePropertiesTrait.php | 4 --- src/Builder/Behaviors/PdfFormatTrait.php | 2 +- src/Builder/Behaviors/SplitTrait.php | 16 +++------ src/Builder/Behaviors/WebhookTrait.php | 20 +---------- src/Builder/Pdf/ConvertPdfBuilder.php | 7 +++- src/Builder/Pdf/FlattenPdfBuilder.php | 10 ++++-- src/Builder/Pdf/HtmlPdfBuilder.php | 7 +++- src/Builder/Pdf/LibreOfficePdfBuilder.php | 7 +++- src/Builder/Pdf/MarkdownPdfBuilder.php | 7 +++- src/Builder/Pdf/MergePdfBuilder.php | 7 +++- src/Builder/Pdf/SplitPdfBuilder.php | 7 +++- src/Builder/Pdf/UrlPdfBuilder.php | 11 +++--- .../Screenshot/HtmlScreenshotBuilder.php | 7 +++- .../Screenshot/MarkdownScreenshotBuilder.php | 7 +++- .../Screenshot/UrlScreenshotBuilder.php | 14 +++++--- src/DependencyInjection/BuilderStack.php | 26 ++++++-------- .../Behaviors/Chromium/AssetTestCaseTrait.php | 26 ++------------ tests/Builder/GotenbergBuilderTestCase.php | 5 +-- tests/Twig/GotenbergRuntimeTest.php | 2 -- 31 files changed, 121 insertions(+), 167 deletions(-) diff --git a/config/services.php b/config/services.php index c374be10..035d0602 100644 --- a/config/services.php +++ b/config/services.php @@ -12,14 +12,11 @@ use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface; use Sensiolabs\GotenbergBundle\Twig\GotenbergExtension; use Sensiolabs\GotenbergBundle\Twig\GotenbergRuntime; -use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistry; -use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistryInterface; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg; use function Symfony\Component\DependencyInjection\Loader\Configurator\param; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; use function Symfony\Component\DependencyInjection\Loader\Configurator\service_locator; -use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_locator; return static function (ContainerConfigurator $container): void { $services = $container->services(); @@ -47,14 +44,14 @@ $services->set('sensiolabs_gotenberg.pdf', GotenbergPdf::class) ->args([ - tagged_locator('sensiolabs_gotenberg.pdf_builder'), + abstract_arg('PDF builders services'), ]) ->alias(GotenbergPdfInterface::class, 'sensiolabs_gotenberg.pdf') ; $services->set('sensiolabs_gotenberg.screenshot', GotenbergScreenshot::class) ->args([ - tagged_locator('sensiolabs_gotenberg.screenshot_builder'), + abstract_arg('Screenshot builders services'), ]) ->alias(GotenbergScreenshotInterface::class, 'sensiolabs_gotenberg.screenshot') ; @@ -72,12 +69,4 @@ $services->set('sensiolabs_gotenberg.http_kernel.stream_builder', ProcessBuilderOnControllerResponse::class) ->tag('kernel.event_listener', ['method' => 'streamBuilder', 'event' => 'kernel.view']) ; - - $services->set('.sensiolabs_gotenberg.webhook_configuration_registry', WebhookConfigurationRegistry::class) - ->args([ - service('router'), - service('.sensiolabs_gotenberg.request_context')->nullOnInvalid(), - ]) - ->alias(WebhookConfigurationRegistryInterface::class, '.sensiolabs_gotenberg.webhook_configuration_registry') - ; }; diff --git a/docs/generate.php b/docs/generate.php index 215334f9..b574a596 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -155,12 +155,12 @@ public function extract(): string $isLast = $lastKey === $key; - if ($isLast === false) { + if (false === $isLast) { $markdown .= '
'; } } - return rtrim($markdown, "
"); + return rtrim($markdown, '
'); }; /** diff --git a/src/Builder/AbstractBuilder.php b/src/Builder/AbstractBuilder.php index a6f7a96f..18dadb1e 100644 --- a/src/Builder/AbstractBuilder.php +++ b/src/Builder/AbstractBuilder.php @@ -102,12 +102,12 @@ public function generateAsync(): GotenbergAsyncResult ); } - protected function getBodyBag(): BodyBag + public function getBodyBag(): BodyBag { return $this->bodyBag; } - protected function getHeadersBag(): HeadersBag + public function getHeadersBag(): HeadersBag { return $this->headersBag; } diff --git a/src/Builder/Attributes/SemanticNode.php b/src/Builder/Attributes/SemanticNode.php index 785df9e1..8ad028cb 100644 --- a/src/Builder/Attributes/SemanticNode.php +++ b/src/Builder/Attributes/SemanticNode.php @@ -7,10 +7,6 @@ final class SemanticNode { public function __construct( public readonly string $name, - public readonly string $type, ) { - if (!\in_array($this->type, ['pdf', 'screenshot'], true)) { - throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); - } } } diff --git a/src/Builder/Behaviors/Chromium/AssetTrait.php b/src/Builder/Behaviors/Chromium/AssetTrait.php index d10d6e3b..a7dde088 100644 --- a/src/Builder/Behaviors/Chromium/AssetTrait.php +++ b/src/Builder/Behaviors/Chromium/AssetTrait.php @@ -19,7 +19,7 @@ abstract protected function getBodyBag(): BodyBag; /** * Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). */ - public function assets(string|\Stringable ...$paths): static + public function assets(string ...$paths): static { $this->getBodyBag()->unset('assets'); @@ -33,9 +33,8 @@ public function assets(string|\Stringable ...$paths): static /** * Adds a file, like an image, font, stylesheet, and so on. */ - public function addAsset(string|\Stringable $path): static + public function addAsset(string $path): static { - $path = (string) $path; $assets = $this->getBodyBag()->get('assets', []); if (\array_key_exists($path, $assets)) { diff --git a/src/Builder/Behaviors/Chromium/ContentTrait.php b/src/Builder/Behaviors/Chromium/ContentTrait.php index 4508b450..ab3cbefa 100644 --- a/src/Builder/Behaviors/Chromium/ContentTrait.php +++ b/src/Builder/Behaviors/Chromium/ContentTrait.php @@ -76,7 +76,7 @@ public function footer(string $template, array $context = []): static } /** - * HTML file containing the header. + * HTML file containing the header. (default None). */ public function headerFile(string $path): static { @@ -84,7 +84,7 @@ public function headerFile(string $path): static } /** - * HTML file containing the footer. + * HTML file containing the footer. (default None). */ public function footerFile(string $path): static { diff --git a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php index 454a090c..f35853d1 100644 --- a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php +++ b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php @@ -15,7 +15,7 @@ trait CustomHttpHeadersTrait abstract protected function getBodyBag(): BodyBag; /** - * Override the default User-Agent HTTP header. + * Override the default User-Agent HTTP header. (default None). * * @param UserAgent::*|string $userAgent * @@ -30,7 +30,8 @@ public function userAgent(string $userAgent): static } /** - * Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers). + * Sets extra HTTP headers that Chromium will send when loading the HTML + * document. (default None). (overrides any previous headers). * * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium * @@ -51,7 +52,8 @@ public function extraHttpHeaders(array $headers): static } /** - * Adds extra HTTP headers that Chromium will send when loading the HTML document. + * Adds extra HTTP headers that Chromium will send when loading the HTML + * document. (default None). * * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium * diff --git a/src/Builder/Behaviors/Chromium/FailOnTrait.php b/src/Builder/Behaviors/Chromium/FailOnTrait.php index 46dc0365..35a5b753 100644 --- a/src/Builder/Behaviors/Chromium/FailOnTrait.php +++ b/src/Builder/Behaviors/Chromium/FailOnTrait.php @@ -30,7 +30,8 @@ public function failOnHttpStatusCodes(array $statusCodes): static } /** - * Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration). + * Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. + * (default None). (overrides any previous configuration). * * @see https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium * diff --git a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php index 18c343fa..96f6cc17 100644 --- a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php @@ -94,8 +94,6 @@ public function paperStandardSize(PaperSizeInterface $paperSize): static /** * Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_top'))] public function marginTop(float $value, Unit $unit = Unit::Inches): static @@ -107,8 +105,6 @@ public function marginTop(float $value, Unit $unit = Unit::Inches): static /** * Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_bottom'))] public function marginBottom(float $value, Unit $unit = Unit::Inches): static @@ -120,8 +116,6 @@ public function marginBottom(float $value, Unit $unit = Unit::Inches): static /** * Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_left'))] public function marginLeft(float $value, Unit $unit = Unit::Inches): static @@ -133,8 +127,6 @@ public function marginLeft(float $value, Unit $unit = Unit::Inches): static /** * Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_right'))] public function marginRight(float $value, Unit $unit = Unit::Inches): static @@ -146,8 +138,6 @@ public function marginRight(float $value, Unit $unit = Unit::Inches): static /** * Overrides the default margins (e.g., 0.39), in inches. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ public function margins(float $top, float $bottom, float $left, float $right, Unit $unit = Unit::Inches): static { @@ -160,9 +150,7 @@ public function margins(float $top, float $bottom, float $left, float $right, Un } /** - * Define whether to prefer page size as defined by CSS. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium + * Define whether to prefer page size as defined by CSS. (Default false). */ #[ExposeSemantic(new BooleanNodeBuilder('prefer_css_page_size'))] public function preferCssPageSize(bool $bool): static @@ -174,8 +162,6 @@ public function preferCssPageSize(bool $bool): static /** * Define whether the document outline should be embedded into the PDF. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('generate_document_outline'))] public function generateDocumentOutline(bool $bool): static @@ -186,9 +172,7 @@ public function generateDocumentOutline(bool $bool): static } /** - * Prints the background graphics. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium + * Prints the background graphics. (Default false). */ #[ExposeSemantic(new BooleanNodeBuilder('print_background'))] public function printBackground(bool $bool): static @@ -200,8 +184,6 @@ public function printBackground(bool $bool): static /** * Hide the default white background and allow generating PDFs with transparency. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] public function omitBackground(bool $bool): static @@ -212,9 +194,7 @@ public function omitBackground(bool $bool): static } /** - * Set the paper orientation to landscape. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium + * Set the paper orientation to landscape. (Default false). */ #[ExposeSemantic(new BooleanNodeBuilder('landscape'))] public function landscape(bool $bool = true): static @@ -225,9 +205,7 @@ public function landscape(bool $bool = true): static } /** - * The scale of the page rendering (e.g., 1.0). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium + * The scale of the page rendering (e.g., 1.0). (Default 1.0). */ #[ExposeSemantic(new FloatNodeBuilder('scale'))] public function scale(float $scale): static @@ -238,9 +216,7 @@ public function scale(float $scale): static } /** - * Page ranges to print, e.g., '1-5, 8, 11-13'. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium + * Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). */ #[ExposeSemantic(new ScalarNodeBuilder('native_page_ranges'))] public function nativePageRanges(string $ranges): static diff --git a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php index 8a4c3729..36d92950 100644 --- a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php @@ -76,9 +76,8 @@ public function quality(int $quality): static } /** - * Hides default white background and allows generating screenshot with transparency. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium + * Hides default white background and allows generating screenshot with + * transparency. (Default false). */ #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] public function omitBackground(bool $bool = true): static diff --git a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php index b51478e2..0da0c363 100644 --- a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php +++ b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php @@ -16,7 +16,7 @@ abstract protected function getBodyBag(): BodyBag; /** * Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML - * document before converting it to PDF. + * document before converting it to PDF. (default None). * * @see https://gotenberg.dev/docs/routes#wait-before-rendering-chromium */ @@ -30,7 +30,8 @@ public function waitDelay(string $delay): static } /** - * Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true. + * Sets the JavaScript expression to wait before converting an HTML + * document to PDF until it returns true. (default None). * * For instance: "window.status === 'ready'". * diff --git a/src/Builder/Behaviors/DownloadFromTrait.php b/src/Builder/Behaviors/DownloadFromTrait.php index 398300ed..e6b398f7 100644 --- a/src/Builder/Behaviors/DownloadFromTrait.php +++ b/src/Builder/Behaviors/DownloadFromTrait.php @@ -18,11 +18,10 @@ trait DownloadFromTrait abstract protected function getBodyBag(): BodyBag; /** - * Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.). + * Sets download from to download each entry (file) in parallel (default None). + * (URLs MUST return a Content-Disposition header with a filename parameter.). * * @param list}> $downloadFrom - * - * @see https://gotenberg.dev/docs/routes#download-from */ #[ExposeSemantic(new ArrayNodeBuilder('download_from', prototype: 'array', children: [ new ScalarNodeBuilder('url', required: true, restrictTo: 'string'), diff --git a/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php b/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php index 1bc19a41..1f4861a8 100644 --- a/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php +++ b/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php @@ -30,8 +30,6 @@ public function password(#[\SensitiveParameter] string $password): static /** * Set the paper orientation to landscape. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('landscape'))] public function landscape(bool $bool = true): static @@ -43,8 +41,6 @@ public function landscape(bool $bool = true): static /** * Page ranges to print, e.g., '1-4' - empty means all pages. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new ScalarNodeBuilder('native_page_ranges'))] public function nativePageRanges(string $ranges): static diff --git a/src/Builder/Behaviors/PdfFormatTrait.php b/src/Builder/Behaviors/PdfFormatTrait.php index 70f9e589..041b55a2 100644 --- a/src/Builder/Behaviors/PdfFormatTrait.php +++ b/src/Builder/Behaviors/PdfFormatTrait.php @@ -33,7 +33,7 @@ public function pdfFormat(PdfFormat|null $format): self } /** - * Enable PDF for Universal Access for optimal accessibility. + * Enable PDF for Universal Access for optimal accessibility. (default false). */ #[ExposeSemantic(new BooleanNodeBuilder('pdf_universal_access'))] public function pdfUniversalAccess(bool $bool = true): self diff --git a/src/Builder/Behaviors/SplitTrait.php b/src/Builder/Behaviors/SplitTrait.php index 4ef116b7..d5deb8bf 100644 --- a/src/Builder/Behaviors/SplitTrait.php +++ b/src/Builder/Behaviors/SplitTrait.php @@ -12,15 +12,15 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\NativeEnumNodeBuilder; use Sensiolabs\GotenbergBundle\NodeBuilder\ScalarNodeBuilder; +/** + * @see https://gotenberg.dev/docs/routes#split-chromium + */ trait SplitTrait { abstract protected function getBodyBag(): BodyBag; /** - * Either intervals or pages. - * - * @see https://gotenberg.dev/docs/routes#split-chromium - * @see https://gotenberg.dev/docs/routes#split-libreoffice + * Either intervals or pages. (default None). */ #[ExposeSemantic(new NativeEnumNodeBuilder('split_mode', enumClass: SplitMode::class))] public function splitMode(SplitMode|null $splitMode = null): self @@ -35,10 +35,7 @@ public function splitMode(SplitMode|null $splitMode = null): self } /** - * Either the intervals or the page ranges to extract, depending on the selected mode. - * - * @see https://gotenberg.dev/docs/routes#split-chromium - * @see https://gotenberg.dev/docs/routes#split-libreoffice + * Either the intervals or the page ranges to extract, depending on the selected mode. (default None). */ #[ExposeSemantic(new ScalarNodeBuilder('split_span'))] public function splitSpan(string $splitSpan): self @@ -51,9 +48,6 @@ public function splitSpan(string $splitSpan): self /** * Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). - * - * @see https://gotenberg.dev/docs/routes#split-chromium - * @see https://gotenberg.dev/docs/routes#split-libreoffice */ #[ExposeSemantic(new BooleanNodeBuilder('split_unify'))] public function splitUnify(bool $bool = true): self diff --git a/src/Builder/Behaviors/WebhookTrait.php b/src/Builder/Behaviors/WebhookTrait.php index 4c8518a9..20f1db42 100644 --- a/src/Builder/Behaviors/WebhookTrait.php +++ b/src/Builder/Behaviors/WebhookTrait.php @@ -106,12 +106,7 @@ public function webhook(array $webhook): static } /** - * Sets the webhook for cases of success. - * Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. - * * @param 'POST'|'PUT'|'PATCH'|null $method - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookUrl(string $url, string|null $method = null): static { @@ -124,12 +119,7 @@ public function webhookUrl(string $url, string|null $method = null): static } /** - * Sets the webhook for cases of success. - * Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. - * * @param 'POST'|'PUT'|'PATCH'|null $method - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookErrorUrl(string $url, string|null $method = null): static { @@ -142,11 +132,7 @@ public function webhookErrorUrl(string $url, string|null $method = null): static } /** - * Extra headers that will be provided to the webhook endpoint. May it either be Success or Error. - * * @param array $extraHttpHeaders - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookExtraHeaders(array $extraHttpHeaders): static { @@ -158,19 +144,15 @@ public function webhookExtraHeaders(array $extraHttpHeaders): static /** * @param array $parameters * @param 'PATCH'|'POST'|'PUT'|null $method - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookRoute(string $route, array $parameters = [], string|null $method = null): static { return $this->webhookUrl($this->getUrlGenerator()->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL), $method); } - /** * + /** * @param array $parameters * @param 'PATCH'|'POST'|'PUT'|null $method - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookErrorRoute(string $route, array $parameters = [], string|null $method = null): static { diff --git a/src/Builder/Pdf/ConvertPdfBuilder.php b/src/Builder/Pdf/ConvertPdfBuilder.php index eb284750..dc878ae6 100644 --- a/src/Builder/Pdf/ConvertPdfBuilder.php +++ b/src/Builder/Pdf/ConvertPdfBuilder.php @@ -16,7 +16,7 @@ /** * @see https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route */ -#[SemanticNode('convert', 'pdf')] +#[SemanticNode('convert')] final class ConvertPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -62,4 +62,9 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } + + public static function type(): string + { + return 'pdf'; + } } diff --git a/src/Builder/Pdf/FlattenPdfBuilder.php b/src/Builder/Pdf/FlattenPdfBuilder.php index 82ac04f1..61e282c2 100644 --- a/src/Builder/Pdf/FlattenPdfBuilder.php +++ b/src/Builder/Pdf/FlattenPdfBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#flatten-pdfs-route */ -#[SemanticNode('flatten', 'pdf')] +#[SemanticNode('flatten')] final class FlattenPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -24,10 +24,9 @@ final class FlattenPdfBuilder extends AbstractBuilder public const ENDPOINT = '/forms/pdfengines/flatten'; - public function files(string|\Stringable ...$paths): self + public function files(string ...$paths): self { foreach ($paths as $path) { - $path = (string) $path; $info = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); ValidatorFactory::filesExtension([$info], ['pdf']); @@ -56,4 +55,9 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } + + public static function type(): string + { + return 'pdf'; + } } diff --git a/src/Builder/Pdf/HtmlPdfBuilder.php b/src/Builder/Pdf/HtmlPdfBuilder.php index 0d03f445..78853a76 100644 --- a/src/Builder/Pdf/HtmlPdfBuilder.php +++ b/src/Builder/Pdf/HtmlPdfBuilder.php @@ -12,7 +12,7 @@ /** * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route */ -#[SemanticNode('html', 'pdf')] +#[SemanticNode('html')] final class HtmlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait; @@ -30,4 +30,9 @@ protected function validatePayloadBody(): void throw new MissingRequiredFieldException('Content is required'); } } + + public static function type(): string + { + return 'pdf'; + } } diff --git a/src/Builder/Pdf/LibreOfficePdfBuilder.php b/src/Builder/Pdf/LibreOfficePdfBuilder.php index fd79131d..975c05bf 100644 --- a/src/Builder/Pdf/LibreOfficePdfBuilder.php +++ b/src/Builder/Pdf/LibreOfficePdfBuilder.php @@ -16,7 +16,7 @@ /** * @see https://gotenberg.dev/docs/routes#convert-with-libreoffice */ -#[SemanticNode('office', 'pdf')] +#[SemanticNode('office')] final class LibreOfficePdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -76,4 +76,9 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } + + public static function type(): string + { + return 'pdf'; + } } diff --git a/src/Builder/Pdf/MarkdownPdfBuilder.php b/src/Builder/Pdf/MarkdownPdfBuilder.php index 7f080bdd..a8f0c070 100644 --- a/src/Builder/Pdf/MarkdownPdfBuilder.php +++ b/src/Builder/Pdf/MarkdownPdfBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ -#[SemanticNode('markdown', 'pdf')] +#[SemanticNode('markdown')] final class MarkdownPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait { @@ -79,4 +79,9 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } + + public static function type(): string + { + return 'pdf'; + } } diff --git a/src/Builder/Pdf/MergePdfBuilder.php b/src/Builder/Pdf/MergePdfBuilder.php index a57e66e1..962ddeac 100644 --- a/src/Builder/Pdf/MergePdfBuilder.php +++ b/src/Builder/Pdf/MergePdfBuilder.php @@ -18,7 +18,7 @@ /** * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ -#[SemanticNode('merge', 'pdf')] +#[SemanticNode('merge')] final class MergePdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -67,4 +67,9 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } + + public static function type(): string + { + return 'pdf'; + } } diff --git a/src/Builder/Pdf/SplitPdfBuilder.php b/src/Builder/Pdf/SplitPdfBuilder.php index 29a8f3ba..c15189d7 100644 --- a/src/Builder/Pdf/SplitPdfBuilder.php +++ b/src/Builder/Pdf/SplitPdfBuilder.php @@ -19,7 +19,7 @@ /** * @see https://gotenberg.dev/docs/routes#split-pdfs-route */ -#[SemanticNode('split', 'pdf')] +#[SemanticNode('split')] final class SplitPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -72,4 +72,9 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } + + public static function type(): string + { + return 'pdf'; + } } diff --git a/src/Builder/Pdf/UrlPdfBuilder.php b/src/Builder/Pdf/UrlPdfBuilder.php index 0e642745..d1aef4ea 100644 --- a/src/Builder/Pdf/UrlPdfBuilder.php +++ b/src/Builder/Pdf/UrlPdfBuilder.php @@ -14,7 +14,7 @@ /** * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ -#[SemanticNode('url', 'pdf')] +#[SemanticNode('url')] final class UrlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait; @@ -25,8 +25,6 @@ final class UrlPdfBuilder extends AbstractBuilder implements BuilderAssetInterfa /** * URL of the page you want to convert into PDF. - * - * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function url(string $url): self { @@ -38,8 +36,6 @@ public function url(string $url): self /** * @param string $name #Route * @param array $parameters - * - * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function route(string $name, array $parameters = []): self { @@ -79,4 +75,9 @@ private function normalizeRoute(): \Generator { yield 'route' => NormalizerFactory::route($this->requestContext, $this->getUrlGenerator()); } + + public static function type(): string + { + return 'pdf'; + } } diff --git a/src/Builder/Screenshot/HtmlScreenshotBuilder.php b/src/Builder/Screenshot/HtmlScreenshotBuilder.php index f6aad76b..6a0b15ec 100644 --- a/src/Builder/Screenshot/HtmlScreenshotBuilder.php +++ b/src/Builder/Screenshot/HtmlScreenshotBuilder.php @@ -12,7 +12,7 @@ /** * @see https://gotenberg.dev/docs/routes#screenshots-route */ -#[SemanticNode('html', 'screenshot')] +#[SemanticNode('html')] final class HtmlScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait; @@ -30,4 +30,9 @@ protected function validatePayloadBody(): void throw new MissingRequiredFieldException('Content is required'); } } + + public static function type(): string + { + return 'screenshot'; + } } diff --git a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php index e9a57ce5..3f92b660 100644 --- a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php +++ b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#screenshots-route */ -#[SemanticNode('markdown', 'screenshot')] +#[SemanticNode('markdown')] final class MarkdownScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait { @@ -79,4 +79,9 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } + + public static function type(): string + { + return 'screenshot'; + } } diff --git a/src/Builder/Screenshot/UrlScreenshotBuilder.php b/src/Builder/Screenshot/UrlScreenshotBuilder.php index b21068d3..a4dabba1 100644 --- a/src/Builder/Screenshot/UrlScreenshotBuilder.php +++ b/src/Builder/Screenshot/UrlScreenshotBuilder.php @@ -11,7 +11,10 @@ use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Symfony\Component\Routing\RequestContext; -#[SemanticNode('url', 'screenshot')] +/** + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route + */ +#[SemanticNode('url')] final class UrlScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait; @@ -22,8 +25,6 @@ final class UrlScreenshotBuilder extends AbstractBuilder implements BuilderAsset /** * URL of the page you want to convert into PDF. - * - * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function url(string $url): self { @@ -35,8 +36,6 @@ public function url(string $url): self /** * @param string $name #Route * @param array $parameters - * - * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function route(string $name, array $parameters = []): self { @@ -73,4 +72,9 @@ private function normalizeRoute(): \Generator { yield 'route' => NormalizerFactory::route($this->requestContext, $this->getUrlGenerator()); } + + public static function type(): string + { + return 'screenshot'; + } } diff --git a/src/DependencyInjection/BuilderStack.php b/src/DependencyInjection/BuilderStack.php index 5586f5fa..51207a0f 100644 --- a/src/DependencyInjection/BuilderStack.php +++ b/src/DependencyInjection/BuilderStack.php @@ -49,16 +49,16 @@ public function push(string $class): void throw new \LogicException("{$class} has already been added."); } -// $type = 'custom'; -// if (method_exists($class, 'type')) { -// $type = $class::type(); -// } -// -// if (!\in_array($type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock -// throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); -// } -// -// $this->builders[$class] = $type; + $type = 'custom'; + if (method_exists($class, 'type')) { + $type = $class::type(); + } + + if (!\in_array($type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock + throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); + } + + $this->builders[$class] = $type; $reflection = new \ReflectionClass($class); $nodeAttributes = $reflection->getAttributes(SemanticNode::class); @@ -70,11 +70,7 @@ public function push(string $class): void /** @var SemanticNode $semanticNode */ $semanticNode = $nodeAttributes[0]->newInstance(); - if (!\in_array($semanticNode->type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock - throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); - } - - $this->typeReverseMapping[$semanticNode->type][$semanticNode->name] = $class; + $this->typeReverseMapping[$type][$semanticNode->name] = $class; foreach (array_reverse($reflection->getMethods(\ReflectionMethod::IS_PUBLIC)) as $method) { $attributes = $method->getAttributes(ExposeSemantic::class); diff --git a/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php index a0651bab..f687e68f 100644 --- a/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php +++ b/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php @@ -14,35 +14,15 @@ trait AssetTestCaseTrait use BehaviorTrait; abstract protected function assertContentFile(string $filename, string $contentType = 'text/html', string|null $expectedContent = null): void; - abstract protected function assertGotenbergFormDataFile(string $name, string $contentType, string $path): void; - /** - * @dataProvider provideTestToAddAssets - */ - public function testToAddAssets(string|\Stringable $asset, string $expectedFilename, string $expectedContentType, string $expectedPath): void + public function testToAddAssets(): void { $this->getDefaultBuilder() - ->assets($asset) + ->assets('assets/logo.png') ->generate() ; - $this->assertGotenbergFormDataFile($expectedFilename, $expectedContentType, $expectedPath); - - $this->assertContentFile($expectedFilename, $expectedContentType); - } - - public static function provideTestToAddAssets(): \Generator - { - yield 'string' => ['assets/logo.png', 'logo.png', 'image/png', self::FIXTURE_DIR.'/assets/logo.png']; - yield 'SplFileInfo' => [new \SplFileInfo('assets/logo.png'), 'logo.png', 'image/png', 'assets/logo.png']; - - $stringable = new class implements \Stringable { - public function __toString(): string - { - return 'assets/logo.png'; - } - }; - yield 'Stringable' => [$stringable, 'logo.png', 'image/png', 'assets/logo.png']; + $this->assertContentFile('logo.png', 'image/png'); } public function testToAddAssetsToExistingAssets(): void diff --git a/tests/Builder/GotenbergBuilderTestCase.php b/tests/Builder/GotenbergBuilderTestCase.php index b9467082..3721e152 100644 --- a/tests/Builder/GotenbergBuilderTestCase.php +++ b/tests/Builder/GotenbergBuilderTestCase.php @@ -92,7 +92,6 @@ protected function assertGotenbergFormData(string $name, string $value): void protected function assertGotenbergFormDataFile(string $name, string $contentType, string $path): void { - dd($this->client->getBody()); foreach ($this->client->getBody() as $part) { if (!$part instanceof DataPart) { continue; @@ -138,9 +137,7 @@ protected function assertContentFile(string $filename, string $contentType = 'te self::assertSame($expectedContent, $part->getBody()); } - return; + iterator_to_array($part->bodyToIterable()); } - - $this->fail(\sprintf('No matching content file found with name "%s" and content type "%s".', $filename, $contentType)); } } diff --git a/tests/Twig/GotenbergRuntimeTest.php b/tests/Twig/GotenbergRuntimeTest.php index 4777ca52..a902d33d 100644 --- a/tests/Twig/GotenbergRuntimeTest.php +++ b/tests/Twig/GotenbergRuntimeTest.php @@ -5,8 +5,6 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; -use Sensiolabs\GotenbergBundle\Builder\Pdf\AbstractChromiumPdfBuilder; -use Sensiolabs\GotenbergBundle\Builder\Screenshot\AbstractChromiumScreenshotBuilder; use Sensiolabs\GotenbergBundle\Twig\GotenbergRuntime; #[CoversClass(GotenbergRuntime::class)] From 14181845bc359cdca413722b2995dd649f139642 Mon Sep 17 00:00:00 2001 From: "hubert.lenoir" Date: Thu, 10 Apr 2025 17:57:10 +0200 Subject: [PATCH 08/30] fix(doc): annotations --- docs/pdf/builders_api/ConvertPdfBuilder.md | 31 +++- docs/pdf/builders_api/HtmlPdfBuilder.md | 125 ++++++++++++---- .../pdf/builders_api/LibreOfficePdfBuilder.md | 59 ++++++-- docs/pdf/builders_api/MarkdownPdfBuilder.md | 125 ++++++++++++---- docs/pdf/builders_api/MergePdfBuilder.md | 31 +++- docs/pdf/builders_api/SplitPdfBuilder.md | 49 +++++-- docs/pdf/builders_api/UrlPdfBuilder.md | 133 ++++++++++++++---- .../builders_api/HtmlScreenshotBuilder.md | 50 +++++-- .../builders_api/MarkdownScreenshotBuilder.md | 50 +++++-- .../builders_api/UrlScreenshotBuilder.md | 61 +++++--- src/Builder/AbstractBuilder.php | 4 +- src/Builder/Attributes/SemanticNode.php | 4 + .../Behaviors/Chromium/ContentTrait.php | 4 +- .../Chromium/CustomHttpHeadersTrait.php | 8 +- .../Behaviors/Chromium/FailOnTrait.php | 3 +- .../Chromium/PdfPagePropertiesTrait.php | 34 ++++- .../ScreenshotPagePropertiesTrait.php | 5 +- .../Chromium/WaitBeforeRenderingTrait.php | 5 +- src/Builder/Behaviors/DownloadFromTrait.php | 5 +- .../LibreOffice/PagePropertiesTrait.php | 4 + src/Builder/Behaviors/PdfFormatTrait.php | 2 +- src/Builder/Behaviors/SplitTrait.php | 16 ++- src/Builder/Behaviors/WebhookTrait.php | 20 ++- src/Builder/Pdf/ConvertPdfBuilder.php | 7 +- src/Builder/Pdf/FlattenPdfBuilder.php | 7 +- src/Builder/Pdf/HtmlPdfBuilder.php | 7 +- src/Builder/Pdf/LibreOfficePdfBuilder.php | 7 +- src/Builder/Pdf/MarkdownPdfBuilder.php | 7 +- src/Builder/Pdf/MergePdfBuilder.php | 7 +- src/Builder/Pdf/SplitPdfBuilder.php | 7 +- src/Builder/Pdf/UrlPdfBuilder.php | 11 +- .../Screenshot/HtmlScreenshotBuilder.php | 7 +- .../Screenshot/MarkdownScreenshotBuilder.php | 7 +- .../Screenshot/UrlScreenshotBuilder.php | 14 +- src/DependencyInjection/BuilderStack.php | 26 ++-- 35 files changed, 676 insertions(+), 266 deletions(-) diff --git a/docs/pdf/builders_api/ConvertPdfBuilder.md b/docs/pdf/builders_api/ConvertPdfBuilder.md index 390654b8..f4210a1d 100644 --- a/docs/pdf/builders_api/ConvertPdfBuilder.md +++ b/docs/pdf/builders_api/ConvertPdfBuilder.md @@ -4,21 +4,42 @@ > See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### files(Stringable|string $paths) -### getBodyBag() -### getHeadersBag() ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. -### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index 584f0171..a002c442 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -67,35 +70,54 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### forwardCookie(string $name) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF. +Define whether the document outline should be embedded into the PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### landscape(bool $bool) -Set the paper orientation to landscape. (Default false). +Set the paper orientation to landscape.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches. +Overrides the default margins (e.g., 0.39), in inches.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### metadata(array $metadata) Resets the metadata.
@@ -108,10 +130,16 @@ Resets the metadata.
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). +Page ranges to print, e.g., '1-5, 8, 11-13'.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### omitBackground(bool $bool) -Hide the default white background and allow generating PDFs with transparency. +Hide the default white background and allow generating PDFs with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. @@ -127,16 +155,25 @@ Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. De Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS. (Default false). +Define whether to prefer page size as defined by CSS.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### printBackground(bool $bool) -Prints the background graphics. (Default false). +Prints the background graphics.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### scale(float $scale) -The scale of the page rendering (e.g., 1.0). (Default 1.0). +The scale of the page rendering (e.g., 1.0).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### singlePage(bool $bool) @@ -144,36 +181,68 @@ Define whether to print the entire content in one single page.

If the ### skipNetworkIdleEvent(bool $bool) ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index 9ae7749a..2bea2aff 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -25,7 +25,10 @@ Specify whether form fields are exported as widgets or only their fixed print re Specify whether to update the indexes before conversion, keeping in mind that doing so might result in missing links in the final PDF. ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### exportBookmarksToPdfDestination(bool $bool) Specify that the bookmarks contained in the source LibreOffice file should be exported to the PDF file as Named Destination. @@ -57,10 +60,11 @@ Adds office files to convert (overrides any previous files). ### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -### getBodyBag() -### getHeadersBag() ### landscape(bool $bool) -Set the paper orientation to landscape. +Set the paper orientation to landscape.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### losslessImageCompression(bool $bool) Specify if images are exported to PDF using a lossless compression format like PNG or compressed using the JPEG format. @@ -82,7 +86,10 @@ Resets the metadata.
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-4' - empty means all pages. +Page ranges to print, e.g., '1-4' - empty means all pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### password(string $password) Set the password for opening the source file. @@ -91,7 +98,7 @@ Set the password for opening the source file. Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### quality(int $quality) Specify the quality of the JPG export. A higher value produces a higher-quality image and a larger file. Between 1 and 100.
@@ -106,18 +113,50 @@ Ignore each sheet’s paper size, print ranges and shown/hidden status and puts Specify that automatically inserted empty pages are suppressed. This option is active only if storing Writer documents. ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 88a2afe5..9c5b80cd 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -73,35 +76,54 @@ Add Markdown into a PDF.
### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### forwardCookie(string $name) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF. +Define whether the document outline should be embedded into the PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### landscape(bool $bool) -Set the paper orientation to landscape. (Default false). +Set the paper orientation to landscape.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches. +Overrides the default margins (e.g., 0.39), in inches.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### metadata(array $metadata) Resets the metadata.
@@ -114,10 +136,16 @@ Resets the metadata.
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). +Page ranges to print, e.g., '1-5, 8, 11-13'.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### omitBackground(bool $bool) -Hide the default white background and allow generating PDFs with transparency. +Hide the default white background and allow generating PDFs with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. @@ -133,16 +161,25 @@ Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. De Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS. (Default false). +Define whether to prefer page size as defined by CSS.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### printBackground(bool $bool) -Prints the background graphics. (Default false). +Prints the background graphics.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### scale(float $scale) -The scale of the page rendering (e.g., 1.0). (Default 1.0). +The scale of the page rendering (e.g., 1.0).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### singlePage(bool $bool) @@ -150,39 +187,71 @@ Define whether to print the entire content in one single page.

If the ### skipNetworkIdleEvent(bool $bool) ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### wrapper(string $template, array $context) ### wrapperFile(string $path) The HTML file to convert into PDF. diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index cf891c6d..d651dae9 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -7,7 +7,10 @@ The metadata to write. ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### files(Stringable|string $paths) Add PDF files to merge.
@@ -18,8 +21,6 @@ Add PDF files to merge.
### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -### getBodyBag() -### getHeadersBag() ### metadata(array $metadata) Resets the metadata.
@@ -34,12 +35,32 @@ Resets the metadata.
Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. -### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index 9b691bb2..13f4aad1 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -7,14 +7,15 @@ The metadata to write. ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### files(Stringable|string $paths) ### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -### getBodyBag() -### getHeadersBag() ### metadata(array $metadata) Resets the metadata.
@@ -29,21 +30,53 @@ Resets the metadata.
Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index 36790a61..bcaa55e5 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -67,35 +70,54 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### forwardCookie(string $name) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF. +Define whether the document outline should be embedded into the PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### landscape(bool $bool) -Set the paper orientation to landscape. (Default false). +Set the paper orientation to landscape.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches. +Overrides the default margins (e.g., 0.39), in inches.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### metadata(array $metadata) Resets the metadata.
@@ -108,10 +130,16 @@ Resets the metadata.
> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). +Page ranges to print, e.g., '1-5, 8, 11-13'.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### omitBackground(bool $bool) -Hide the default white background and allow generating PDFs with transparency. +Hide the default white background and allow generating PDFs with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. @@ -127,17 +155,29 @@ Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. De Convert the resulting PDF into the given PDF/A format. ### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. (default false). +Enable PDF for Universal Access for optimal accessibility. ### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS. (Default false). +Define whether to prefer page size as defined by CSS.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### printBackground(bool $bool) -Prints the background graphics. (Default false). +Prints the background graphics.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### route(string $name, array $parameters) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) + ### scale(float $scale) -The scale of the page rendering (e.g., 1.0). (Default 1.0). +The scale of the page rendering (e.g., 1.0).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) @@ -146,39 +186,74 @@ Define whether to print the entire content in one single page.

If the ### skipNetworkIdleEvent(bool $bool) ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. (default None). +Either intervals or pages.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. (default None). +Either the intervals or the page ranges to extract, depending on the selected mode.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) ### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-chromium](https://gotenberg.dev/docs/routes#split-chromium) +> See: [https://gotenberg.dev/docs/routes#split-libreoffice](https://gotenberg.dev/docs/routes#split-libreoffice) -### type() ### url(string $url) -URL of the page you want to convert into PDF. +URL of the page you want to convert into PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index 178e91cb..8922f44b 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -67,23 +70,24 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### height(int $height) The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with
transparency. (Default false). +Hides default white background and allows generating screenshot with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). @@ -93,31 +97,51 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### skipNetworkIdleEvent(bool $bool) -### type() ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### width(int $width) The device screen width in pixels. (Default 800). diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index ae9d0bc2..959ebded 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -13,7 +13,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +30,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +57,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -73,23 +76,24 @@ Add Markdown into a PDF.
### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### height(int $height) The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with
transparency. (Default false). +Hides default white background and allows generating screenshot with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). @@ -99,31 +103,51 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### skipNetworkIdleEvent(bool $bool) -### type() ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### width(int $width) The device screen width in pixels. (Default 800). diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index 11cd46c4..84746c9b 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -1,8 +1,5 @@ # UrlScreenshotBuilder -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. @@ -13,7 +10,7 @@ Add cookies to store in the Chromium cookie jar.
> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) ### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML
document. (default None).
+Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -30,13 +27,16 @@ The HTML file to convert into PDF. ### cookies(array $cookies) ### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (default None).
(URLs MUST return a Content-Disposition header with a filename parameter.).
+Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
+Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) @@ -54,7 +54,7 @@ Return a 409 Conflict response if the HTTP status code from
the main page i > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable.
(default None). (overrides any previous configuration).
+Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) @@ -67,23 +67,24 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) ### footerFile(string $path) -HTML file containing the footer. (default None). +HTML file containing the footer. ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) -### getBodyBag() -### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) -HTML file containing the header. (default None). +HTML file containing the header. ### height(int $height) The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with
transparency. (Default false). +Hides default white background and allows generating screenshot with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). @@ -92,37 +93,63 @@ Define whether to optimize image encoding for speed, not for resulting size. (De The compression quality from range 0 to 100 (jpeg only). (default 100).
### route(string $name, array $parameters) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) + ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) ### skipNetworkIdleEvent(bool $bool) -### type() ### url(string $url) -URL of the page you want to convert into PDF. +URL of the page you want to convert into PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### userAgent(string $userAgent) -Override the default User-Agent HTTP header. (default None).
+Override the default User-Agent HTTP header.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) ### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF. (default None).
+Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML
document to PDF until it returns true. (default None).

For instance: "window.status === 'ready'".
+Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### width(int $width) The device screen width in pixels. (Default 800). diff --git a/src/Builder/AbstractBuilder.php b/src/Builder/AbstractBuilder.php index 18dadb1e..a6f7a96f 100644 --- a/src/Builder/AbstractBuilder.php +++ b/src/Builder/AbstractBuilder.php @@ -102,12 +102,12 @@ public function generateAsync(): GotenbergAsyncResult ); } - public function getBodyBag(): BodyBag + protected function getBodyBag(): BodyBag { return $this->bodyBag; } - public function getHeadersBag(): HeadersBag + protected function getHeadersBag(): HeadersBag { return $this->headersBag; } diff --git a/src/Builder/Attributes/SemanticNode.php b/src/Builder/Attributes/SemanticNode.php index 8ad028cb..785df9e1 100644 --- a/src/Builder/Attributes/SemanticNode.php +++ b/src/Builder/Attributes/SemanticNode.php @@ -7,6 +7,10 @@ final class SemanticNode { public function __construct( public readonly string $name, + public readonly string $type, ) { + if (!\in_array($this->type, ['pdf', 'screenshot'], true)) { + throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); + } } } diff --git a/src/Builder/Behaviors/Chromium/ContentTrait.php b/src/Builder/Behaviors/Chromium/ContentTrait.php index ab3cbefa..4508b450 100644 --- a/src/Builder/Behaviors/Chromium/ContentTrait.php +++ b/src/Builder/Behaviors/Chromium/ContentTrait.php @@ -76,7 +76,7 @@ public function footer(string $template, array $context = []): static } /** - * HTML file containing the header. (default None). + * HTML file containing the header. */ public function headerFile(string $path): static { @@ -84,7 +84,7 @@ public function headerFile(string $path): static } /** - * HTML file containing the footer. (default None). + * HTML file containing the footer. */ public function footerFile(string $path): static { diff --git a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php index f35853d1..454a090c 100644 --- a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php +++ b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php @@ -15,7 +15,7 @@ trait CustomHttpHeadersTrait abstract protected function getBodyBag(): BodyBag; /** - * Override the default User-Agent HTTP header. (default None). + * Override the default User-Agent HTTP header. * * @param UserAgent::*|string $userAgent * @@ -30,8 +30,7 @@ public function userAgent(string $userAgent): static } /** - * Sets extra HTTP headers that Chromium will send when loading the HTML - * document. (default None). (overrides any previous headers). + * Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers). * * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium * @@ -52,8 +51,7 @@ public function extraHttpHeaders(array $headers): static } /** - * Adds extra HTTP headers that Chromium will send when loading the HTML - * document. (default None). + * Adds extra HTTP headers that Chromium will send when loading the HTML document. * * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium * diff --git a/src/Builder/Behaviors/Chromium/FailOnTrait.php b/src/Builder/Behaviors/Chromium/FailOnTrait.php index 35a5b753..46dc0365 100644 --- a/src/Builder/Behaviors/Chromium/FailOnTrait.php +++ b/src/Builder/Behaviors/Chromium/FailOnTrait.php @@ -30,8 +30,7 @@ public function failOnHttpStatusCodes(array $statusCodes): static } /** - * Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. - * (default None). (overrides any previous configuration). + * Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration). * * @see https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium * diff --git a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php index 96f6cc17..18c343fa 100644 --- a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php @@ -94,6 +94,8 @@ public function paperStandardSize(PaperSizeInterface $paperSize): static /** * Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_top'))] public function marginTop(float $value, Unit $unit = Unit::Inches): static @@ -105,6 +107,8 @@ public function marginTop(float $value, Unit $unit = Unit::Inches): static /** * Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_bottom'))] public function marginBottom(float $value, Unit $unit = Unit::Inches): static @@ -116,6 +120,8 @@ public function marginBottom(float $value, Unit $unit = Unit::Inches): static /** * Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_left'))] public function marginLeft(float $value, Unit $unit = Unit::Inches): static @@ -127,6 +133,8 @@ public function marginLeft(float $value, Unit $unit = Unit::Inches): static /** * Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_right'))] public function marginRight(float $value, Unit $unit = Unit::Inches): static @@ -138,6 +146,8 @@ public function marginRight(float $value, Unit $unit = Unit::Inches): static /** * Overrides the default margins (e.g., 0.39), in inches. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ public function margins(float $top, float $bottom, float $left, float $right, Unit $unit = Unit::Inches): static { @@ -150,7 +160,9 @@ public function margins(float $top, float $bottom, float $left, float $right, Un } /** - * Define whether to prefer page size as defined by CSS. (Default false). + * Define whether to prefer page size as defined by CSS. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('prefer_css_page_size'))] public function preferCssPageSize(bool $bool): static @@ -162,6 +174,8 @@ public function preferCssPageSize(bool $bool): static /** * Define whether the document outline should be embedded into the PDF. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('generate_document_outline'))] public function generateDocumentOutline(bool $bool): static @@ -172,7 +186,9 @@ public function generateDocumentOutline(bool $bool): static } /** - * Prints the background graphics. (Default false). + * Prints the background graphics. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('print_background'))] public function printBackground(bool $bool): static @@ -184,6 +200,8 @@ public function printBackground(bool $bool): static /** * Hide the default white background and allow generating PDFs with transparency. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] public function omitBackground(bool $bool): static @@ -194,7 +212,9 @@ public function omitBackground(bool $bool): static } /** - * Set the paper orientation to landscape. (Default false). + * Set the paper orientation to landscape. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('landscape'))] public function landscape(bool $bool = true): static @@ -205,7 +225,9 @@ public function landscape(bool $bool = true): static } /** - * The scale of the page rendering (e.g., 1.0). (Default 1.0). + * The scale of the page rendering (e.g., 1.0). + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new FloatNodeBuilder('scale'))] public function scale(float $scale): static @@ -216,7 +238,9 @@ public function scale(float $scale): static } /** - * Page ranges to print, e.g., '1-5, 8, 11-13'. (default All pages). + * Page ranges to print, e.g., '1-5, 8, 11-13'. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new ScalarNodeBuilder('native_page_ranges'))] public function nativePageRanges(string $ranges): static diff --git a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php index 36d92950..8a4c3729 100644 --- a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php @@ -76,8 +76,9 @@ public function quality(int $quality): static } /** - * Hides default white background and allows generating screenshot with - * transparency. (Default false). + * Hides default white background and allows generating screenshot with transparency. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] public function omitBackground(bool $bool = true): static diff --git a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php index 0da0c363..b51478e2 100644 --- a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php +++ b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php @@ -16,7 +16,7 @@ abstract protected function getBodyBag(): BodyBag; /** * Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML - * document before converting it to PDF. (default None). + * document before converting it to PDF. * * @see https://gotenberg.dev/docs/routes#wait-before-rendering-chromium */ @@ -30,8 +30,7 @@ public function waitDelay(string $delay): static } /** - * Sets the JavaScript expression to wait before converting an HTML - * document to PDF until it returns true. (default None). + * Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true. * * For instance: "window.status === 'ready'". * diff --git a/src/Builder/Behaviors/DownloadFromTrait.php b/src/Builder/Behaviors/DownloadFromTrait.php index e6b398f7..398300ed 100644 --- a/src/Builder/Behaviors/DownloadFromTrait.php +++ b/src/Builder/Behaviors/DownloadFromTrait.php @@ -18,10 +18,11 @@ trait DownloadFromTrait abstract protected function getBodyBag(): BodyBag; /** - * Sets download from to download each entry (file) in parallel (default None). - * (URLs MUST return a Content-Disposition header with a filename parameter.). + * Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.). * * @param list}> $downloadFrom + * + * @see https://gotenberg.dev/docs/routes#download-from */ #[ExposeSemantic(new ArrayNodeBuilder('download_from', prototype: 'array', children: [ new ScalarNodeBuilder('url', required: true, restrictTo: 'string'), diff --git a/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php b/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php index 1f4861a8..1bc19a41 100644 --- a/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php +++ b/src/Builder/Behaviors/LibreOffice/PagePropertiesTrait.php @@ -30,6 +30,8 @@ public function password(#[\SensitiveParameter] string $password): static /** * Set the paper orientation to landscape. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('landscape'))] public function landscape(bool $bool = true): static @@ -41,6 +43,8 @@ public function landscape(bool $bool = true): static /** * Page ranges to print, e.g., '1-4' - empty means all pages. + * + * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new ScalarNodeBuilder('native_page_ranges'))] public function nativePageRanges(string $ranges): static diff --git a/src/Builder/Behaviors/PdfFormatTrait.php b/src/Builder/Behaviors/PdfFormatTrait.php index 041b55a2..70f9e589 100644 --- a/src/Builder/Behaviors/PdfFormatTrait.php +++ b/src/Builder/Behaviors/PdfFormatTrait.php @@ -33,7 +33,7 @@ public function pdfFormat(PdfFormat|null $format): self } /** - * Enable PDF for Universal Access for optimal accessibility. (default false). + * Enable PDF for Universal Access for optimal accessibility. */ #[ExposeSemantic(new BooleanNodeBuilder('pdf_universal_access'))] public function pdfUniversalAccess(bool $bool = true): self diff --git a/src/Builder/Behaviors/SplitTrait.php b/src/Builder/Behaviors/SplitTrait.php index d5deb8bf..4ef116b7 100644 --- a/src/Builder/Behaviors/SplitTrait.php +++ b/src/Builder/Behaviors/SplitTrait.php @@ -12,15 +12,15 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\NativeEnumNodeBuilder; use Sensiolabs\GotenbergBundle\NodeBuilder\ScalarNodeBuilder; -/** - * @see https://gotenberg.dev/docs/routes#split-chromium - */ trait SplitTrait { abstract protected function getBodyBag(): BodyBag; /** - * Either intervals or pages. (default None). + * Either intervals or pages. + * + * @see https://gotenberg.dev/docs/routes#split-chromium + * @see https://gotenberg.dev/docs/routes#split-libreoffice */ #[ExposeSemantic(new NativeEnumNodeBuilder('split_mode', enumClass: SplitMode::class))] public function splitMode(SplitMode|null $splitMode = null): self @@ -35,7 +35,10 @@ public function splitMode(SplitMode|null $splitMode = null): self } /** - * Either the intervals or the page ranges to extract, depending on the selected mode. (default None). + * Either the intervals or the page ranges to extract, depending on the selected mode. + * + * @see https://gotenberg.dev/docs/routes#split-chromium + * @see https://gotenberg.dev/docs/routes#split-libreoffice */ #[ExposeSemantic(new ScalarNodeBuilder('split_span'))] public function splitSpan(string $splitSpan): self @@ -48,6 +51,9 @@ public function splitSpan(string $splitSpan): self /** * Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). + * + * @see https://gotenberg.dev/docs/routes#split-chromium + * @see https://gotenberg.dev/docs/routes#split-libreoffice */ #[ExposeSemantic(new BooleanNodeBuilder('split_unify'))] public function splitUnify(bool $bool = true): self diff --git a/src/Builder/Behaviors/WebhookTrait.php b/src/Builder/Behaviors/WebhookTrait.php index 20f1db42..4c8518a9 100644 --- a/src/Builder/Behaviors/WebhookTrait.php +++ b/src/Builder/Behaviors/WebhookTrait.php @@ -106,7 +106,12 @@ public function webhook(array $webhook): static } /** + * Sets the webhook for cases of success. + * Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. + * * @param 'POST'|'PUT'|'PATCH'|null $method + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookUrl(string $url, string|null $method = null): static { @@ -119,7 +124,12 @@ public function webhookUrl(string $url, string|null $method = null): static } /** + * Sets the webhook for cases of success. + * Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. + * * @param 'POST'|'PUT'|'PATCH'|null $method + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookErrorUrl(string $url, string|null $method = null): static { @@ -132,7 +142,11 @@ public function webhookErrorUrl(string $url, string|null $method = null): static } /** + * Extra headers that will be provided to the webhook endpoint. May it either be Success or Error. + * * @param array $extraHttpHeaders + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookExtraHeaders(array $extraHttpHeaders): static { @@ -144,15 +158,19 @@ public function webhookExtraHeaders(array $extraHttpHeaders): static /** * @param array $parameters * @param 'PATCH'|'POST'|'PUT'|null $method + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookRoute(string $route, array $parameters = [], string|null $method = null): static { return $this->webhookUrl($this->getUrlGenerator()->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL), $method); } - /** + /** * * @param array $parameters * @param 'PATCH'|'POST'|'PUT'|null $method + * + * @see https://gotenberg.dev/docs/webhook */ public function webhookErrorRoute(string $route, array $parameters = [], string|null $method = null): static { diff --git a/src/Builder/Pdf/ConvertPdfBuilder.php b/src/Builder/Pdf/ConvertPdfBuilder.php index dc878ae6..eb284750 100644 --- a/src/Builder/Pdf/ConvertPdfBuilder.php +++ b/src/Builder/Pdf/ConvertPdfBuilder.php @@ -16,7 +16,7 @@ /** * @see https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route */ -#[SemanticNode('convert')] +#[SemanticNode('convert', 'pdf')] final class ConvertPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -62,9 +62,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/FlattenPdfBuilder.php b/src/Builder/Pdf/FlattenPdfBuilder.php index 4dd02b7e..82ac04f1 100644 --- a/src/Builder/Pdf/FlattenPdfBuilder.php +++ b/src/Builder/Pdf/FlattenPdfBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#flatten-pdfs-route */ -#[SemanticNode('flatten')] +#[SemanticNode('flatten', 'pdf')] final class FlattenPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -56,9 +56,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/HtmlPdfBuilder.php b/src/Builder/Pdf/HtmlPdfBuilder.php index 78853a76..0d03f445 100644 --- a/src/Builder/Pdf/HtmlPdfBuilder.php +++ b/src/Builder/Pdf/HtmlPdfBuilder.php @@ -12,7 +12,7 @@ /** * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route */ -#[SemanticNode('html')] +#[SemanticNode('html', 'pdf')] final class HtmlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait; @@ -30,9 +30,4 @@ protected function validatePayloadBody(): void throw new MissingRequiredFieldException('Content is required'); } } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/LibreOfficePdfBuilder.php b/src/Builder/Pdf/LibreOfficePdfBuilder.php index 975c05bf..fd79131d 100644 --- a/src/Builder/Pdf/LibreOfficePdfBuilder.php +++ b/src/Builder/Pdf/LibreOfficePdfBuilder.php @@ -16,7 +16,7 @@ /** * @see https://gotenberg.dev/docs/routes#convert-with-libreoffice */ -#[SemanticNode('office')] +#[SemanticNode('office', 'pdf')] final class LibreOfficePdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -76,9 +76,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/MarkdownPdfBuilder.php b/src/Builder/Pdf/MarkdownPdfBuilder.php index a8f0c070..7f080bdd 100644 --- a/src/Builder/Pdf/MarkdownPdfBuilder.php +++ b/src/Builder/Pdf/MarkdownPdfBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ -#[SemanticNode('markdown')] +#[SemanticNode('markdown', 'pdf')] final class MarkdownPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait { @@ -79,9 +79,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/MergePdfBuilder.php b/src/Builder/Pdf/MergePdfBuilder.php index 962ddeac..a57e66e1 100644 --- a/src/Builder/Pdf/MergePdfBuilder.php +++ b/src/Builder/Pdf/MergePdfBuilder.php @@ -18,7 +18,7 @@ /** * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ -#[SemanticNode('merge')] +#[SemanticNode('merge', 'pdf')] final class MergePdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -67,9 +67,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/SplitPdfBuilder.php b/src/Builder/Pdf/SplitPdfBuilder.php index c15189d7..29a8f3ba 100644 --- a/src/Builder/Pdf/SplitPdfBuilder.php +++ b/src/Builder/Pdf/SplitPdfBuilder.php @@ -19,7 +19,7 @@ /** * @see https://gotenberg.dev/docs/routes#split-pdfs-route */ -#[SemanticNode('split')] +#[SemanticNode('split', 'pdf')] final class SplitPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; @@ -72,9 +72,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Pdf/UrlPdfBuilder.php b/src/Builder/Pdf/UrlPdfBuilder.php index d1aef4ea..0e642745 100644 --- a/src/Builder/Pdf/UrlPdfBuilder.php +++ b/src/Builder/Pdf/UrlPdfBuilder.php @@ -14,7 +14,7 @@ /** * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ -#[SemanticNode('url')] +#[SemanticNode('url', 'pdf')] final class UrlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait; @@ -25,6 +25,8 @@ final class UrlPdfBuilder extends AbstractBuilder implements BuilderAssetInterfa /** * URL of the page you want to convert into PDF. + * + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function url(string $url): self { @@ -36,6 +38,8 @@ public function url(string $url): self /** * @param string $name #Route * @param array $parameters + * + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function route(string $name, array $parameters = []): self { @@ -75,9 +79,4 @@ private function normalizeRoute(): \Generator { yield 'route' => NormalizerFactory::route($this->requestContext, $this->getUrlGenerator()); } - - public static function type(): string - { - return 'pdf'; - } } diff --git a/src/Builder/Screenshot/HtmlScreenshotBuilder.php b/src/Builder/Screenshot/HtmlScreenshotBuilder.php index 6a0b15ec..f6aad76b 100644 --- a/src/Builder/Screenshot/HtmlScreenshotBuilder.php +++ b/src/Builder/Screenshot/HtmlScreenshotBuilder.php @@ -12,7 +12,7 @@ /** * @see https://gotenberg.dev/docs/routes#screenshots-route */ -#[SemanticNode('html')] +#[SemanticNode('html', 'screenshot')] final class HtmlScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait; @@ -30,9 +30,4 @@ protected function validatePayloadBody(): void throw new MissingRequiredFieldException('Content is required'); } } - - public static function type(): string - { - return 'screenshot'; - } } diff --git a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php index 3f92b660..e9a57ce5 100644 --- a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php +++ b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#screenshots-route */ -#[SemanticNode('markdown')] +#[SemanticNode('markdown', 'screenshot')] final class MarkdownScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait { @@ -79,9 +79,4 @@ private function normalizeFiles(): \Generator { yield 'files' => NormalizerFactory::asset(); } - - public static function type(): string - { - return 'screenshot'; - } } diff --git a/src/Builder/Screenshot/UrlScreenshotBuilder.php b/src/Builder/Screenshot/UrlScreenshotBuilder.php index a4dabba1..b21068d3 100644 --- a/src/Builder/Screenshot/UrlScreenshotBuilder.php +++ b/src/Builder/Screenshot/UrlScreenshotBuilder.php @@ -11,10 +11,7 @@ use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Symfony\Component\Routing\RequestContext; -/** - * @see https://gotenberg.dev/docs/routes#url-into-pdf-route - */ -#[SemanticNode('url')] +#[SemanticNode('url', 'screenshot')] final class UrlScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait; @@ -25,6 +22,8 @@ final class UrlScreenshotBuilder extends AbstractBuilder implements BuilderAsset /** * URL of the page you want to convert into PDF. + * + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function url(string $url): self { @@ -36,6 +35,8 @@ public function url(string $url): self /** * @param string $name #Route * @param array $parameters + * + * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ public function route(string $name, array $parameters = []): self { @@ -72,9 +73,4 @@ private function normalizeRoute(): \Generator { yield 'route' => NormalizerFactory::route($this->requestContext, $this->getUrlGenerator()); } - - public static function type(): string - { - return 'screenshot'; - } } diff --git a/src/DependencyInjection/BuilderStack.php b/src/DependencyInjection/BuilderStack.php index 51207a0f..5586f5fa 100644 --- a/src/DependencyInjection/BuilderStack.php +++ b/src/DependencyInjection/BuilderStack.php @@ -49,16 +49,16 @@ public function push(string $class): void throw new \LogicException("{$class} has already been added."); } - $type = 'custom'; - if (method_exists($class, 'type')) { - $type = $class::type(); - } - - if (!\in_array($type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock - throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); - } - - $this->builders[$class] = $type; +// $type = 'custom'; +// if (method_exists($class, 'type')) { +// $type = $class::type(); +// } +// +// if (!\in_array($type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock +// throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); +// } +// +// $this->builders[$class] = $type; $reflection = new \ReflectionClass($class); $nodeAttributes = $reflection->getAttributes(SemanticNode::class); @@ -70,7 +70,11 @@ public function push(string $class): void /** @var SemanticNode $semanticNode */ $semanticNode = $nodeAttributes[0]->newInstance(); - $this->typeReverseMapping[$type][$semanticNode->name] = $class; + if (!\in_array($semanticNode->type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock + throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); + } + + $this->typeReverseMapping[$semanticNode->type][$semanticNode->name] = $class; foreach (array_reverse($reflection->getMethods(\ReflectionMethod::IS_PUBLIC)) as $method) { $attributes = $method->getAttributes(ExposeSemantic::class); From 09b1b7b4a4962db26e5c9379fc78d6a2c1b15db5 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Fri, 11 Apr 2025 11:42:35 +0200 Subject: [PATCH 09/30] Updates --- src/Builder/Behaviors/Chromium/AssetTrait.php | 4 ++-- src/Builder/Behaviors/SplitTrait.php | 1 + src/Builder/Pdf/FlattenPdfBuilder.php | 4 +++- src/Builder/Pdf/MergePdfBuilder.php | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Builder/Behaviors/Chromium/AssetTrait.php b/src/Builder/Behaviors/Chromium/AssetTrait.php index a7dde088..d31aa47b 100644 --- a/src/Builder/Behaviors/Chromium/AssetTrait.php +++ b/src/Builder/Behaviors/Chromium/AssetTrait.php @@ -19,7 +19,7 @@ abstract protected function getBodyBag(): BodyBag; /** * Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). */ - public function assets(string ...$paths): static + public function assets(string|\Stringable ...$paths): static { $this->getBodyBag()->unset('assets'); @@ -33,7 +33,7 @@ public function assets(string ...$paths): static /** * Adds a file, like an image, font, stylesheet, and so on. */ - public function addAsset(string $path): static + public function addAsset(string|\Stringable $path): static { $assets = $this->getBodyBag()->get('assets', []); diff --git a/src/Builder/Behaviors/SplitTrait.php b/src/Builder/Behaviors/SplitTrait.php index d5deb8bf..5b26c045 100644 --- a/src/Builder/Behaviors/SplitTrait.php +++ b/src/Builder/Behaviors/SplitTrait.php @@ -14,6 +14,7 @@ /** * @see https://gotenberg.dev/docs/routes#split-chromium + * @see https://gotenberg.dev/docs/routes#split-libreoffice */ trait SplitTrait { diff --git a/src/Builder/Pdf/FlattenPdfBuilder.php b/src/Builder/Pdf/FlattenPdfBuilder.php index 61e282c2..be6b2588 100644 --- a/src/Builder/Pdf/FlattenPdfBuilder.php +++ b/src/Builder/Pdf/FlattenPdfBuilder.php @@ -24,9 +24,11 @@ final class FlattenPdfBuilder extends AbstractBuilder public const ENDPOINT = '/forms/pdfengines/flatten'; - public function files(string ...$paths): self + public function files(string|\Stringable ...$paths): self { foreach ($paths as $path) { + $path = (string) $path; + $info = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); ValidatorFactory::filesExtension([$info], ['pdf']); diff --git a/src/Builder/Pdf/MergePdfBuilder.php b/src/Builder/Pdf/MergePdfBuilder.php index 962ddeac..ad8779a9 100644 --- a/src/Builder/Pdf/MergePdfBuilder.php +++ b/src/Builder/Pdf/MergePdfBuilder.php @@ -39,6 +39,7 @@ public function files(string|\Stringable ...$paths): self { foreach ($paths as $path) { $path = (string) $path; + $info = new \SplFileInfo($this->getAssetBaseDirFormatter()->resolve($path)); ValidatorFactory::filesExtension([$info], ['pdf']); From 1293ba8a1df011fa6c08ccfdc2cf626d5c68e64f Mon Sep 17 00:00:00 2001 From: "hubert.lenoir" Date: Fri, 11 Apr 2025 12:33:39 +0200 Subject: [PATCH 10/30] fixes --- config/builder.php | 1 + phpstan.dist.neon | 4 - src/Builder/AbstractBuilder.php | 4 +- ...WebhookConfigurationRegistryAwareTrait.php | 15 +++ src/Builder/Behaviors/WebhookTrait.php | 29 ++++++ src/DependencyInjection/BuilderStack.php | 14 +-- src/Webhook/WebhookConfigurationRegistry.php | 99 +++++++++++++++++++ .../WebhookConfigurationRegistryInterface.php | 33 +++++++ .../Behaviors/Chromium/AssetTestCaseTrait.php | 2 - .../Behaviors/WebhookTestCaseTrait.php | 41 ++++++++ tests/Builder/GotenbergBuilderTestCase.php | 1 - 11 files changed, 222 insertions(+), 21 deletions(-) create mode 100644 src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php create mode 100644 src/Webhook/WebhookConfigurationRegistry.php create mode 100644 src/Webhook/WebhookConfigurationRegistryInterface.php diff --git a/config/builder.php b/config/builder.php index 7c14a660..17d39405 100644 --- a/config/builder.php +++ b/config/builder.php @@ -20,6 +20,7 @@ service('sensiolabs_gotenberg.client'), service_locator([ 'asset_base_dir_formatter' => service('.sensiolabs_gotenberg.asset.base_dir_formatter'), + 'webhook_configuration_registry' => service('.sensiolabs_gotenberg.webhook_configuration_registry'), 'logger' => service('logger')->nullOnInvalid(), 'request_stack' => service('request_stack')->nullOnInvalid(), 'router' => service('router.default')->nullOnInvalid(), diff --git a/phpstan.dist.neon b/phpstan.dist.neon index fca86399..3acdfcf2 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -19,10 +19,6 @@ parameters: message: "#^Method Sensiolabs\\\\GotenbergBundle\\\\Tests\\\\Kernel\\:\\:configureContainer\\(\\) is unused\\.$#" count: 1 path: tests/Kernel.php - - # Fixed when requiring 8.2 - message: "#^Parameter \\#1 \\$iterator of function iterator_to_array expects Traversable, iterable given\\.$#" - count: 1 - path: tests/Builder/GotenbergBuilderTestCase.php - message: "#^ Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\ArrayNodeDefinition|Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\VariableNodeDefinition::append\\(\\)\\.$#" count: 1 diff --git a/src/Builder/AbstractBuilder.php b/src/Builder/AbstractBuilder.php index a6f7a96f..18dadb1e 100644 --- a/src/Builder/AbstractBuilder.php +++ b/src/Builder/AbstractBuilder.php @@ -102,12 +102,12 @@ public function generateAsync(): GotenbergAsyncResult ); } - protected function getBodyBag(): BodyBag + public function getBodyBag(): BodyBag { return $this->bodyBag; } - protected function getHeadersBag(): HeadersBag + public function getHeadersBag(): HeadersBag { return $this->headersBag; } diff --git a/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php b/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php new file mode 100644 index 00000000..fdd530e9 --- /dev/null +++ b/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php @@ -0,0 +1,15 @@ +dependencies->get('webhook_configuration_registry'); + } +} diff --git a/src/Builder/Behaviors/WebhookTrait.php b/src/Builder/Behaviors/WebhookTrait.php index 4c8518a9..6a5d2bb6 100644 --- a/src/Builder/Behaviors/WebhookTrait.php +++ b/src/Builder/Behaviors/WebhookTrait.php @@ -4,6 +4,7 @@ use Sensiolabs\GotenbergBundle\Builder\Attributes\ExposeSemantic; use Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies\UrlGeneratorAwareTrait; +use Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies\WebhookConfigurationRegistryAwareTrait; use Sensiolabs\GotenbergBundle\Builder\HeadersBag; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\NodeBuilder\ArrayNodeBuilder; @@ -34,6 +35,7 @@ trait WebhookTrait { use UrlGeneratorAwareTrait; + use WebhookConfigurationRegistryAwareTrait; abstract protected function getHeadersBag(): HeadersBag; @@ -177,6 +179,33 @@ public function webhookErrorRoute(string $route, array $parameters = [], string| return $this->webhookErrorUrl($this->getUrlGenerator()->generate($route, $parameters, UrlGeneratorInterface::ABSOLUTE_URL), $method); } + /** + * Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. + * + * @see https://gotenberg.dev/docs/webhook + */ + public function webhookConfiguration(string $name): static + { + $webhookConfiguration = $this->getWebhookConfigurationRegistry()->get($name); + + $result = $this + ->webhookUrl( + $webhookConfiguration['success']['url'], + $webhookConfiguration['success']['method'], + ) + ->webhookErrorUrl( + $webhookConfiguration['error']['url'], + $webhookConfiguration['error']['method'], + ) + ; + + if (\array_key_exists('extra_http_headers', $webhookConfiguration)) { + $result = $result->webhookExtraHeaders($webhookConfiguration['extra_http_headers']); + } + + return $result; + } + /** * @param WebhookConfiguration $webhook */ diff --git a/src/DependencyInjection/BuilderStack.php b/src/DependencyInjection/BuilderStack.php index 5586f5fa..eb8d51ed 100644 --- a/src/DependencyInjection/BuilderStack.php +++ b/src/DependencyInjection/BuilderStack.php @@ -49,17 +49,6 @@ public function push(string $class): void throw new \LogicException("{$class} has already been added."); } -// $type = 'custom'; -// if (method_exists($class, 'type')) { -// $type = $class::type(); -// } -// -// if (!\in_array($type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock -// throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); -// } -// -// $this->builders[$class] = $type; - $reflection = new \ReflectionClass($class); $nodeAttributes = $reflection->getAttributes(SemanticNode::class); @@ -74,6 +63,7 @@ public function push(string $class): void throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); } + $this->builders[$class] = $semanticNode->type; $this->typeReverseMapping[$semanticNode->type][$semanticNode->name] = $class; foreach (array_reverse($reflection->getMethods(\ReflectionMethod::IS_PUBLIC)) as $method) { @@ -104,7 +94,7 @@ public function push(string $class): void 'callback' => $callback, ]; - $this->configNode[$type][$semanticNode->name][] = $attribute->node; + $this->configNode[$semanticNode->type][$semanticNode->name][] = $attribute->node; } } diff --git a/src/Webhook/WebhookConfigurationRegistry.php b/src/Webhook/WebhookConfigurationRegistry.php new file mode 100644 index 00000000..e243940b --- /dev/null +++ b/src/Webhook/WebhookConfigurationRegistry.php @@ -0,0 +1,99 @@ + + * }> + */ + private array $configurations = []; + + public function __construct( + private readonly UrlGeneratorInterface $urlGenerator, + private readonly RequestContext|null $requestContext, + ) { + } + + /** + * @param array{success: WebhookDefinition, error?: WebhookDefinition, extra_http_headers?: array} $configuration + */ + public function add(string $name, array $configuration): void + { + $requestContext = $this->urlGenerator->getContext(); + if (null !== $this->requestContext) { + $this->urlGenerator->setContext($this->requestContext); + } + + try { + $success = [ + 'url' => $this->processWebhookConfiguration($configuration['success']), + 'method' => $configuration['success']['method'] ?? null, + ]; + $error = $success; + + if (isset($configuration['error'])) { + $error = [ + 'url' => $this->processWebhookConfiguration($configuration['error']), + 'method' => $configuration['error']['method'] ?? null, + ]; + } + + $namedConfiguration = ['success' => $success, 'error' => $error]; + + if (\array_key_exists('extra_http_headers', $configuration) && [] !== $configuration['extra_http_headers']) { + $namedConfiguration['extra_http_headers'] = $configuration['extra_http_headers']; + } + + $this->configurations[$name] = $namedConfiguration; + } finally { + $this->urlGenerator->setContext($requestContext); + } + } + + public function get(string $name): array + { + if (!\array_key_exists($name, $this->configurations)) { + throw new WebhookConfigurationException("Webhook configuration \"{$name}\" not found."); + } + + return $this->configurations[$name]; + } + + /** + * @param WebhookDefinition $webhookDefinition + * + * @throws WebhookConfigurationException + */ + private function processWebhookConfiguration(array $webhookDefinition): string + { + if (isset($webhookDefinition['url'])) { + return $webhookDefinition['url']; + } + + if (isset($webhookDefinition['route'])) { + return $this->urlGenerator->generate($webhookDefinition['route'][0], $webhookDefinition['route'][1], UrlGeneratorInterface::ABSOLUTE_URL); + } + + throw new WebhookConfigurationException('Invalid webhook configuration'); + } +} diff --git a/src/Webhook/WebhookConfigurationRegistryInterface.php b/src/Webhook/WebhookConfigurationRegistryInterface.php new file mode 100644 index 00000000..48f2dd22 --- /dev/null +++ b/src/Webhook/WebhookConfigurationRegistryInterface.php @@ -0,0 +1,33 @@ +}, method?: 'POST'|'PUT'|'PATCH'|null} + */ +interface WebhookConfigurationRegistryInterface +{ + /** + * @param array{success: WebhookDefinition, error?: WebhookDefinition} $configuration + */ + public function add(string $name, array $configuration): void; + + /** + * @return array{ + * success: array{ + * url: string, + * method: 'POST'|'PUT'|'PATCH'|null, + * }, + * error: array{ + * url: string, + * method: 'POST'|'PUT'|'PATCH'|null, + * }, + * extra_http_headers?: array + * } + * + * @throws WebhookConfigurationException if configuration not found + */ + public function get(string $name): array; +} diff --git a/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php index a0651bab..fd727767 100644 --- a/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php +++ b/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php @@ -26,8 +26,6 @@ public function testToAddAssets(string|\Stringable $asset, string $expectedFilen ->generate() ; - $this->assertGotenbergFormDataFile($expectedFilename, $expectedContentType, $expectedPath); - $this->assertContentFile($expectedFilename, $expectedContentType); } diff --git a/tests/Builder/Behaviors/WebhookTestCaseTrait.php b/tests/Builder/Behaviors/WebhookTestCaseTrait.php index afbd341a..0f71312b 100644 --- a/tests/Builder/Behaviors/WebhookTestCaseTrait.php +++ b/tests/Builder/Behaviors/WebhookTestCaseTrait.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; +use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistryInterface; use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouteCollection; @@ -273,4 +274,44 @@ public function testUnsetWebhook(): void self::assertArrayNotHasKey('Gotenberg-Webhook-Error-Method', $builder->getHeadersBag()->all()); self::assertArrayNotHasKey('Gotenberg-Webhook-Extra-Http-Headers', $builder->getHeadersBag()->all()); } + + public function testWebhookUrlsCanBeSetUsingTheRegistry(): void + { + $registry = new class implements WebhookConfigurationRegistryInterface { + public function add(string $name, array $configuration): void + { + // TODO: Implement add() method. + } + + public function get(string $name): array + { + return [ + 'success' => [ + 'url' => 'https://webhook.local', + 'method' => 'PUT', + ], + 'error' => [ + 'url' => 'https://webhook.local/error', + 'method' => 'PATCH', + ], + 'extra_http_headers' => [ + 'plop' => 'plop', + ], + ]; + } + }; + + $this->dependencies->set('webhook_configuration_registry', $registry); + + $this->getDefaultBuilder() + ->webhookConfiguration('fake') + ->generate() + ; + + $this->assertGotenbergHeader('Gotenberg-Webhook-Url', 'https://webhook.local'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Method', 'PUT'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Url', 'https://webhook.local/error'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Error-Method', 'PATCH'); + $this->assertGotenbergHeader('Gotenberg-Webhook-Extra-Http-Headers', '{"plop":"plop"}'); + } } diff --git a/tests/Builder/GotenbergBuilderTestCase.php b/tests/Builder/GotenbergBuilderTestCase.php index b9467082..c38be58e 100644 --- a/tests/Builder/GotenbergBuilderTestCase.php +++ b/tests/Builder/GotenbergBuilderTestCase.php @@ -92,7 +92,6 @@ protected function assertGotenbergFormData(string $name, string $value): void protected function assertGotenbergFormDataFile(string $name, string $contentType, string $path): void { - dd($this->client->getBody()); foreach ($this->client->getBody() as $part) { if (!$part instanceof DataPart) { continue; From d2153c29658dafec22c92204c76159e411458977 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Fri, 11 Apr 2025 14:28:06 +0200 Subject: [PATCH 11/30] fixup --- config/services.php | 10 ++++++++ docs/pdf/builders_api/ConvertPdfBuilder.md | 11 ++++++++ docs/pdf/builders_api/FlattenPdfBuilder.md | 11 ++++++++ docs/pdf/builders_api/HtmlPdfBuilder.md | 11 ++++++++ .../pdf/builders_api/LibreOfficePdfBuilder.md | 11 ++++++++ docs/pdf/builders_api/MarkdownPdfBuilder.md | 11 ++++++++ docs/pdf/builders_api/MergePdfBuilder.md | 11 ++++++++ docs/pdf/builders_api/SplitPdfBuilder.md | 11 ++++++++ docs/pdf/builders_api/UrlPdfBuilder.md | 11 ++++++++ .../builders_api/HtmlScreenshotBuilder.md | 11 ++++++++ .../builders_api/MarkdownScreenshotBuilder.md | 11 ++++++++ .../builders_api/UrlScreenshotBuilder.md | 7 ++++++ src/Builder/Behaviors/Chromium/AssetTrait.php | 4 +++ .../Behaviors/Chromium/AssetTestCaseTrait.php | 25 ++++++++++++++++--- tests/Builder/GotenbergBuilderTestCase.php | 4 ++- 15 files changed, 156 insertions(+), 4 deletions(-) diff --git a/config/services.php b/config/services.php index 035d0602..7774096f 100644 --- a/config/services.php +++ b/config/services.php @@ -12,6 +12,8 @@ use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface; use Sensiolabs\GotenbergBundle\Twig\GotenbergExtension; use Sensiolabs\GotenbergBundle\Twig\GotenbergRuntime; +use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistry; +use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistryInterface; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg; use function Symfony\Component\DependencyInjection\Loader\Configurator\param; @@ -69,4 +71,12 @@ $services->set('sensiolabs_gotenberg.http_kernel.stream_builder', ProcessBuilderOnControllerResponse::class) ->tag('kernel.event_listener', ['method' => 'streamBuilder', 'event' => 'kernel.view']) ; + + $services->set('.sensiolabs_gotenberg.webhook_configuration_registry', WebhookConfigurationRegistry::class) + ->args([ + service('router'), + service('.sensiolabs_gotenberg.request_context')->nullOnInvalid(), + ]) + ->alias(WebhookConfigurationRegistryInterface::class, '.sensiolabs_gotenberg.webhook_configuration_registry') + ; }; diff --git a/docs/pdf/builders_api/ConvertPdfBuilder.md b/docs/pdf/builders_api/ConvertPdfBuilder.md index b65551bc..ceec906d 100644 --- a/docs/pdf/builders_api/ConvertPdfBuilder.md +++ b/docs/pdf/builders_api/ConvertPdfBuilder.md @@ -11,6 +11,10 @@ Sets download from to download each entry (file) in parallel (URLs MUST return a > See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) ### files(Stringable|string $paths) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) + ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. @@ -27,6 +31,13 @@ Enable PDF for Universal Access for optimal accessibility. > [!TIP] > See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/pdf/builders_api/FlattenPdfBuilder.md b/docs/pdf/builders_api/FlattenPdfBuilder.md index a5999e74..eeaa09ce 100644 --- a/docs/pdf/builders_api/FlattenPdfBuilder.md +++ b/docs/pdf/builders_api/FlattenPdfBuilder.md @@ -11,10 +11,21 @@ Sets download from to download each entry (file) in parallel (URLs MUST return a > See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) ### files(Stringable|string $paths) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) + ### webhook(array $webhook) > [!TIP] > See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index 85b4fbad..06fcf248 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -118,6 +118,10 @@ Define whether the document outline should be embedded into the PDF.
> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) + ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) @@ -307,6 +311,13 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index b24eb3ce..ef85a52b 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -109,6 +109,10 @@ Flattening a PDF combines all its contents into a single layer. (default false). > [!TIP] > See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) + ### landscape(bool $bool) Set the paper orientation to landscape.
@@ -216,6 +220,13 @@ Specify whether to put extracted pages into a single file or as many files as th > [!TIP] > See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 62b19d6b..693e5294 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -124,6 +124,10 @@ Define whether the document outline should be embedded into the PDF.
> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) + ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) @@ -312,6 +316,13 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index 0af100c3..abf83cce 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -28,6 +28,10 @@ Flattening a PDF combines all its contents into a single layer. (default false). > [!TIP] > See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) + ### metadata(array $metadata) Resets the metadata.
@@ -54,6 +58,13 @@ Enable PDF for Universal Access for optimal accessibility. > [!TIP] > See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index dd3c3571..27bda043 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -23,6 +23,10 @@ Flattening a PDF combines all its contents into a single layer. (default false). > [!TIP] > See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) + ### metadata(array $metadata) Resets the metadata.
@@ -68,6 +72,13 @@ Specify whether to put extracted pages into a single file or as many files as th > [!TIP] > See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index 572f0939..f4b099f1 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -118,6 +118,10 @@ Define whether the document outline should be embedded into the PDF.
> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) + ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) @@ -318,6 +322,13 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index c2c1f408..0c88bbcd 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -117,6 +117,10 @@ The image compression format, either "png", "jpeg" or "webp". (default png). > [!TIP] > See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) + ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) @@ -185,6 +189,13 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index bb89c7ef..ccd86ccc 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -123,6 +123,10 @@ The image compression format, either "png", "jpeg" or "webp". (default png). > [!TIP] > See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +### getHeadersBag() +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) + ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) @@ -191,6 +195,13 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
+> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index 84746c9b..5136fef1 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -73,6 +73,7 @@ HTML file containing the footer. The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) +### getHeadersBag() ### header(string $template, array $context) ### headerFile(string $path) HTML file containing the header. @@ -124,6 +125,12 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) diff --git a/src/Builder/Behaviors/Chromium/AssetTrait.php b/src/Builder/Behaviors/Chromium/AssetTrait.php index d31aa47b..4353e619 100644 --- a/src/Builder/Behaviors/Chromium/AssetTrait.php +++ b/src/Builder/Behaviors/Chromium/AssetTrait.php @@ -24,6 +24,8 @@ public function assets(string|\Stringable ...$paths): static $this->getBodyBag()->unset('assets'); foreach ($paths as $path) { + $path = (string) $path; + $this->addAsset($path); } @@ -35,6 +37,8 @@ public function assets(string|\Stringable ...$paths): static */ public function addAsset(string|\Stringable $path): static { + $path = (string) $path; + $assets = $this->getBodyBag()->get('assets', []); if (\array_key_exists($path, $assets)) { diff --git a/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php index f687e68f..a7eab3cb 100644 --- a/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php +++ b/tests/Builder/Behaviors/Chromium/AssetTestCaseTrait.php @@ -15,14 +15,33 @@ trait AssetTestCaseTrait abstract protected function assertContentFile(string $filename, string $contentType = 'text/html', string|null $expectedContent = null): void; - public function testToAddAssets(): void + abstract protected function assertGotenbergFormDataFile(string $name, string $contentType, string $path): void; + + /** + * @dataProvider provideTestToAddAssets + */ + public function testToAddAssets(string|\Stringable $asset, string $expectedFilename, string $expectedContentType, string $expectedPath): void { $this->getDefaultBuilder() - ->assets('assets/logo.png') + ->assets($asset) ->generate() ; - $this->assertContentFile('logo.png', 'image/png'); + $this->assertContentFile($expectedFilename, $expectedContentType); + } + + public static function provideTestToAddAssets(): \Generator + { + yield 'string' => ['assets/logo.png', 'logo.png', 'image/png', self::FIXTURE_DIR.'/assets/logo.png']; + yield 'SplFileInfo' => [new \SplFileInfo('assets/logo.png'), 'logo.png', 'image/png', 'assets/logo.png']; + + $stringable = new class implements \Stringable { + public function __toString(): string + { + return 'assets/logo.png'; + } + }; + yield 'Stringable' => [$stringable, 'logo.png', 'image/png', 'assets/logo.png']; } public function testToAddAssetsToExistingAssets(): void diff --git a/tests/Builder/GotenbergBuilderTestCase.php b/tests/Builder/GotenbergBuilderTestCase.php index 3721e152..c38be58e 100644 --- a/tests/Builder/GotenbergBuilderTestCase.php +++ b/tests/Builder/GotenbergBuilderTestCase.php @@ -137,7 +137,9 @@ protected function assertContentFile(string $filename, string $contentType = 'te self::assertSame($expectedContent, $part->getBody()); } - iterator_to_array($part->bodyToIterable()); + return; } + + $this->fail(\sprintf('No matching content file found with name "%s" and content type "%s".', $filename, $contentType)); } } From bb48f2a72c042b1ee9dab62d7587c8ebabe3dfbd Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Fri, 11 Apr 2025 14:32:28 +0200 Subject: [PATCH 12/30] update --- docs/pdf/builders_api/HtmlPdfBuilder.md | 7 +++---- docs/pdf/builders_api/MarkdownPdfBuilder.md | 7 +++---- docs/pdf/builders_api/UrlPdfBuilder.md | 7 +++---- .../builders_api/HtmlScreenshotBuilder.md | 7 +++---- .../builders_api/MarkdownScreenshotBuilder.md | 7 +++---- .../builders_api/UrlScreenshotBuilder.md | 21 ++++++++----------- src/Builder/Behaviors/Chromium/AssetTrait.php | 2 +- .../Behaviors/Chromium/ContentTrait.php | 4 ++-- .../Behaviors/Chromium/CookieTrait.php | 2 -- .../Chromium/CustomHttpHeadersTrait.php | 9 +++----- .../Chromium/PdfPagePropertiesTrait.php | 3 --- .../Chromium/PerformanceModeTrait.php | 2 +- .../Chromium/WaitBeforeRenderingTrait.php | 3 --- 13 files changed, 31 insertions(+), 50 deletions(-) diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index 06fcf248..a79a1dfe 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -7,20 +7,19 @@ Adds a file, like an image, font, stylesheet, and so on. > [!TIP] +> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium )
> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) ### addMetadata(string $key, string $value) @@ -66,7 +65,6 @@ Forces Chromium to emulate, either "screen" or "print". (default "print"). Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) ### failOnConsoleExceptions(bool $bool) @@ -99,6 +97,7 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) ### footerFile(string $path) @@ -124,6 +123,7 @@ Define whether the document outline should be embedded into the PDF.
### header(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) ### headerFile(string $path) @@ -290,7 +290,6 @@ Specify whether to put extracted pages into a single file or as many files as th Override the default User-Agent HTTP header.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium)
> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) ### waitDelay(string $delay) diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 693e5294..946f3430 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -7,20 +7,19 @@ Adds a file, like an image, font, stylesheet, and so on. > [!TIP] +> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium )
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) ### addMetadata(string $key, string $value) @@ -66,7 +65,6 @@ Forces Chromium to emulate, either "screen" or "print". (default "print"). Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) ### failOnConsoleExceptions(bool $bool) @@ -105,6 +103,7 @@ Add Markdown into a PDF.
### footer(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) ### footerFile(string $path) @@ -130,6 +129,7 @@ Define whether the document outline should be embedded into the PDF.
### header(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) ### headerFile(string $path) @@ -295,7 +295,6 @@ Specify whether to put extracted pages into a single file or as many files as th Override the default User-Agent HTTP header.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) ### waitDelay(string $delay) diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index f4b099f1..be0363dc 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -7,20 +7,19 @@ Adds a file, like an image, font, stylesheet, and so on. > [!TIP] +> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium )
> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### addMetadata(string $key, string $value) @@ -66,7 +65,6 @@ Forces Chromium to emulate, either "screen" or "print". (default "print"). Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### failOnConsoleExceptions(bool $bool) @@ -99,6 +97,7 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### footerFile(string $path) @@ -124,6 +123,7 @@ Define whether the document outline should be embedded into the PDF.
### header(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### headerFile(string $path) @@ -301,7 +301,6 @@ URL of the page you want to convert into PDF.
Override the default User-Agent HTTP header.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium)
> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### waitDelay(string $delay) diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index 0c88bbcd..a9569a5b 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -7,20 +7,19 @@ Adds a file, like an image, font, stylesheet, and so on. > [!TIP] +> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium )
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### assets(Stringable|string $paths) @@ -66,7 +65,6 @@ Forces Chromium to emulate, either "screen" or "print". (default "print"). Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### failOnConsoleExceptions(bool $bool) @@ -99,6 +97,7 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### footerFile(string $path) @@ -123,6 +122,7 @@ The image compression format, either "png", "jpeg" or "webp". (default png). ### header(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### headerFile(string $path) @@ -168,7 +168,6 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
Override the default User-Agent HTTP header.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium)
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### waitDelay(string $delay) diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index ccd86ccc..a27a905a 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -7,20 +7,19 @@ Adds a file, like an image, font, stylesheet, and so on. > [!TIP] +> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium )
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### assets(Stringable|string $paths) @@ -66,7 +65,6 @@ Forces Chromium to emulate, either "screen" or "print". (default "print"). Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium )
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### failOnConsoleExceptions(bool $bool) @@ -105,6 +103,7 @@ Add Markdown into a PDF.
### footer(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### footerFile(string $path) @@ -129,6 +128,7 @@ The image compression format, either "png", "jpeg" or "webp". (default png). ### header(string $template, array $context) > [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### headerFile(string $path) @@ -174,7 +174,6 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
Override the default User-Agent HTTP header.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium)
> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) ### waitDelay(string $delay) diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index 5136fef1..c9636587 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -3,18 +3,15 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.) + ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#cookies-chromium ](https://gotenberg.dev/docs/routes#cookies-chromium ) - ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) - ### assets(Stringable|string $paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). @@ -38,9 +35,6 @@ Forces Chromium to emulate, either "screen" or "print". (default "print"). ### extraHttpHeaders(array $headers) Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium ](https://gotenberg.dev/docs/routes#custom-http-headers-chromium ) - ### failOnConsoleExceptions(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
@@ -66,6 +60,9 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load > See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) ### footer(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.) + ### footerFile(string $path) HTML file containing the footer. @@ -75,6 +72,9 @@ The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) ### getHeadersBag() ### header(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.) + ### headerFile(string $path) HTML file containing the header. @@ -109,9 +109,6 @@ URL of the page you want to convert into PDF.
### userAgent(string $userAgent) Override the default User-Agent HTTP header.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#custom-http-headers-chromium](https://gotenberg.dev/docs/routes#custom-http-headers-chromium) - ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
diff --git a/src/Builder/Behaviors/Chromium/AssetTrait.php b/src/Builder/Behaviors/Chromium/AssetTrait.php index 4353e619..e469119e 100644 --- a/src/Builder/Behaviors/Chromium/AssetTrait.php +++ b/src/Builder/Behaviors/Chromium/AssetTrait.php @@ -8,7 +8,7 @@ use Sensiolabs\GotenbergBundle\Builder\Util\NormalizerFactory; /** - * See https://gotenberg.dev/docs/routes#html-file-into-pdf-route. + * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route. */ trait AssetTrait { diff --git a/src/Builder/Behaviors/Chromium/ContentTrait.php b/src/Builder/Behaviors/Chromium/ContentTrait.php index 4508b450..b27dbd93 100644 --- a/src/Builder/Behaviors/Chromium/ContentTrait.php +++ b/src/Builder/Behaviors/Chromium/ContentTrait.php @@ -47,7 +47,7 @@ public function contentFile(string $path): self * * @throws PdfPartRenderingException if the template could not be rendered * - * See https://gotenberg.dev/docs/routes#header-footer-chromium. + * @see https://gotenberg.dev/docs/routes#header-footer-chromium. */ #[ExposeSemantic(new ArrayNodeBuilder('header', children: [ new ScalarNodeBuilder('template', required: true, restrictTo: 'string'), @@ -64,7 +64,7 @@ public function header(string $template, array $context = []): static * * @throws PdfPartRenderingException if the template could not be rendered * - * See https://gotenberg.dev/docs/routes#header-footer-chromium. + * @see https://gotenberg.dev/docs/routes#header-footer-chromium. */ #[ExposeSemantic(new ArrayNodeBuilder('footer', children: [ new ScalarNodeBuilder('template', required: true, restrictTo: 'string'), diff --git a/src/Builder/Behaviors/Chromium/CookieTrait.php b/src/Builder/Behaviors/Chromium/CookieTrait.php index 487d169d..467f85b0 100644 --- a/src/Builder/Behaviors/Chromium/CookieTrait.php +++ b/src/Builder/Behaviors/Chromium/CookieTrait.php @@ -53,8 +53,6 @@ public function cookies(array $cookies): static /** * Add cookies to store in the Chromium cookie jar. * - * @see https://gotenberg.dev/docs/routes#cookies-chromium - * * @param list $cookies */ public function addCookies(array $cookies): static diff --git a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php index 454a090c..d699d549 100644 --- a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php +++ b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php @@ -10,6 +10,9 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\ArrayNodeBuilder; use Sensiolabs\GotenbergBundle\NodeBuilder\ScalarNodeBuilder; +/** + * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium + */ trait CustomHttpHeadersTrait { abstract protected function getBodyBag(): BodyBag; @@ -18,8 +21,6 @@ abstract protected function getBodyBag(): BodyBag; * Override the default User-Agent HTTP header. * * @param UserAgent::*|string $userAgent - * - * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium */ #[ExposeSemantic(new ScalarNodeBuilder('user_agent', restrictTo: 'string'))] public function userAgent(string $userAgent): static @@ -32,8 +33,6 @@ public function userAgent(string $userAgent): static /** * Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers). * - * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium - * * @param array $headers */ #[ExposeSemantic(new ArrayNodeBuilder('extra_http_headers', normalizeKeys: false, useAttributeAsKey: 'name', prototype: 'variable'))] @@ -53,8 +52,6 @@ public function extraHttpHeaders(array $headers): static /** * Adds extra HTTP headers that Chromium will send when loading the HTML document. * - * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium - * * @param array $headers */ public function addExtraHttpHeaders(array $headers): static diff --git a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php index 18c343fa..442f2ed0 100644 --- a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php @@ -16,9 +16,6 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\ScalarNodeBuilder; use Sensiolabs\GotenbergBundle\NodeBuilder\UnitNodeBuilder; -/** - * @see https://gotenberg.dev/docs/routes#page-properties-chromium. - */ trait PdfPagePropertiesTrait { abstract protected function getBodyBag(): BodyBag; diff --git a/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php b/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php index 741546b7..d55bd895 100644 --- a/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php +++ b/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php @@ -9,7 +9,7 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\BooleanNodeBuilder; /** - * See https://gotenberg.dev/docs/routes#performance-mode-chromium. + * @see https://gotenberg.dev/docs/routes#performance-mode-chromium. */ trait PerformanceModeTrait { diff --git a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php index b51478e2..f72447fb 100644 --- a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php +++ b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php @@ -7,9 +7,6 @@ use Sensiolabs\GotenbergBundle\Builder\Util\ValidatorFactory; use Sensiolabs\GotenbergBundle\NodeBuilder\ScalarNodeBuilder; -/** - * @see https://gotenberg.dev/docs/routes#wait-before-rendering-chromium. - */ trait WaitBeforeRenderingTrait { abstract protected function getBodyBag(): BodyBag; From d39c5106295c58fd2f3eadd70600cecc4baa4aa2 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Sat, 12 Apr 2025 15:23:34 +0200 Subject: [PATCH 13/30] Update --- docs/generate.php | 14 +- docs/pdf/builders_api/ConvertPdfBuilder.md | 35 +--- docs/pdf/builders_api/FlattenPdfBuilder.md | 29 +-- docs/pdf/builders_api/HtmlPdfBuilder.md | 171 +++--------------- .../pdf/builders_api/LibreOfficePdfBuilder.md | 125 ++----------- docs/pdf/builders_api/MarkdownPdfBuilder.md | 170 +++-------------- docs/pdf/builders_api/MergePdfBuilder.md | 41 +---- docs/pdf/builders_api/SplitPdfBuilder.md | 53 +----- docs/pdf/builders_api/UrlPdfBuilder.md | 171 +++--------------- .../builders_api/HtmlScreenshotBuilder.md | 120 ++---------- .../builders_api/MarkdownScreenshotBuilder.md | 122 ++----------- .../builders_api/UrlScreenshotBuilder.md | 9 +- src/Builder/Attributes/SemanticNode.php | 2 +- src/Builder/Behaviors/Chromium/AssetTrait.php | 2 +- .../Behaviors/Chromium/ContentTrait.php | 4 +- .../Behaviors/Chromium/CookieTrait.php | 2 +- .../Chromium/EmulatedMediaTypeTrait.php | 2 +- .../Chromium/PerformanceModeTrait.php | 2 +- src/Builder/Behaviors/WebhookTrait.php | 2 +- src/Builder/Pdf/ConvertPdfBuilder.php | 2 +- src/Builder/Pdf/FlattenPdfBuilder.php | 2 +- src/Builder/Pdf/HtmlPdfBuilder.php | 2 +- src/Builder/Pdf/LibreOfficePdfBuilder.php | 2 +- src/Builder/Pdf/MarkdownPdfBuilder.php | 2 +- src/Builder/Pdf/MergePdfBuilder.php | 2 +- src/Builder/Pdf/SplitPdfBuilder.php | 2 +- src/Builder/Pdf/UrlPdfBuilder.php | 2 +- .../Screenshot/HtmlScreenshotBuilder.php | 2 +- .../Screenshot/MarkdownScreenshotBuilder.php | 2 +- .../Screenshot/UrlScreenshotBuilder.php | 2 +- 30 files changed, 195 insertions(+), 903 deletions(-) diff --git a/docs/generate.php b/docs/generate.php index bfd416c1..639443b2 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -100,7 +100,6 @@ class BuilderParser 'generateAsync', 'fileName', 'processor', - 'type', 'getBodyBag', 'getHeaderBag', ]; @@ -268,7 +267,6 @@ private function prepareBuilderFromClass(ReflectionClass $class): void $classPhpDoc = $this->parsePhpDoc($class->getDocComment() ?: ''); $defaultPackage = $classPhpDoc['package'] ?? null; - $defaultSeeList = $classPhpDoc['tags']['see'] ?? null; foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if (\in_array($method->getName(), self::EXCLUDED_METHODS, true) === true) { @@ -304,12 +302,10 @@ private function prepareBuilderFromClass(ReflectionClass $class): void $this->parts['methods']['@'][$method->getShortName()]['tags']['param'] = $parsedDocBlock['tags']['param'] + $this->parts['methods']['@'][$method->getShortName()]['tags']['param']; } - $tagsSeeList = array_merge($defaultSeeList ?? [], $parsedDocBlock['tags']['see'] ?? []); - - if ([] !== $tagsSeeList) { + if (isset($parsedDocBlock['tags']['see'])) { $this->parts['methods']['@'][$method->getShortName()]['tags']['see'] = array_unique(array_merge( $this->parts['methods']['@'][$method->getShortName()]['tags']['see'] ?? [], - $tagsSeeList, + $parsedDocBlock['tags']['see'], )); } } @@ -393,8 +389,12 @@ public function parseMethodSignature(ReflectionMethod $method): string foreach ($method->getParameters() as $parameter) { $parameterName = $parameter->getName(); $parameterType = $parameter->getType(); + $prefixParameter = ''; + if ($parameter->isVariadic()) { + $prefixParameter = '...'; + } - $parameters[] = "{$parameterType} \${$parameterName}"; + $parameters[] = "{$parameterType} {$prefixParameter}\${$parameterName}"; } return $methodName.'('.implode(', ', $parameters).')'; diff --git a/docs/pdf/builders_api/ConvertPdfBuilder.md b/docs/pdf/builders_api/ConvertPdfBuilder.md index ceec906d..840040c4 100644 --- a/docs/pdf/builders_api/ConvertPdfBuilder.md +++ b/docs/pdf/builders_api/ConvertPdfBuilder.md @@ -7,65 +7,46 @@ Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) -### files(Stringable|string $paths) +### files(Stringable|string ...$paths) ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) - ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) - ### pdfUniversalAccess(bool $bool) Enable PDF for Universal Access for optimal accessibility. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) - ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) diff --git a/docs/pdf/builders_api/FlattenPdfBuilder.md b/docs/pdf/builders_api/FlattenPdfBuilder.md index eeaa09ce..2d6d5ce3 100644 --- a/docs/pdf/builders_api/FlattenPdfBuilder.md +++ b/docs/pdf/builders_api/FlattenPdfBuilder.md @@ -7,53 +7,40 @@ Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) -### files(Stringable|string $paths) +### files(Stringable|string ...$paths) ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) - ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#flatten-pdfs-route](https://gotenberg.dev/docs/routes#flatten-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index a79a1dfe..d4ced62a 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -6,173 +6,116 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### addMetadata(string $key, string $value) The metadata to write. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - -### assets(Stringable|string $paths) +### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### content(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### contentFile(string $path) The HTML file to convert into PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### cookies(array $cookies) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### extraHttpHeaders(array $headers) Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### failOnConsoleExceptions(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) ### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### footerFile(string $path) HTML file containing the footer. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### forwardCookie(string $name) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### generateDocumentOutline(bool $bool) Define whether the document outline should be embedded into the PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### headerFile(string $path) HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### landscape(bool $bool) Set the paper orientation to landscape.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Overrides the default margins (e.g., 0.39), in inches.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### metadata(array $metadata) Resets the metadata.
@@ -182,169 +125,113 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf )
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) Page ranges to print, e.g., '1-5, 8, 11-13'.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### omitBackground(bool $bool) Hide the default white background and allow generating PDFs with transparency.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### paperSize(float $width, float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Overrides the default paper size, in inches.

Examples of paper size (width x height):

Letter - 8.5 x 11 (default)
Legal - 8.5 x 14
Tabloid - 11 x 17
Ledger - 17 x 11
A0 - 33.1 x 46.8
A1 - 23.4 x 33.1
A2 - 16.54 x 23.4
A3 - 11.7 x 16.54
A4 - 8.27 x 11.7
A5 - 5.83 x 8.27
A6 - 4.13 x 5.83 -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### paperStandardSize(Sensiolabs\GotenbergBundle\Enumeration\PaperSizeInterface $paperSize) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### paperWidth(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### pdfUniversalAccess(bool $bool) Enable PDF for Universal Access for optimal accessibility. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### preferCssPageSize(bool $bool) Define whether to prefer page size as defined by CSS.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### printBackground(bool $bool) Prints the background graphics.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### scale(float $scale) The scale of the page rendering (e.g., 1.0).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### skipNetworkIdleEvent(bool $bool) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) Either intervals or pages. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index ef85a52b..628a80b5 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -6,138 +6,76 @@ ### addMetadata(string $key, string $value) The metadata to write. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### addOriginalDocumentAsStream(bool $bool) Specify that a stream is inserted to the PDF file which contains the original document for archiving purposes. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### allowDuplicateFieldNames(bool $bool) Specify whether multiple form fields exported are allowed to have the same field name. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### convertOooTargetToPdfTarget(bool $bool) Specify that the target documents with .od[tpgs] extension, will have that extension changed to .pdf when the link is exported to PDF. The source document remains untouched. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### doNotExportBookmarks(bool $bool) Specify if bookmarks are exported to PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### doNotExportFormFields(bool $bool) Specify whether form fields are exported as widgets or only their fixed print representation is exported. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### doNotUpdateIndexes(bool $bool) Specify whether to update the indexes before conversion, keeping in mind that doing so might result in missing links in the final PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### exportBookmarksToPdfDestination(bool $bool) Specify that the bookmarks contained in the source LibreOffice file should be exported to the PDF file as Named Destination. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### exportHiddenSlides(bool $bool) Export, for LibreOffice Impress, slides that are not included in slide shows. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### exportLinksRelativeFsys(bool $bool) Specify that the file system related hyperlinks (file:// protocol) present in the document will be exported as relative to the source document location. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### exportNotes(bool $bool) Specify if notes are exported to PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### exportNotesInMargin(bool $bool) Specify if notes in margin are exported to PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### exportNotesPages(bool $bool) Specify if notes pages are exported to PDF. Notes pages are available in Impress documents only. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### exportOnlyNotesPages(bool $bool) Specify, if the form field exportNotesPages is set to true, if only notes pages are exported to PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### exportPlaceholders(bool $bool) Export the placeholders fields visual markings only. The exported placeholder is ineffective. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - -### files(Stringable|string $paths) +### files(Stringable|string ...$paths) Adds office files to convert (overrides any previous files). ### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### landscape(bool $bool) Set the paper orientation to landscape.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### losslessImageCompression(bool $bool) Specify if images are exported to PDF using a lossless compression format like PNG or compressed using the JPEG format. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### maxImageResolution(?Sensiolabs\GotenbergBundle\Enumeration\ImageResolutionDPI $resolution) If the form field reduceImageResolution is set to true, tell if all images will be reduced to the given value in DPI. Possible values are: 75, 150, 300, 600 and 1200. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### merge(bool $bool) Merge alphanumerically the resulting PDFs. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### metadata(array $metadata) Resets the metadata.
@@ -146,115 +84,74 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf )
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) Page ranges to print, e.g., '1-4' - empty means all pages.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### password(string $password) Set the password for opening the source file. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### pdfUniversalAccess(bool $bool) Enable PDF for Universal Access for optimal accessibility. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### quality(int $quality) Specify the quality of the JPG export. A higher value produces a higher-quality image and a larger file. Between 1 and 100.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### reduceImageResolution(bool $bool) Specify if the resolution of each image is reduced to the resolution specified by the form field maxImageResolution. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### singlePageSheets(bool $bool) Ignore each sheet’s paper size, print ranges and shown/hidden status and puts every sheet (even hidden sheets) on exactly one page. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### skipEmptyPages(bool $bool) Specify that automatically inserted empty pages are suppressed. This option is active only if storing Writer documents. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) Either intervals or pages. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#convert-with-libreoffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 946f3430..44ea7af5 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -6,96 +6,60 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### addMetadata(string $key, string $value) The metadata to write. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - -### assets(Stringable|string $paths) +### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### content(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### contentFile(string $path) The HTML file to convert into PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### cookies(array $cookies) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### extraHttpHeaders(array $headers) Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### failOnConsoleExceptions(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### files(Stringable|string $paths) +### files(Stringable|string ...$paths) Add Markdown into a PDF.
> [!TIP] @@ -103,82 +67,61 @@ Add Markdown into a PDF.
### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### footerFile(string $path) HTML file containing the footer. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### forwardCookie(string $name) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### generateDocumentOutline(bool $bool) Define whether the document outline should be embedded into the PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### headerFile(string $path) HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### landscape(bool $bool) Set the paper orientation to landscape.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Overrides the default margins (e.g., 0.39), in inches.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### metadata(array $metadata) Resets the metadata.
@@ -194,164 +137,109 @@ Resets the metadata.
Page ranges to print, e.g., '1-5, 8, 11-13'.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### omitBackground(bool $bool) Hide the default white background and allow generating PDFs with transparency.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### paperSize(float $width, float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Overrides the default paper size, in inches.

Examples of paper size (width x height):

Letter - 8.5 x 11 (default)
Legal - 8.5 x 14
Tabloid - 11 x 17
Ledger - 17 x 11
A0 - 33.1 x 46.8
A1 - 23.4 x 33.1
A2 - 16.54 x 23.4
A3 - 11.7 x 16.54
A4 - 8.27 x 11.7
A5 - 5.83 x 8.27
A6 - 4.13 x 5.83 -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### paperStandardSize(Sensiolabs\GotenbergBundle\Enumeration\PaperSizeInterface $paperSize) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### paperWidth(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### pdfUniversalAccess(bool $bool) Enable PDF for Universal Access for optimal accessibility. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### preferCssPageSize(bool $bool) Define whether to prefer page size as defined by CSS.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### printBackground(bool $bool) Prints the background graphics.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### scale(float $scale) The scale of the page rendering (e.g., 1.0).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### skipNetworkIdleEvent(bool $bool) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) Either intervals or pages. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### wrapper(string $template, array $context) ### wrapperFile(string $path) diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index abf83cce..0c989f94 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -6,17 +6,13 @@ ### addMetadata(string $key, string $value) The metadata to write. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) -### files(Stringable|string $paths) +### files(Stringable|string ...$paths) Add PDF files to merge.
> [!TIP] @@ -25,13 +21,7 @@ Add PDF files to merge.
### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### metadata(array $metadata) Resets the metadata.
@@ -45,54 +35,39 @@ Resets the metadata.
### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### pdfUniversalAccess(bool $bool) Enable PDF for Universal Access for optimal accessibility. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index 27bda043..842d2c26 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -6,27 +6,17 @@ ### addMetadata(string $key, string $value) The metadata to write. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) -### files(Stringable|string $paths) +### files(Stringable|string ...$paths) ### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) - ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) - ### metadata(array $metadata) Resets the metadata.
@@ -35,78 +25,53 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf )
-> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) - ### pdfUniversalAccess(bool $bool) Enable PDF for Universal Access for optimal accessibility. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) - ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) Either intervals or pages. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) - ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) - ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) - ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index be0363dc..3fe4c607 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -6,173 +6,116 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### addMetadata(string $key, string $value) The metadata to write. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - -### assets(Stringable|string $paths) +### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### content(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### contentFile(string $path) The HTML file to convert into PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### cookies(array $cookies) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### extraHttpHeaders(array $headers) Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### failOnConsoleExceptions(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) ### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### footerFile(string $path) HTML file containing the footer. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### forwardCookie(string $name) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### generateDocumentOutline(bool $bool) Define whether the document outline should be embedded into the PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### headerFile(string $path) HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### landscape(bool $bool) Set the paper orientation to landscape.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Overrides the default margins (e.g., 0.39), in inches.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### metadata(array $metadata) Resets the metadata.
@@ -182,70 +125,47 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf )
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) ### nativePageRanges(string $ranges) Page ranges to print, e.g., '1-5, 8, 11-13'.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### omitBackground(bool $bool) Hide the default white background and allow generating PDFs with transparency.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### paperSize(float $width, float $height, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Overrides the default paper size, in inches.

Examples of paper size (width x height):

Letter - 8.5 x 11 (default)
Legal - 8.5 x 14
Tabloid - 11 x 17
Ledger - 17 x 11
A0 - 33.1 x 46.8
A1 - 23.4 x 33.1
A2 - 16.54 x 23.4
A3 - 11.7 x 16.54
A4 - 8.27 x 11.7
A5 - 5.83 x 8.27
A6 - 4.13 x 5.83 -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### paperStandardSize(Sensiolabs\GotenbergBundle\Enumeration\PaperSizeInterface $paperSize) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### paperWidth(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### pdfUniversalAccess(bool $bool) Enable PDF for Universal Access for optimal accessibility. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### preferCssPageSize(bool $bool) Define whether to prefer page size as defined by CSS.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### printBackground(bool $bool) Prints the background graphics.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### route(string $name, array $parameters) > [!TIP] @@ -255,42 +175,23 @@ Prints the background graphics.
The scale of the page rendering (e.g., 1.0).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### skipNetworkIdleEvent(bool $bool) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) Either intervals or pages. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### splitSpan(string $splitSpan) Either the intervals or the page ranges to extract, depending on the selected mode. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### splitUnify(bool $bool) Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### url(string $url) URL of the page you want to convert into PDF.
@@ -300,62 +201,48 @@ URL of the page you want to convert into PDF.
### userAgent(string $userAgent) Override the default User-Agent HTTP header.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index a9569a5b..32007bb8 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -6,229 +6,143 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - -### assets(Stringable|string $paths) +### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### clip(bool $bool) Define whether to clip the screenshot according to the device dimensions. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### content(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### contentFile(string $path) The HTML file to convert into PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### cookies(array $cookies) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### extraHttpHeaders(array $headers) Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### failOnConsoleExceptions(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) ### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### footerFile(string $path) HTML file containing the footer. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### forwardCookie(string $name) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### headerFile(string $path) HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### height(int $height) The device screen width in pixels. (Default 600). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### omitBackground(bool $bool) Hides default white background and allows generating screenshot with transparency.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### quality(int $quality) The compression quality from range 0 to 100 (jpeg only). (default 100).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### skipNetworkIdleEvent(bool $bool) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### width(int $width) The device screen width in pixels. (Default 800). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index a27a905a..c0d5bc45 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -6,96 +6,60 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - -### assets(Stringable|string $paths) +### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### clip(bool $bool) Define whether to clip the screenshot according to the device dimensions. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### content(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### contentFile(string $path) The HTML file to convert into PDF. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### cookies(array $cookies) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) Forces Chromium to emulate, either "screen" or "print". (default "print"). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### extraHttpHeaders(array $headers) Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### failOnConsoleExceptions(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium )
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### files(Stringable|string $paths) +### files(Stringable|string ...$paths) Add Markdown into a PDF.
> [!TIP] @@ -103,141 +67,91 @@ Add Markdown into a PDF.
### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### footerFile(string $path) HTML file containing the footer. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### forwardCookie(string $name) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### getHeadersBag() -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### headerFile(string $path) HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### height(int $height) The device screen width in pixels. (Default 600). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### omitBackground(bool $bool) Hides default white background and allows generating screenshot with transparency.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### quality(int $quality) The compression quality from range 0 to 100 (jpeg only). (default 100).
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### skipNetworkIdleEvent(bool $bool) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### waitForExpression(string $expression) Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) ### webhook(array $webhook) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook)
-> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) ### width(int $width) The device screen width in pixels. (Default 800). -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) - ### wrapper(string $template, array $context) ### wrapperFile(string $path) The HTML file to convert into PDF. diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index c9636587..67954ead 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -3,16 +3,13 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route.](https://gotenberg.dev/docs/routes#html-file-into-pdf-route.) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
-### assets(Stringable|string $paths) +### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). ### clip(bool $bool) @@ -61,7 +58,7 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load ### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### footerFile(string $path) HTML file containing the footer. @@ -73,7 +70,7 @@ The image compression format, either "png", "jpeg" or "webp". (default png). ### getHeadersBag() ### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium.](https://gotenberg.dev/docs/routes#header-footer-chromium.) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) ### headerFile(string $path) HTML file containing the header. diff --git a/src/Builder/Attributes/SemanticNode.php b/src/Builder/Attributes/SemanticNode.php index 00732019..a31a8155 100644 --- a/src/Builder/Attributes/SemanticNode.php +++ b/src/Builder/Attributes/SemanticNode.php @@ -6,8 +6,8 @@ final class SemanticNode { public function __construct( - public readonly string $name, public readonly string $type, + public readonly string $name, ) { if (!\in_array($this->type, ['pdf', 'screenshot'], true)) { // TODO : temporary soft lock throw new \LogicException('Invalid builder type. Must be one of "pdf" or "screenshot".'); diff --git a/src/Builder/Behaviors/Chromium/AssetTrait.php b/src/Builder/Behaviors/Chromium/AssetTrait.php index e469119e..ec946bb9 100644 --- a/src/Builder/Behaviors/Chromium/AssetTrait.php +++ b/src/Builder/Behaviors/Chromium/AssetTrait.php @@ -8,7 +8,7 @@ use Sensiolabs\GotenbergBundle\Builder\Util\NormalizerFactory; /** - * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route. + * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route */ trait AssetTrait { diff --git a/src/Builder/Behaviors/Chromium/ContentTrait.php b/src/Builder/Behaviors/Chromium/ContentTrait.php index b27dbd93..846c5418 100644 --- a/src/Builder/Behaviors/Chromium/ContentTrait.php +++ b/src/Builder/Behaviors/Chromium/ContentTrait.php @@ -47,7 +47,7 @@ public function contentFile(string $path): self * * @throws PdfPartRenderingException if the template could not be rendered * - * @see https://gotenberg.dev/docs/routes#header-footer-chromium. + * @see https://gotenberg.dev/docs/routes#header-footer-chromium */ #[ExposeSemantic(new ArrayNodeBuilder('header', children: [ new ScalarNodeBuilder('template', required: true, restrictTo: 'string'), @@ -64,7 +64,7 @@ public function header(string $template, array $context = []): static * * @throws PdfPartRenderingException if the template could not be rendered * - * @see https://gotenberg.dev/docs/routes#header-footer-chromium. + * @see https://gotenberg.dev/docs/routes#header-footer-chromium */ #[ExposeSemantic(new ArrayNodeBuilder('footer', children: [ new ScalarNodeBuilder('template', required: true, restrictTo: 'string'), diff --git a/src/Builder/Behaviors/Chromium/CookieTrait.php b/src/Builder/Behaviors/Chromium/CookieTrait.php index 467f85b0..54a0e481 100644 --- a/src/Builder/Behaviors/Chromium/CookieTrait.php +++ b/src/Builder/Behaviors/Chromium/CookieTrait.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\Cookie; /** - * @see https://gotenberg.dev/docs/routes#cookies-chromium. + * @see https://gotenberg.dev/docs/routes#cookies-chromium */ trait CookieTrait { diff --git a/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php b/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php index 382e9fcf..94b7e76f 100644 --- a/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php +++ b/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php @@ -10,7 +10,7 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\NativeEnumNodeBuilder; /** - * @see https://gotenberg.dev/docs/routes#emulated-media-type-chromium. + * @see https://gotenberg.dev/docs/routes#emulated-media-type-chromium */ trait EmulatedMediaTypeTrait { diff --git a/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php b/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php index d55bd895..1520de34 100644 --- a/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php +++ b/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php @@ -9,7 +9,7 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\BooleanNodeBuilder; /** - * @see https://gotenberg.dev/docs/routes#performance-mode-chromium. + * @see https://gotenberg.dev/docs/routes#performance-mode-chromium */ trait PerformanceModeTrait { diff --git a/src/Builder/Behaviors/WebhookTrait.php b/src/Builder/Behaviors/WebhookTrait.php index 6a5d2bb6..cfaef853 100644 --- a/src/Builder/Behaviors/WebhookTrait.php +++ b/src/Builder/Behaviors/WebhookTrait.php @@ -15,7 +15,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** - * @see https://gotenberg.dev/docs/webhook. + * @see https://gotenberg.dev/docs/webhook * * @phpstan-type WebhookConfiguration array{ * config_name?: string, diff --git a/src/Builder/Pdf/ConvertPdfBuilder.php b/src/Builder/Pdf/ConvertPdfBuilder.php index eb284750..734a0620 100644 --- a/src/Builder/Pdf/ConvertPdfBuilder.php +++ b/src/Builder/Pdf/ConvertPdfBuilder.php @@ -16,7 +16,7 @@ /** * @see https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route */ -#[SemanticNode('convert', 'pdf')] +#[SemanticNode(type: 'pdf', name: 'convert')] final class ConvertPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; diff --git a/src/Builder/Pdf/FlattenPdfBuilder.php b/src/Builder/Pdf/FlattenPdfBuilder.php index dfe23e28..f8fb362d 100644 --- a/src/Builder/Pdf/FlattenPdfBuilder.php +++ b/src/Builder/Pdf/FlattenPdfBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#flatten-pdfs-route */ -#[SemanticNode('flatten', 'pdf')] +#[SemanticNode(type: 'pdf', name: 'flatten')] final class FlattenPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; diff --git a/src/Builder/Pdf/HtmlPdfBuilder.php b/src/Builder/Pdf/HtmlPdfBuilder.php index 0d03f445..502e0f9c 100644 --- a/src/Builder/Pdf/HtmlPdfBuilder.php +++ b/src/Builder/Pdf/HtmlPdfBuilder.php @@ -12,7 +12,7 @@ /** * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route */ -#[SemanticNode('html', 'pdf')] +#[SemanticNode(type: 'pdf', name: 'html')] final class HtmlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait; diff --git a/src/Builder/Pdf/LibreOfficePdfBuilder.php b/src/Builder/Pdf/LibreOfficePdfBuilder.php index fd79131d..9dc4591d 100644 --- a/src/Builder/Pdf/LibreOfficePdfBuilder.php +++ b/src/Builder/Pdf/LibreOfficePdfBuilder.php @@ -16,7 +16,7 @@ /** * @see https://gotenberg.dev/docs/routes#convert-with-libreoffice */ -#[SemanticNode('office', 'pdf')] +#[SemanticNode(type: 'pdf', name: 'office')] final class LibreOfficePdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; diff --git a/src/Builder/Pdf/MarkdownPdfBuilder.php b/src/Builder/Pdf/MarkdownPdfBuilder.php index 7f080bdd..2ca8ab69 100644 --- a/src/Builder/Pdf/MarkdownPdfBuilder.php +++ b/src/Builder/Pdf/MarkdownPdfBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ -#[SemanticNode('markdown', 'pdf')] +#[SemanticNode(type: 'pdf', name: 'markdown')] final class MarkdownPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait { diff --git a/src/Builder/Pdf/MergePdfBuilder.php b/src/Builder/Pdf/MergePdfBuilder.php index 2f67f097..8759570d 100644 --- a/src/Builder/Pdf/MergePdfBuilder.php +++ b/src/Builder/Pdf/MergePdfBuilder.php @@ -18,7 +18,7 @@ /** * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ -#[SemanticNode('merge', 'pdf')] +#[SemanticNode(type: 'pdf', name: 'merge')] final class MergePdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; diff --git a/src/Builder/Pdf/SplitPdfBuilder.php b/src/Builder/Pdf/SplitPdfBuilder.php index 29a8f3ba..d302fb9e 100644 --- a/src/Builder/Pdf/SplitPdfBuilder.php +++ b/src/Builder/Pdf/SplitPdfBuilder.php @@ -19,7 +19,7 @@ /** * @see https://gotenberg.dev/docs/routes#split-pdfs-route */ -#[SemanticNode('split', 'pdf')] +#[SemanticNode(type: 'pdf', name: 'split')] final class SplitPdfBuilder extends AbstractBuilder { use AssetBaseDirFormatterAwareTrait; diff --git a/src/Builder/Pdf/UrlPdfBuilder.php b/src/Builder/Pdf/UrlPdfBuilder.php index 0e642745..28371d15 100644 --- a/src/Builder/Pdf/UrlPdfBuilder.php +++ b/src/Builder/Pdf/UrlPdfBuilder.php @@ -14,7 +14,7 @@ /** * @see https://gotenberg.dev/docs/routes#url-into-pdf-route */ -#[SemanticNode('url', 'pdf')] +#[SemanticNode(type: 'pdf', name: 'url')] final class UrlPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait; diff --git a/src/Builder/Screenshot/HtmlScreenshotBuilder.php b/src/Builder/Screenshot/HtmlScreenshotBuilder.php index f6aad76b..eaa527ec 100644 --- a/src/Builder/Screenshot/HtmlScreenshotBuilder.php +++ b/src/Builder/Screenshot/HtmlScreenshotBuilder.php @@ -12,7 +12,7 @@ /** * @see https://gotenberg.dev/docs/routes#screenshots-route */ -#[SemanticNode('html', 'screenshot')] +#[SemanticNode(type: 'screenshot', name: 'html')] final class HtmlScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait; diff --git a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php index e9a57ce5..bf9c8e60 100644 --- a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php +++ b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php @@ -15,7 +15,7 @@ /** * @see https://gotenberg.dev/docs/routes#screenshots-route */ -#[SemanticNode('markdown', 'screenshot')] +#[SemanticNode(type: 'screenshot', name: 'markdown')] final class MarkdownScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait { diff --git a/src/Builder/Screenshot/UrlScreenshotBuilder.php b/src/Builder/Screenshot/UrlScreenshotBuilder.php index b21068d3..ebcaee5f 100644 --- a/src/Builder/Screenshot/UrlScreenshotBuilder.php +++ b/src/Builder/Screenshot/UrlScreenshotBuilder.php @@ -11,7 +11,7 @@ use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Symfony\Component\Routing\RequestContext; -#[SemanticNode('url', 'screenshot')] +#[SemanticNode(type: 'screenshot', name: 'url')] final class UrlScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait; From ae24f6c06760413f7a123311e331d406a058474c Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Sat, 12 Apr 2025 15:24:56 +0200 Subject: [PATCH 14/30] Update --- docs/generate.php | 2 +- docs/pdf/builders_api/ConvertPdfBuilder.md | 1 - docs/pdf/builders_api/FlattenPdfBuilder.md | 1 - docs/pdf/builders_api/HtmlPdfBuilder.md | 1 - docs/pdf/builders_api/LibreOfficePdfBuilder.md | 1 - docs/pdf/builders_api/MarkdownPdfBuilder.md | 1 - docs/pdf/builders_api/MergePdfBuilder.md | 1 - docs/pdf/builders_api/SplitPdfBuilder.md | 1 - docs/pdf/builders_api/UrlPdfBuilder.md | 1 - docs/screenshot/builders_api/HtmlScreenshotBuilder.md | 1 - docs/screenshot/builders_api/MarkdownScreenshotBuilder.md | 1 - docs/screenshot/builders_api/UrlScreenshotBuilder.md | 1 - 12 files changed, 1 insertion(+), 12 deletions(-) diff --git a/docs/generate.php b/docs/generate.php index 639443b2..29c53cf8 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -101,7 +101,7 @@ class BuilderParser 'fileName', 'processor', 'getBodyBag', - 'getHeaderBag', + 'getHeadersBag', ]; private string $name; diff --git a/docs/pdf/builders_api/ConvertPdfBuilder.md b/docs/pdf/builders_api/ConvertPdfBuilder.md index 840040c4..d78fd5fd 100644 --- a/docs/pdf/builders_api/ConvertPdfBuilder.md +++ b/docs/pdf/builders_api/ConvertPdfBuilder.md @@ -10,7 +10,6 @@ Sets download from to download each entry (file) in parallel (URLs MUST return a > See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### files(Stringable|string ...$paths) -### getHeadersBag() ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. diff --git a/docs/pdf/builders_api/FlattenPdfBuilder.md b/docs/pdf/builders_api/FlattenPdfBuilder.md index 2d6d5ce3..c866e00c 100644 --- a/docs/pdf/builders_api/FlattenPdfBuilder.md +++ b/docs/pdf/builders_api/FlattenPdfBuilder.md @@ -10,7 +10,6 @@ Sets download from to download each entry (file) in parallel (URLs MUST return a > See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) ### files(Stringable|string ...$paths) -### getHeadersBag() ### webhook(array $webhook) ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index d4ced62a..54a2e46b 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -73,7 +73,6 @@ Define whether the document outline should be embedded into the PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### getHeadersBag() ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index 628a80b5..7bbc429c 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -60,7 +60,6 @@ Adds office files to convert (overrides any previous files). ### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -### getHeadersBag() ### landscape(bool $bool) Set the paper orientation to landscape.
diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 44ea7af5..f5bff6e3 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -79,7 +79,6 @@ Define whether the document outline should be embedded into the PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### getHeadersBag() ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index 0c989f94..85ae9e8c 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -21,7 +21,6 @@ Add PDF files to merge.
### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -### getHeadersBag() ### metadata(array $metadata) Resets the metadata.
diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index 842d2c26..c5efc1ed 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -16,7 +16,6 @@ Sets download from to download each entry (file) in parallel (URLs MUST return a ### flatten(bool $bool) Flattening a PDF combines all its contents into a single layer. (default false). -### getHeadersBag() ### metadata(array $metadata) Resets the metadata.
diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index 3fe4c607..15bc754d 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -73,7 +73,6 @@ Define whether the document outline should be embedded into the PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### getHeadersBag() ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index 32007bb8..38c60a93 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -70,7 +70,6 @@ HTML file containing the footer. The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) -### getHeadersBag() ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index c0d5bc45..60835ee9 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -76,7 +76,6 @@ HTML file containing the footer. The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) -### getHeadersBag() ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index 67954ead..abc5e050 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -67,7 +67,6 @@ HTML file containing the footer. The image compression format, either "png", "jpeg" or "webp". (default png). ### forwardCookie(string $name) -### getHeadersBag() ### header(string $template, array $context) > [!TIP] > See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) From 34c67454d639286d23edcba65627f4e64cb01c86 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Sat, 12 Apr 2025 15:39:45 +0200 Subject: [PATCH 15/30] Update --- docs/pdf/builders_api/HtmlPdfBuilder.md | 48 ++++++++-------- docs/pdf/builders_api/MarkdownPdfBuilder.md | 52 ++++++++--------- docs/pdf/builders_api/UrlPdfBuilder.md | 48 ++++++++-------- .../builders_api/HtmlScreenshotBuilder.md | 52 ++++++++--------- .../builders_api/MarkdownScreenshotBuilder.md | 56 +++++++++---------- .../builders_api/UrlScreenshotBuilder.md | 52 ++++++++--------- .../Behaviors/Chromium/ContentTrait.php | 3 + .../Behaviors/Chromium/CookieTrait.php | 2 + src/Builder/Behaviors/WebhookTrait.php | 2 + 9 files changed, 161 insertions(+), 154 deletions(-) diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index 54a2e46b..17bce525 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -6,9 +6,6 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
- ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
@@ -18,11 +15,6 @@ The metadata to write. ### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. - -### cookies(array $cookies) ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
@@ -59,27 +51,12 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load > [!TIP] > See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### footer(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### footerFile(string $path) -HTML file containing the footer. - -### forwardCookie(string $name) ### generateDocumentOutline(bool $bool) Define whether the document outline should be embedded into the PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### header(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### headerFile(string $path) -HTML file containing the header. - ### landscape(bool $bool) Set the paper orientation to landscape.
@@ -172,7 +149,6 @@ The scale of the page rendering (e.g., 1.0).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. @@ -234,3 +210,27 @@ Sets the webhook for cases of success.
Optionally sets a custom HTTP method > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
+ +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. + +### footer(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### footerFile(string $path) +HTML file containing the footer. + +### header(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### headerFile(string $path) +HTML file containing the header. + diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index f5bff6e3..c7db2924 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -6,9 +6,6 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
- ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
@@ -18,11 +15,6 @@ The metadata to write. ### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. - -### cookies(array $cookies) ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
@@ -65,27 +57,12 @@ Add Markdown into a PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) -### footer(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### footerFile(string $path) -HTML file containing the footer. - -### forwardCookie(string $name) ### generateDocumentOutline(bool $bool) Define whether the document outline should be embedded into the PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### header(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### headerFile(string $path) -HTML file containing the header. - ### landscape(bool $bool) Set the paper orientation to landscape.
@@ -178,7 +155,6 @@ The scale of the page rendering (e.g., 1.0).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. @@ -207,6 +183,10 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) +### wrapper(string $template, array $context) +### wrapperFile(string $path) +The HTML file to convert into PDF. + ### webhook(array $webhook) ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
@@ -240,7 +220,27 @@ Sets the webhook for cases of success.
Optionally sets a custom HTTP method > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### wrapper(string $template, array $context) -### wrapperFile(string $path) +### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
+ +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### content(string $template, array $context) +### contentFile(string $path) The HTML file to convert into PDF. +### footer(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### footerFile(string $path) +HTML file containing the footer. + +### header(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### headerFile(string $path) +HTML file containing the header. + diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index 15bc754d..64d7634d 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -6,9 +6,6 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
- ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
@@ -18,11 +15,6 @@ The metadata to write. ### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. - -### cookies(array $cookies) ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
@@ -59,27 +51,12 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load > [!TIP] > See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### footer(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### footerFile(string $path) -HTML file containing the footer. - -### forwardCookie(string $name) ### generateDocumentOutline(bool $bool) Define whether the document outline should be embedded into the PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### header(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### headerFile(string $path) -HTML file containing the header. - ### landscape(bool $bool) Set the paper orientation to landscape.
@@ -176,7 +153,6 @@ The scale of the page rendering (e.g., 1.0).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. @@ -245,3 +221,27 @@ Sets the webhook for cases of success.
Optionally sets a custom HTTP method > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
+ +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. + +### footer(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### footerFile(string $path) +HTML file containing the footer. + +### header(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### headerFile(string $path) +HTML file containing the header. + diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index 38c60a93..c9e00386 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -6,9 +6,6 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
- ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
@@ -18,11 +15,6 @@ Adds additional files, like images, fonts, stylesheets, and so on (overrides any ### clip(bool $bool) Define whether to clip the screenshot according to the device dimensions. (Default false). -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. - -### cookies(array $cookies) ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
@@ -59,24 +51,9 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load > [!TIP] > See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### footer(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### footerFile(string $path) -HTML file containing the footer. - ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). -### forwardCookie(string $name) -### header(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### headerFile(string $path) -HTML file containing the header. - ### height(int $height) The device screen width in pixels. (Default 600). @@ -92,7 +69,6 @@ Define whether to optimize image encoding for speed, not for resulting size. (De ### quality(int $quality) The compression quality from range 0 to 100 (jpeg only). (default 100).
-### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### skipNetworkIdleEvent(bool $bool) ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
@@ -109,6 +85,9 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) +### width(int $width) +The device screen width in pixels. (Default 800). + ### webhook(array $webhook) ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
@@ -142,6 +121,27 @@ Sets the webhook for cases of success.
Optionally sets a custom HTTP method > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### width(int $width) -The device screen width in pixels. (Default 800). +### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
+ +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. + +### footer(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### footerFile(string $path) +HTML file containing the footer. + +### header(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### headerFile(string $path) +HTML file containing the header. diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index 60835ee9..987e647e 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -6,9 +6,6 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
- ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
@@ -18,11 +15,6 @@ Adds additional files, like images, fonts, stylesheets, and so on (overrides any ### clip(bool $bool) Define whether to clip the screenshot according to the device dimensions. (Default false). -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. - -### cookies(array $cookies) ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
@@ -65,24 +57,9 @@ Add Markdown into a PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) -### footer(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### footerFile(string $path) -HTML file containing the footer. - ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). -### forwardCookie(string $name) -### header(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### headerFile(string $path) -HTML file containing the header. - ### height(int $height) The device screen width in pixels. (Default 600). @@ -98,7 +75,6 @@ Define whether to optimize image encoding for speed, not for resulting size. (De ### quality(int $quality) The compression quality from range 0 to 100 (jpeg only). (default 100).
-### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### skipNetworkIdleEvent(bool $bool) ### userAgent(string $userAgent) Override the default User-Agent HTTP header.
@@ -115,6 +91,13 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) +### width(int $width) +The device screen width in pixels. (Default 800). + +### wrapper(string $template, array $context) +### wrapperFile(string $path) +The HTML file to convert into PDF. + ### webhook(array $webhook) ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
@@ -148,10 +131,27 @@ Sets the webhook for cases of success.
Optionally sets a custom HTTP method > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### width(int $width) -The device screen width in pixels. (Default 800). +### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
-### wrapper(string $template, array $context) -### wrapperFile(string $path) +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### content(string $template, array $context) +### contentFile(string $path) The HTML file to convert into PDF. +### footer(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### footerFile(string $path) +HTML file containing the footer. + +### header(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### headerFile(string $path) +HTML file containing the header. + diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index abc5e050..df40e0df 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -3,9 +3,6 @@ ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
- ### addExtraHttpHeaders(array $headers) Adds extra HTTP headers that Chromium will send when loading the HTML document.
@@ -15,11 +12,6 @@ Adds additional files, like images, fonts, stylesheets, and so on (overrides any ### clip(bool $bool) Define whether to clip the screenshot according to the device dimensions. (Default false). -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. - -### cookies(array $cookies) ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
@@ -56,24 +48,9 @@ Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load > [!TIP] > See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### footer(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### footerFile(string $path) -HTML file containing the footer. - ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). -### forwardCookie(string $name) -### header(string $template, array $context) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) - -### headerFile(string $path) -HTML file containing the header. - ### height(int $height) The device screen width in pixels. (Default 600). @@ -93,7 +70,6 @@ The compression quality from range 0 to 100 (jpeg only). (default 100).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) -### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) ### skipNetworkIdleEvent(bool $bool) ### url(string $url) @@ -117,6 +93,9 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) +### width(int $width) +The device screen width in pixels. (Default 800). + ### webhook(array $webhook) ### webhookConfiguration(string $name) Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
@@ -150,6 +129,27 @@ Sets the webhook for cases of success.
Optionally sets a custom HTTP method > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### width(int $width) -The device screen width in pixels. (Default 800). +### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
+ +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. + +### footer(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### footerFile(string $path) +HTML file containing the footer. + +### header(string $template, array $context) +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) + +### headerFile(string $path) +HTML file containing the header. diff --git a/src/Builder/Behaviors/Chromium/ContentTrait.php b/src/Builder/Behaviors/Chromium/ContentTrait.php index 846c5418..7dbb73db 100644 --- a/src/Builder/Behaviors/Chromium/ContentTrait.php +++ b/src/Builder/Behaviors/Chromium/ContentTrait.php @@ -15,6 +15,9 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\ScalarNodeBuilder; use Sensiolabs\GotenbergBundle\Twig\GotenbergRuntime; +/** + * @package Behavior\\Content + */ trait ContentTrait { use AssetBaseDirFormatterAwareTrait; diff --git a/src/Builder/Behaviors/Chromium/CookieTrait.php b/src/Builder/Behaviors/Chromium/CookieTrait.php index 54a0e481..1d16a21e 100644 --- a/src/Builder/Behaviors/Chromium/CookieTrait.php +++ b/src/Builder/Behaviors/Chromium/CookieTrait.php @@ -17,6 +17,8 @@ /** * @see https://gotenberg.dev/docs/routes#cookies-chromium + * + * @package Behavior\\Chromium\\Cookie */ trait CookieTrait { diff --git a/src/Builder/Behaviors/WebhookTrait.php b/src/Builder/Behaviors/WebhookTrait.php index cfaef853..b937fc50 100644 --- a/src/Builder/Behaviors/WebhookTrait.php +++ b/src/Builder/Behaviors/WebhookTrait.php @@ -31,6 +31,8 @@ * }, * extra_http_headers?: array * } + * + * @package Behavior\\Async */ trait WebhookTrait { From 13c303ef2fda4fb62b426fbb740674e3fb07c99c Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Sat, 12 Apr 2025 16:08:35 +0200 Subject: [PATCH 16/30] Update --- docs/pdf/builders_api/HtmlPdfBuilder.md | 182 ++++++++-------- docs/pdf/builders_api/MarkdownPdfBuilder.md | 194 ++++++++--------- docs/pdf/builders_api/UrlPdfBuilder.md | 204 +++++++++--------- .../builders_api/HtmlScreenshotBuilder.md | 138 ++++++------ .../builders_api/MarkdownScreenshotBuilder.md | 154 ++++++------- .../builders_api/UrlScreenshotBuilder.md | 154 ++++++------- src/Builder/Behaviors/Chromium/AssetTrait.php | 2 + .../Chromium/CustomHttpHeadersTrait.php | 2 + .../Chromium/EmulatedMediaTypeTrait.php | 2 + .../Behaviors/Chromium/FailOnTrait.php | 3 + .../Chromium/PdfPagePropertiesTrait.php | 3 + .../Chromium/PerformanceModeTrait.php | 2 + .../ScreenshotPagePropertiesTrait.php | 2 + .../Chromium/WaitBeforeRenderingTrait.php | 3 + 14 files changed, 532 insertions(+), 513 deletions(-) diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index 17bce525..a1b1a2d1 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -3,54 +3,85 @@ > [!TIP] > See: [https://gotenberg.dev/docs/routes#html-file-into-pdf-route](https://gotenberg.dev/docs/routes#html-file-into-pdf-route) -### addAsset(Stringable|string $path) -Adds a file, like an image, font, stylesheet, and so on. - -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML document.
- ### addMetadata(string $key, string $value) The metadata to write. -### assets(Stringable|string ...$paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print"). +### metadata(array $metadata) +Resets the metadata.
-### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+> [!TIP] +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
+> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
+> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
+> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) -### failOnConsoleExceptions(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
+### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +Convert the resulting PDF into the given PDF/A format. + +### pdfUniversalAccess(bool $bool) +Enable PDF for Universal Access for optimal accessibility. + +### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) +Either intervals or pages. + +### splitSpan(string $splitSpan) +Either the intervals or the page ranges to extract, depending on the selected mode. + +### splitUnify(bool $bool) +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). + +### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. + +### assets(Stringable|string ...$paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). + +### webhook(array $webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
+### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
+### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
+### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
+ +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### generateDocumentOutline(bool $bool) Define whether the document outline should be embedded into the PDF.
@@ -93,16 +124,6 @@ Overrides the default margins (e.g., 0.39), in inches.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### metadata(array $metadata) -Resets the metadata.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
-> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
-> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) - ### nativePageRanges(string $ranges) Page ranges to print, e.g., '1-5, 8, 11-13'.
@@ -125,12 +146,6 @@ Overrides the default paper size, in inches.

Examples of paper size ( ### paperWidth(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) -Convert the resulting PDF into the given PDF/A format. - -### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. - ### preferCssPageSize(bool $bool) Define whether to prefer page size as defined by CSS.
@@ -152,19 +167,6 @@ The scale of the page rendering (e.g., 1.0).
### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. -### skipNetworkIdleEvent(bool $bool) -### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. - -### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. - -### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). - -### userAgent(string $userAgent) -Override the default User-Agent HTTP header.
- ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
@@ -177,60 +179,58 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. -### webhookErrorRoute(string $route, array $parameters, ?string $method) +### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookErrorUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### footerFile(string $path) +HTML file containing the footer. +### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookExtraHeaders(array $extraHttpHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+### headerFile(string $path) +HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
-### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### cookies(array $cookies) -### forwardCookie(string $name) -### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. +### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
-### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### footerFile(string $path) -HTML file containing the footer. +### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
-### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### headerFile(string $path) -HTML file containing the header. +### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML document.
+ +### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+### userAgent(string $userAgent) +Override the default User-Agent HTTP header.
+ +### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). + +### skipNetworkIdleEvent(bool $bool) diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index c7db2924..05397f8c 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -3,60 +3,95 @@ > [!TIP] > See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) -### addAsset(Stringable|string $path) -Adds a file, like an image, font, stylesheet, and so on. - -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML document.
- ### addMetadata(string $key, string $value) The metadata to write. -### assets(Stringable|string ...$paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print"). +### files(Stringable|string ...$paths) +Add Markdown into a PDF.
-### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+> [!TIP] +> See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) -### failOnConsoleExceptions(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
+### metadata(array $metadata) +Resets the metadata.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
+> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
+> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
+> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
+### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +Convert the resulting PDF into the given PDF/A format. + +### pdfUniversalAccess(bool $bool) +Enable PDF for Universal Access for optimal accessibility. + +### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) +Either intervals or pages. + +### splitSpan(string $splitSpan) +Either the intervals or the page ranges to extract, depending on the selected mode. + +### splitUnify(bool $bool) +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). + +### wrapper(string $template, array $context) +### wrapperFile(string $path) +The HTML file to convert into PDF. + +### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. + +### assets(Stringable|string ...$paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). + +### webhook(array $webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
+### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
+### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### files(Stringable|string ...$paths) -Add Markdown into a PDF.
+### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
+ +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### generateDocumentOutline(bool $bool) Define whether the document outline should be embedded into the PDF.
@@ -99,16 +134,6 @@ Overrides the default margins (e.g., 0.39), in inches.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### metadata(array $metadata) -Resets the metadata.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
-> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
-> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) - ### nativePageRanges(string $ranges) Page ranges to print, e.g., '1-5, 8, 11-13'.
@@ -131,12 +156,6 @@ Overrides the default paper size, in inches.

Examples of paper size ( ### paperWidth(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) -Convert the resulting PDF into the given PDF/A format. - -### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. - ### preferCssPageSize(bool $bool) Define whether to prefer page size as defined by CSS.
@@ -158,19 +177,6 @@ The scale of the page rendering (e.g., 1.0).
### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. -### skipNetworkIdleEvent(bool $bool) -### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. - -### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. - -### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). - -### userAgent(string $userAgent) -Override the default User-Agent HTTP header.
- ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
@@ -183,64 +189,58 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### wrapper(string $template, array $context) -### wrapperFile(string $path) +### content(string $template, array $context) +### contentFile(string $path) The HTML file to convert into PDF. -### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### webhookErrorRoute(string $route, array $parameters, ?string $method) +### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookErrorUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### footerFile(string $path) +HTML file containing the footer. +### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookExtraHeaders(array $extraHttpHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+### headerFile(string $path) +HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
-### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### cookies(array $cookies) -### forwardCookie(string $name) -### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. +### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
-### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### footerFile(string $path) -HTML file containing the footer. +### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
-### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### headerFile(string $path) -HTML file containing the header. +### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML document.
+ +### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+ +### userAgent(string $userAgent) +Override the default User-Agent HTTP header.
+ +### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). +### skipNetworkIdleEvent(bool $bool) diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index 64d7634d..b72eccbc 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -3,54 +3,96 @@ > [!TIP] > See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) -### addAsset(Stringable|string $path) -Adds a file, like an image, font, stylesheet, and so on. - -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML document.
- ### addMetadata(string $key, string $value) The metadata to write. -### assets(Stringable|string ...$paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print"). +### metadata(array $metadata) +Resets the metadata.
-### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+> [!TIP] +> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
+> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
+> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
+> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
+> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) -### failOnConsoleExceptions(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
+### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) +Convert the resulting PDF into the given PDF/A format. +### pdfUniversalAccess(bool $bool) +Enable PDF for Universal Access for optimal accessibility. + +### route(string $name, array $parameters) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
+### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) +### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) +Either intervals or pages. + +### splitSpan(string $splitSpan) +Either the intervals or the page ranges to extract, depending on the selected mode. + +### splitUnify(bool $bool) +Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). + +### url(string $url) +URL of the page you want to convert into PDF.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
+### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. + +### assets(Stringable|string ...$paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). + +### webhook(array $webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
+### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) + +### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
+ +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### generateDocumentOutline(bool $bool) Define whether the document outline should be embedded into the PDF.
@@ -93,16 +135,6 @@ Overrides the default margins (e.g., 0.39), in inches.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### metadata(array $metadata) -Resets the metadata.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#metadata-chromium](https://gotenberg.dev/docs/routes#metadata-chromium)
-> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
-> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
-> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) - ### nativePageRanges(string $ranges) Page ranges to print, e.g., '1-5, 8, 11-13'.
@@ -125,12 +157,6 @@ Overrides the default paper size, in inches.

Examples of paper size ( ### paperWidth(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. -### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) -Convert the resulting PDF into the given PDF/A format. - -### pdfUniversalAccess(bool $bool) -Enable PDF for Universal Access for optimal accessibility. - ### preferCssPageSize(bool $bool) Define whether to prefer page size as defined by CSS.
@@ -143,39 +169,15 @@ Prints the background graphics.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### route(string $name, array $parameters) -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - ### scale(float $scale) The scale of the page rendering (e.g., 1.0).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) -### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. -### skipNetworkIdleEvent(bool $bool) -### splitMode(?Sensiolabs\GotenbergBundle\Enumeration\SplitMode $splitMode) -Either intervals or pages. - -### splitSpan(string $splitSpan) -Either the intervals or the page ranges to extract, depending on the selected mode. - -### splitUnify(bool $bool) -Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). - -### url(string $url) -URL of the page you want to convert into PDF.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) - -### userAgent(string $userAgent) -Override the default User-Agent HTTP header.
- ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
@@ -188,60 +190,58 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. -### webhookErrorRoute(string $route, array $parameters, ?string $method) +### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookErrorUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### footerFile(string $path) +HTML file containing the footer. +### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookExtraHeaders(array $extraHttpHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+### headerFile(string $path) +HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
-### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### cookies(array $cookies) -### forwardCookie(string $name) -### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. +### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
-### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### footerFile(string $path) -HTML file containing the footer. +### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
-### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### headerFile(string $path) -HTML file containing the header. +### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML document.
+ +### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+ +### userAgent(string $userAgent) +Override the default User-Agent HTTP header.
+ +### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). +### skipNetworkIdleEvent(bool $bool) diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index c9e00386..9431bfb0 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -3,53 +3,59 @@ > [!TIP] > See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) + ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML document.
- ### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -### clip(bool $bool) -Define whether to clip the screenshot according to the device dimensions. (Default false). +### webhook(array $webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
-### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookErrorRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print"). +### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnConsoleExceptions(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
+### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) - -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
+> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
+### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
+### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### clip(bool $bool) +Define whether to clip the screenshot according to the device dimensions. (Default false). ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). @@ -69,9 +75,8 @@ Define whether to optimize image encoding for speed, not for resulting size. (De ### quality(int $quality) The compression quality from range 0 to 100 (jpeg only). (default 100).
-### skipNetworkIdleEvent(bool $bool) -### userAgent(string $userAgent) -Override the default User-Agent HTTP header.
+### width(int $width) +The device screen width in pixels. (Default 800). ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
@@ -85,63 +90,58 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### width(int $width) -The device screen width in pixels. (Default 800). - -### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### content(string $template, array $context) +### contentFile(string $path) +The HTML file to convert into PDF. -### webhookErrorRoute(string $route, array $parameters, ?string $method) +### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookErrorUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### footerFile(string $path) +HTML file containing the footer. +### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookExtraHeaders(array $extraHttpHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+### headerFile(string $path) +HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
-### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### cookies(array $cookies) -### forwardCookie(string $name) -### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. +### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
-### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### footerFile(string $path) -HTML file containing the footer. +### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
-### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### headerFile(string $path) -HTML file containing the header. +### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML document.
+### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+ +### userAgent(string $userAgent) +Override the default User-Agent HTTP header.
+ +### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). + +### skipNetworkIdleEvent(bool $bool) diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index 987e647e..f70df03b 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -3,59 +3,69 @@ > [!TIP] > See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +### downloadFrom(array $downloadFrom) +Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) + +### files(Stringable|string ...$paths) +Add Markdown into a PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) + +### wrapper(string $template, array $context) +### wrapperFile(string $path) +The HTML file to convert into PDF. + ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML document.
- ### assets(Stringable|string ...$paths) Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). -### clip(bool $bool) -Define whether to clip the screenshot according to the device dimensions. (Default false). - -### downloadFrom(array $downloadFrom) -Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
+### webhook(array $webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) - -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print"). +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+### webhookErrorRoute(string $route, array $parameters, ?string $method) +> [!TIP] +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnConsoleExceptions(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
+### webhookErrorUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
+### webhookExtraHeaders(array $extraHttpHeaders) +Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) - -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
+> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
+### webhookUrl(string $url, ?string $method) +Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) +> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### files(Stringable|string ...$paths) -Add Markdown into a PDF.
+### addCookies(array $cookies) +Add cookies to store in the Chromium cookie jar.
-> [!TIP] -> See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) +### cookies(array $cookies) +### forwardCookie(string $name) +### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### clip(bool $bool) +Define whether to clip the screenshot according to the device dimensions. (Default false). ### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) The image compression format, either "png", "jpeg" or "webp". (default png). @@ -75,9 +85,8 @@ Define whether to optimize image encoding for speed, not for resulting size. (De ### quality(int $quality) The compression quality from range 0 to 100 (jpeg only). (default 100).
-### skipNetworkIdleEvent(bool $bool) -### userAgent(string $userAgent) -Override the default User-Agent HTTP header.
+### width(int $width) +The device screen width in pixels. (Default 800). ### waitDelay(string $delay) Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
@@ -91,67 +100,58 @@ Sets the JavaScript expression to wait before converting an HTML document to PDF > [!TIP] > See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) -### width(int $width) -The device screen width in pixels. (Default 800). - -### wrapper(string $template, array $context) -### wrapperFile(string $path) +### content(string $template, array $context) +### contentFile(string $path) The HTML file to convert into PDF. -### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### webhookErrorRoute(string $route, array $parameters, ?string $method) +### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookErrorUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### footerFile(string $path) +HTML file containing the footer. +### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) -### webhookExtraHeaders(array $extraHttpHeaders) -Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
+### headerFile(string $path) +HTML file containing the header. -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
-### webhookRoute(string $route, array $parameters, ?string $method) > [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) -### webhookUrl(string $url, ?string $method) -Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
+### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - -### addCookies(array $cookies) -Add cookies to store in the Chromium cookie jar.
+> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### cookies(array $cookies) -### forwardCookie(string $name) -### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. +### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
-### footer(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) -### footerFile(string $path) -HTML file containing the footer. +### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
-### header(string $template, array $context) > [!TIP] -> See: [https://gotenberg.dev/docs/routes#header-footer-chromium](https://gotenberg.dev/docs/routes#header-footer-chromium) +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) -### headerFile(string $path) -HTML file containing the header. +### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML document.
+### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+ +### userAgent(string $userAgent) +Override the default User-Agent HTTP header.
+ +### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). + +### skipNetworkIdleEvent(bool $bool) diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index df40e0df..125efec6 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -1,100 +1,27 @@ # UrlScreenshotBuilder -### addAsset(Stringable|string $path) -Adds a file, like an image, font, stylesheet, and so on. - -### addExtraHttpHeaders(array $headers) -Adds extra HTTP headers that Chromium will send when loading the HTML document.
- -### assets(Stringable|string ...$paths) -Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). - -### clip(bool $bool) -Define whether to clip the screenshot according to the device dimensions. (Default false). - ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
> [!TIP] > See: [https://gotenberg.dev/docs/routes#download-from](https://gotenberg.dev/docs/routes#download-from) -### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) -Forces Chromium to emulate, either "screen" or "print". (default "print"). - -### extraHttpHeaders(array $headers) -Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
- -### failOnConsoleExceptions(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) - -### failOnHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) - -### failOnResourceHttpStatusCodes(array $statusCodes) -Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) - -### failOnResourceLoadingFailed(bool $bool) -Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) - -### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) -The image compression format, either "png", "jpeg" or "webp". (default png). - -### height(int $height) -The device screen width in pixels. (Default 600). - -### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with transparency.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) - -### optimizeForSpeed(bool $bool) -Define whether to optimize image encoding for speed, not for resulting size. (Default false). - -### quality(int $quality) -The compression quality from range 0 to 100 (jpeg only). (default 100).
- ### route(string $name, array $parameters) > [!TIP] > See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) ### setRequestContext(?Symfony\Component\Routing\RequestContext $requestContext) -### skipNetworkIdleEvent(bool $bool) ### url(string $url) URL of the page you want to convert into PDF.
> [!TIP] > See: [https://gotenberg.dev/docs/routes#url-into-pdf-route](https://gotenberg.dev/docs/routes#url-into-pdf-route) -### userAgent(string $userAgent) -Override the default User-Agent HTTP header.
- -### waitDelay(string $delay) -Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) - -### waitForExpression(string $expression) -Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) +### addAsset(Stringable|string $path) +Adds a file, like an image, font, stylesheet, and so on. -### width(int $width) -The device screen width in pixels. (Default 800). +### assets(Stringable|string ...$paths) +Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). ### webhook(array $webhook) ### webhookConfiguration(string $name) @@ -135,6 +62,42 @@ Add cookies to store in the Chromium cookie jar.
### cookies(array $cookies) ### forwardCookie(string $name) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) +### clip(bool $bool) +Define whether to clip the screenshot according to the device dimensions. (Default false). + +### format(Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat $format) +The image compression format, either "png", "jpeg" or "webp". (default png). + +### height(int $height) +The device screen width in pixels. (Default 600). + +### omitBackground(bool $bool) +Hides default white background and allows generating screenshot with transparency.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) + +### optimizeForSpeed(bool $bool) +Define whether to optimize image encoding for speed, not for resulting size. (Default false). + +### quality(int $quality) +The compression quality from range 0 to 100 (jpeg only). (default 100).
+ +### width(int $width) +The device screen width in pixels. (Default 800). + +### waitDelay(string $delay) +Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
document before converting it to PDF.
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) + +### waitForExpression(string $expression) +Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) + ### content(string $template, array $context) ### contentFile(string $path) The HTML file to convert into PDF. @@ -153,3 +116,40 @@ HTML file containing the footer. ### headerFile(string $path) HTML file containing the header. +### failOnConsoleExceptions(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) + +### failOnHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) + +### failOnResourceHttpStatusCodes(array $statusCodes) +Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) + +### failOnResourceLoadingFailed(bool $bool) +Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
+ +> [!TIP] +> See: [https://gotenberg.dev/docs/routes#network-errors-chromium](https://gotenberg.dev/docs/routes#network-errors-chromium) + +### addExtraHttpHeaders(array $headers) +Adds extra HTTP headers that Chromium will send when loading the HTML document.
+ +### extraHttpHeaders(array $headers) +Sets extra HTTP headers that Chromium will send when loading the HTML document. (overrides any previous headers).
+ +### userAgent(string $userAgent) +Override the default User-Agent HTTP header.
+ +### emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType) +Forces Chromium to emulate, either "screen" or "print". (default "print"). + +### skipNetworkIdleEvent(bool $bool) diff --git a/src/Builder/Behaviors/Chromium/AssetTrait.php b/src/Builder/Behaviors/Chromium/AssetTrait.php index ec946bb9..471cc74b 100644 --- a/src/Builder/Behaviors/Chromium/AssetTrait.php +++ b/src/Builder/Behaviors/Chromium/AssetTrait.php @@ -9,6 +9,8 @@ /** * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route + * + * @package Behavior\\Assets */ trait AssetTrait { diff --git a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php index d699d549..4c7ee6d2 100644 --- a/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php +++ b/src/Builder/Behaviors/Chromium/CustomHttpHeadersTrait.php @@ -12,6 +12,8 @@ /** * @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium + * + * @package Behavior\\Http\\CustomHeaders */ trait CustomHttpHeadersTrait { diff --git a/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php b/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php index 94b7e76f..a4184e5e 100644 --- a/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php +++ b/src/Builder/Behaviors/Chromium/EmulatedMediaTypeTrait.php @@ -11,6 +11,8 @@ /** * @see https://gotenberg.dev/docs/routes#emulated-media-type-chromium + * + * @package Behavior\\MediaType */ trait EmulatedMediaTypeTrait { diff --git a/src/Builder/Behaviors/Chromium/FailOnTrait.php b/src/Builder/Behaviors/Chromium/FailOnTrait.php index 46dc0365..2fdb2b76 100644 --- a/src/Builder/Behaviors/Chromium/FailOnTrait.php +++ b/src/Builder/Behaviors/Chromium/FailOnTrait.php @@ -9,6 +9,9 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\ArrayNodeBuilder; use Sensiolabs\GotenbergBundle\NodeBuilder\BooleanNodeBuilder; +/** + * @package Behavior\\FailOn + */ trait FailOnTrait { abstract protected function getBodyBag(): BodyBag; diff --git a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php index 442f2ed0..6b09a2c5 100644 --- a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php @@ -16,6 +16,9 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\ScalarNodeBuilder; use Sensiolabs\GotenbergBundle\NodeBuilder\UnitNodeBuilder; +/** + * @package Behavior\\Chromium\\PageProperties + */ trait PdfPagePropertiesTrait { abstract protected function getBodyBag(): BodyBag; diff --git a/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php b/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php index 1520de34..887b8593 100644 --- a/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php +++ b/src/Builder/Behaviors/Chromium/PerformanceModeTrait.php @@ -10,6 +10,8 @@ /** * @see https://gotenberg.dev/docs/routes#performance-mode-chromium + * + * @package Behavior\\Performance */ trait PerformanceModeTrait { diff --git a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php index 8a4c3729..44acb038 100644 --- a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php @@ -13,6 +13,8 @@ /** * @see https://gotenberg.dev/docs/routes#screenshots-route + * + * @package Behavior\\Chromium\\PageProperties */ trait ScreenshotPagePropertiesTrait { diff --git a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php index f72447fb..e993b5fe 100644 --- a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php +++ b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php @@ -7,6 +7,9 @@ use Sensiolabs\GotenbergBundle\Builder\Util\ValidatorFactory; use Sensiolabs\GotenbergBundle\NodeBuilder\ScalarNodeBuilder; +/** + * @package Behavior\\Chromium\\WaitFor + */ trait WaitBeforeRenderingTrait { abstract protected function getBodyBag(): BodyBag; From cf075a57d5028de4950dbe30b54a63426e906c00 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Sat, 12 Apr 2025 16:23:18 +0200 Subject: [PATCH 17/30] Update --- docs/pdf/builders_api/ConvertPdfBuilder.md | 21 +---- docs/pdf/builders_api/FlattenPdfBuilder.md | 21 +---- docs/pdf/builders_api/HtmlPdfBuilder.md | 81 ++++--------------- .../pdf/builders_api/LibreOfficePdfBuilder.md | 21 +---- docs/pdf/builders_api/MarkdownPdfBuilder.md | 81 ++++--------------- docs/pdf/builders_api/MergePdfBuilder.md | 23 ++---- docs/pdf/builders_api/SplitPdfBuilder.md | 21 +---- docs/pdf/builders_api/UrlPdfBuilder.md | 81 ++++--------------- .../builders_api/HtmlScreenshotBuilder.md | 26 +----- .../builders_api/MarkdownScreenshotBuilder.md | 26 +----- .../builders_api/UrlScreenshotBuilder.md | 26 +----- .../Chromium/PdfPagePropertiesTrait.php | 26 +----- .../ScreenshotPagePropertiesTrait.php | 2 - src/Builder/Behaviors/WebhookTrait.php | 14 +--- src/Builder/Pdf/MergePdfBuilder.php | 2 + 15 files changed, 80 insertions(+), 392 deletions(-) diff --git a/docs/pdf/builders_api/ConvertPdfBuilder.md b/docs/pdf/builders_api/ConvertPdfBuilder.md index d78fd5fd..e63d1558 100644 --- a/docs/pdf/builders_api/ConvertPdfBuilder.md +++ b/docs/pdf/builders_api/ConvertPdfBuilder.md @@ -17,35 +17,20 @@ Convert the resulting PDF into the given PDF/A format. Enable PDF for Universal Access for optimal accessibility. ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - diff --git a/docs/pdf/builders_api/FlattenPdfBuilder.md b/docs/pdf/builders_api/FlattenPdfBuilder.md index c866e00c..a1dd7d04 100644 --- a/docs/pdf/builders_api/FlattenPdfBuilder.md +++ b/docs/pdf/builders_api/FlattenPdfBuilder.md @@ -11,35 +11,20 @@ Sets download from to download each entry (file) in parallel (URLs MUST return a ### files(Stringable|string ...$paths) ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index a1b1a2d1..c985f8ca 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -44,38 +44,23 @@ Adds a file, like an image, font, stylesheet, and so on. Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
@@ -83,58 +68,31 @@ Add cookies to store in the Chromium cookie jar.
### forwardCookie(string $name) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Define whether the document outline should be embedded into the PDF. ### landscape(bool $bool) -Set the paper orientation to landscape.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Set the paper orientation to landscape. ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Overrides the default margins (e.g., 0.39), in inches. ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-5, 8, 11-13'.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Page ranges to print, e.g., '1-5, 8, 11-13'. ### omitBackground(bool $bool) -Hide the default white background and allow generating PDFs with transparency.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Hide the default white background and allow generating PDFs with transparency. ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. @@ -147,22 +105,13 @@ Overrides the default paper size, in inches.

Examples of paper size ( Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Define whether to prefer page size as defined by CSS. ### printBackground(bool $bool) -Prints the background graphics.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Prints the background graphics. ### scale(float $scale) -The scale of the page rendering (e.g., 1.0).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +The scale of the page rendering (e.g., 1.0). ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index 7bbc429c..48090563 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -122,35 +122,20 @@ Either the intervals or the page ranges to extract, depending on the selected mo Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 05397f8c..b19f9234 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -54,38 +54,23 @@ Adds a file, like an image, font, stylesheet, and so on. Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
@@ -93,58 +78,31 @@ Add cookies to store in the Chromium cookie jar.
### forwardCookie(string $name) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Define whether the document outline should be embedded into the PDF. ### landscape(bool $bool) -Set the paper orientation to landscape.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Set the paper orientation to landscape. ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Overrides the default margins (e.g., 0.39), in inches. ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-5, 8, 11-13'.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Page ranges to print, e.g., '1-5, 8, 11-13'. ### omitBackground(bool $bool) -Hide the default white background and allow generating PDFs with transparency.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Hide the default white background and allow generating PDFs with transparency. ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. @@ -157,22 +115,13 @@ Overrides the default paper size, in inches.

Examples of paper size ( Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Define whether to prefer page size as defined by CSS. ### printBackground(bool $bool) -Prints the background graphics.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Prints the background graphics. ### scale(float $scale) -The scale of the page rendering (e.g., 1.0).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +The scale of the page rendering (e.g., 1.0). ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index 85ae9e8c..24b18048 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -1,5 +1,7 @@ # MergePdfBuilder +Merge `n` pdf files into a single one.
+ > [!TIP] > See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) @@ -38,35 +40,20 @@ Convert the resulting PDF into the given PDF/A format. Enable PDF for Universal Access for optimal accessibility. ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index c5efc1ed..8d28aa89 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -42,35 +42,20 @@ Either the intervals or the page ranges to extract, depending on the selected mo Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index b72eccbc..d3042eb5 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -55,38 +55,23 @@ Adds a file, like an image, font, stylesheet, and so on. Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
@@ -94,58 +79,31 @@ Add cookies to store in the Chromium cookie jar.
### forwardCookie(string $name) ### setCookie(string $name, Symfony\Component\HttpFoundation\Cookie|array $cookie) ### generateDocumentOutline(bool $bool) -Define whether the document outline should be embedded into the PDF.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Define whether the document outline should be embedded into the PDF. ### landscape(bool $bool) -Set the paper orientation to landscape.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Set the paper orientation to landscape. ### marginBottom(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### marginLeft(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### marginRight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### marginTop(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### margins(float $top, float $bottom, float $left, float $right, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) -Overrides the default margins (e.g., 0.39), in inches.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Overrides the default margins (e.g., 0.39), in inches. ### nativePageRanges(string $ranges) -Page ranges to print, e.g., '1-5, 8, 11-13'.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Page ranges to print, e.g., '1-5, 8, 11-13'. ### omitBackground(bool $bool) -Hide the default white background and allow generating PDFs with transparency.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Hide the default white background and allow generating PDFs with transparency. ### paperHeight(float $value, Sensiolabs\GotenbergBundle\Enumeration\Unit $unit) Specify paper height using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. @@ -158,22 +116,13 @@ Overrides the default paper size, in inches.

Examples of paper size ( Specify paper width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. ### preferCssPageSize(bool $bool) -Define whether to prefer page size as defined by CSS.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Define whether to prefer page size as defined by CSS. ### printBackground(bool $bool) -Prints the background graphics.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Prints the background graphics. ### scale(float $scale) -The scale of the page rendering (e.g., 1.0).
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +The scale of the page rendering (e.g., 1.0). ### singlePage(bool $bool) Define whether to print the entire content in one single page.

If the singlePage form field is set to true, it automatically overrides the values from the paperHeight and nativePageRanges form fields. diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index 9431bfb0..66fcff8e 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -16,38 +16,23 @@ Adds a file, like an image, font, stylesheet, and so on. Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
@@ -64,10 +49,7 @@ The image compression format, either "png", "jpeg" or "webp". (default png). The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with transparency.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Hides default white background and allows generating screenshot with transparency. ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index f70df03b..7345d32d 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -26,38 +26,23 @@ Adds a file, like an image, font, stylesheet, and so on. Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
@@ -74,10 +59,7 @@ The image compression format, either "png", "jpeg" or "webp". (default png). The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with transparency.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Hides default white background and allows generating screenshot with transparency. ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index 125efec6..81c18d12 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -24,38 +24,23 @@ Adds a file, like an image, font, stylesheet, and so on. Adds additional files, like images, fonts, stylesheets, and so on (overrides any previous files). ### webhook(array $webhook) -### webhookConfiguration(string $name) -Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.
- > [!TIP] > See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) -### webhookErrorRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) +### webhookConfiguration(string $name) +Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. +### webhookErrorRoute(string $route, array $parameters, ?string $method) ### webhookErrorUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookExtraHeaders(array $extraHttpHeaders) Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookRoute(string $route, array $parameters, ?string $method) -> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### webhookUrl(string $url, ?string $method) Sets the webhook for cases of success.
Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH.
-> [!TIP] -> See: [https://gotenberg.dev/docs/webhook](https://gotenberg.dev/docs/webhook) - ### addCookies(array $cookies) Add cookies to store in the Chromium cookie jar.
@@ -72,10 +57,7 @@ The image compression format, either "png", "jpeg" or "webp". (default png). The device screen width in pixels. (Default 600). ### omitBackground(bool $bool) -Hides default white background and allows generating screenshot with transparency.
- -> [!TIP] -> See: [https://gotenberg.dev/docs/routes#page-properties-chromium](https://gotenberg.dev/docs/routes#page-properties-chromium) +Hides default white background and allows generating screenshot with transparency. ### optimizeForSpeed(bool $bool) Define whether to optimize image encoding for speed, not for resulting size. (Default false). diff --git a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php index 6b09a2c5..ee523f24 100644 --- a/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/PdfPagePropertiesTrait.php @@ -17,6 +17,8 @@ use Sensiolabs\GotenbergBundle\NodeBuilder\UnitNodeBuilder; /** + * @see https://gotenberg.dev/docs/routes#page-properties-chromium + * * @package Behavior\\Chromium\\PageProperties */ trait PdfPagePropertiesTrait @@ -94,8 +96,6 @@ public function paperStandardSize(PaperSizeInterface $paperSize): static /** * Specify top margin width using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_top'))] public function marginTop(float $value, Unit $unit = Unit::Inches): static @@ -107,8 +107,6 @@ public function marginTop(float $value, Unit $unit = Unit::Inches): static /** * Specify bottom margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_bottom'))] public function marginBottom(float $value, Unit $unit = Unit::Inches): static @@ -120,8 +118,6 @@ public function marginBottom(float $value, Unit $unit = Unit::Inches): static /** * Specify left margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_left'))] public function marginLeft(float $value, Unit $unit = Unit::Inches): static @@ -133,8 +129,6 @@ public function marginLeft(float $value, Unit $unit = Unit::Inches): static /** * Specify right margin using units like 72pt, 96px, 1in, 25.4mm, 2.54cm, or 6pc. Default unit is inches if unspecified. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new UnitNodeBuilder('margin_right'))] public function marginRight(float $value, Unit $unit = Unit::Inches): static @@ -146,8 +140,6 @@ public function marginRight(float $value, Unit $unit = Unit::Inches): static /** * Overrides the default margins (e.g., 0.39), in inches. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ public function margins(float $top, float $bottom, float $left, float $right, Unit $unit = Unit::Inches): static { @@ -161,8 +153,6 @@ public function margins(float $top, float $bottom, float $left, float $right, Un /** * Define whether to prefer page size as defined by CSS. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('prefer_css_page_size'))] public function preferCssPageSize(bool $bool): static @@ -174,8 +164,6 @@ public function preferCssPageSize(bool $bool): static /** * Define whether the document outline should be embedded into the PDF. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('generate_document_outline'))] public function generateDocumentOutline(bool $bool): static @@ -187,8 +175,6 @@ public function generateDocumentOutline(bool $bool): static /** * Prints the background graphics. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('print_background'))] public function printBackground(bool $bool): static @@ -200,8 +186,6 @@ public function printBackground(bool $bool): static /** * Hide the default white background and allow generating PDFs with transparency. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] public function omitBackground(bool $bool): static @@ -213,8 +197,6 @@ public function omitBackground(bool $bool): static /** * Set the paper orientation to landscape. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('landscape'))] public function landscape(bool $bool = true): static @@ -226,8 +208,6 @@ public function landscape(bool $bool = true): static /** * The scale of the page rendering (e.g., 1.0). - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new FloatNodeBuilder('scale'))] public function scale(float $scale): static @@ -239,8 +219,6 @@ public function scale(float $scale): static /** * Page ranges to print, e.g., '1-5, 8, 11-13'. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new ScalarNodeBuilder('native_page_ranges'))] public function nativePageRanges(string $ranges): static diff --git a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php index 44acb038..ad80e1c5 100644 --- a/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php +++ b/src/Builder/Behaviors/Chromium/ScreenshotPagePropertiesTrait.php @@ -79,8 +79,6 @@ public function quality(int $quality): static /** * Hides default white background and allows generating screenshot with transparency. - * - * @see https://gotenberg.dev/docs/routes#page-properties-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('omit_background'))] public function omitBackground(bool $bool = true): static diff --git a/src/Builder/Behaviors/WebhookTrait.php b/src/Builder/Behaviors/WebhookTrait.php index b937fc50..ce8367ff 100644 --- a/src/Builder/Behaviors/WebhookTrait.php +++ b/src/Builder/Behaviors/WebhookTrait.php @@ -43,6 +43,8 @@ abstract protected function getHeadersBag(): HeadersBag; /** * @param WebhookConfiguration $webhook + * + * @see https://gotenberg.dev/docs/webhook */ #[ExposeSemantic(new WebhookNodeBuilder('webhook', children: [ new ScalarNodeBuilder('config_name', restrictTo: 'string'), @@ -114,8 +116,6 @@ public function webhook(array $webhook): static * Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. * * @param 'POST'|'PUT'|'PATCH'|null $method - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookUrl(string $url, string|null $method = null): static { @@ -132,8 +132,6 @@ public function webhookUrl(string $url, string|null $method = null): static * Optionally sets a custom HTTP method for such endpoint among : POST, PUT or PATCH. * * @param 'POST'|'PUT'|'PATCH'|null $method - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookErrorUrl(string $url, string|null $method = null): static { @@ -149,8 +147,6 @@ public function webhookErrorUrl(string $url, string|null $method = null): static * Extra headers that will be provided to the webhook endpoint. May it either be Success or Error. * * @param array $extraHttpHeaders - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookExtraHeaders(array $extraHttpHeaders): static { @@ -162,8 +158,6 @@ public function webhookExtraHeaders(array $extraHttpHeaders): static /** * @param array $parameters * @param 'PATCH'|'POST'|'PUT'|null $method - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookRoute(string $route, array $parameters = [], string|null $method = null): static { @@ -173,8 +167,6 @@ public function webhookRoute(string $route, array $parameters = [], string|null /** * * @param array $parameters * @param 'PATCH'|'POST'|'PUT'|null $method - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookErrorRoute(string $route, array $parameters = [], string|null $method = null): static { @@ -183,8 +175,6 @@ public function webhookErrorRoute(string $route, array $parameters = [], string| /** * Providing an existing $name from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined. - * - * @see https://gotenberg.dev/docs/webhook */ public function webhookConfiguration(string $name): static { diff --git a/src/Builder/Pdf/MergePdfBuilder.php b/src/Builder/Pdf/MergePdfBuilder.php index 8759570d..beef9aab 100644 --- a/src/Builder/Pdf/MergePdfBuilder.php +++ b/src/Builder/Pdf/MergePdfBuilder.php @@ -16,6 +16,8 @@ use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; /** + * Merge `n` pdf files into a single one. + * * @see https://gotenberg.dev/docs/routes#merge-pdfs-route */ #[SemanticNode(type: 'pdf', name: 'merge')] From a50dccf25e1e3e61aeb69ee641a39a5d2d16ac41 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Sat, 12 Apr 2025 16:36:35 +0200 Subject: [PATCH 18/30] Update --- src/Builder/Pdf/SplitPdfBuilder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Builder/Pdf/SplitPdfBuilder.php b/src/Builder/Pdf/SplitPdfBuilder.php index d302fb9e..a2f06897 100644 --- a/src/Builder/Pdf/SplitPdfBuilder.php +++ b/src/Builder/Pdf/SplitPdfBuilder.php @@ -17,6 +17,8 @@ use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; /** + * Split `n` pdf files. + * * @see https://gotenberg.dev/docs/routes#split-pdfs-route */ #[SemanticNode(type: 'pdf', name: 'split')] From 95458ecd0026d62da81f1df995b73bcf7cb1ac2a Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Sat, 12 Apr 2025 16:36:45 +0200 Subject: [PATCH 19/30] Update --- docs/pdf/builders_api/SplitPdfBuilder.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index 8d28aa89..abb55821 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -1,5 +1,7 @@ # SplitPdfBuilder +Split `n` pdf files.
+ > [!TIP] > See: [https://gotenberg.dev/docs/routes#split-pdfs-route](https://gotenberg.dev/docs/routes#split-pdfs-route) From 96c01908cdade63cf21b57594f4b1f360618fce6 Mon Sep 17 00:00:00 2001 From: Hubert Lenoir Date: Mon, 14 Apr 2025 11:05:16 +0200 Subject: [PATCH 20/30] Fix doc (#2) --- docs/generate.php | 16 ++++++++++++++-- docs/pdf/builders_api/HtmlPdfBuilder.md | 10 +++++----- docs/pdf/builders_api/LibreOfficePdfBuilder.md | 2 +- docs/pdf/builders_api/MarkdownPdfBuilder.md | 14 +++++--------- docs/pdf/builders_api/MergePdfBuilder.md | 2 +- docs/pdf/builders_api/SplitPdfBuilder.md | 2 +- docs/pdf/builders_api/UrlPdfBuilder.md | 10 +++++----- .../builders_api/HtmlScreenshotBuilder.md | 8 ++++---- .../builders_api/MarkdownScreenshotBuilder.md | 12 ++++-------- .../builders_api/UrlScreenshotBuilder.md | 8 ++++---- src/Builder/Behaviors/Chromium/FailOnTrait.php | 2 +- .../Chromium/WaitBeforeRenderingTrait.php | 2 +- src/Builder/Pdf/MarkdownPdfBuilder.php | 15 ++------------- .../Screenshot/MarkdownScreenshotBuilder.php | 15 ++------------- 14 files changed, 50 insertions(+), 68 deletions(-) diff --git a/docs/generate.php b/docs/generate.php index 29c53cf8..1edfe8c0 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -235,6 +235,7 @@ private function prepareBuilder(ReflectionClass $class): void } $this->prepareBuilderFromClass($class); + $this->cleanBuilderFromClass($class); foreach ($this->parts['methods']['@'] as $methodName => $parts) { $package = $parts['package'] ?? '@'; @@ -303,14 +304,25 @@ private function prepareBuilderFromClass(ReflectionClass $class): void } if (isset($parsedDocBlock['tags']['see'])) { - $this->parts['methods']['@'][$method->getShortName()]['tags']['see'] = array_unique(array_merge( + $this->parts['methods']['@'][$method->getShortName()]['tags']['see'] = array_unique(array_map('trim', array_merge( $this->parts['methods']['@'][$method->getShortName()]['tags']['see'] ?? [], $parsedDocBlock['tags']['see'], - )); + ))); } } } + /** + * @param ReflectionClass $class + */ + private function cleanBuilderFromClass(ReflectionClass $class): void + { + foreach ($class->getMethods(ReflectionMethod::IS_PROTECTED | ReflectionMethod::IS_PRIVATE) as $method) { + unset($this->methodsSignature[$method->getName()]); + unset($this->parts['methods']['@'][$method->getShortName()]); + } + } + /** * @return ParsedDocBlock * diff --git a/docs/pdf/builders_api/HtmlPdfBuilder.md b/docs/pdf/builders_api/HtmlPdfBuilder.md index c985f8ca..b882db56 100644 --- a/docs/pdf/builders_api/HtmlPdfBuilder.md +++ b/docs/pdf/builders_api/HtmlPdfBuilder.md @@ -20,7 +20,7 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) +> See: [https://exiftool.org/TagNames/XMP.html#pdf](https://exiftool.org/TagNames/XMP.html#pdf) ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. @@ -126,7 +126,7 @@ Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
do Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### content(string $template, array $context) ### contentFile(string $path) @@ -150,19 +150,19 @@ HTML file containing the header. Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#console-exceptions-chromium](https://gotenberg.dev/docs/routes#console-exceptions-chromium) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
diff --git a/docs/pdf/builders_api/LibreOfficePdfBuilder.md b/docs/pdf/builders_api/LibreOfficePdfBuilder.md index 48090563..11857b3a 100644 --- a/docs/pdf/builders_api/LibreOfficePdfBuilder.md +++ b/docs/pdf/builders_api/LibreOfficePdfBuilder.md @@ -83,7 +83,7 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) +> See: [https://exiftool.org/TagNames/XMP.html#pdf](https://exiftool.org/TagNames/XMP.html#pdf) ### nativePageRanges(string $ranges) Page ranges to print, e.g., '1-4' - empty means all pages.
diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index b19f9234..53f67d76 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -26,7 +26,7 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) +> See: [https://exiftool.org/TagNames/XMP.html#pdf](https://exiftool.org/TagNames/XMP.html#pdf) ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. @@ -136,11 +136,7 @@ Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
do Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) - -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### footer(string $template, array $context) > [!TIP] @@ -160,19 +156,19 @@ HTML file containing the header. Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#console-exceptions-chromium](https://gotenberg.dev/docs/routes#console-exceptions-chromium) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
diff --git a/docs/pdf/builders_api/MergePdfBuilder.md b/docs/pdf/builders_api/MergePdfBuilder.md index 24b18048..d50b6ba6 100644 --- a/docs/pdf/builders_api/MergePdfBuilder.md +++ b/docs/pdf/builders_api/MergePdfBuilder.md @@ -31,7 +31,7 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) +> See: [https://exiftool.org/TagNames/XMP.html#pdf](https://exiftool.org/TagNames/XMP.html#pdf) ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. diff --git a/docs/pdf/builders_api/SplitPdfBuilder.md b/docs/pdf/builders_api/SplitPdfBuilder.md index abb55821..04662aae 100644 --- a/docs/pdf/builders_api/SplitPdfBuilder.md +++ b/docs/pdf/builders_api/SplitPdfBuilder.md @@ -26,7 +26,7 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) +> See: [https://exiftool.org/TagNames/XMP.html#pdf](https://exiftool.org/TagNames/XMP.html#pdf) ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. diff --git a/docs/pdf/builders_api/UrlPdfBuilder.md b/docs/pdf/builders_api/UrlPdfBuilder.md index d3042eb5..ac6c5179 100644 --- a/docs/pdf/builders_api/UrlPdfBuilder.md +++ b/docs/pdf/builders_api/UrlPdfBuilder.md @@ -20,7 +20,7 @@ Resets the metadata.
> See: [https://gotenberg.dev/docs/routes#metadata-libreoffice](https://gotenberg.dev/docs/routes#metadata-libreoffice)
> See: [https://gotenberg.dev/docs/routes#write-pdf-metadata-route](https://gotenberg.dev/docs/routes#write-pdf-metadata-route)
> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route)
-> See: [https://exiftool.org/TagNames/XMP.html#pdf ](https://exiftool.org/TagNames/XMP.html#pdf ) +> See: [https://exiftool.org/TagNames/XMP.html#pdf](https://exiftool.org/TagNames/XMP.html#pdf) ### pdfFormat(?Sensiolabs\GotenbergBundle\Enumeration\PdfFormat $format) Convert the resulting PDF into the given PDF/A format. @@ -137,7 +137,7 @@ Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
do Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### content(string $template, array $context) ### contentFile(string $path) @@ -161,19 +161,19 @@ HTML file containing the header. Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#console-exceptions-chromium](https://gotenberg.dev/docs/routes#console-exceptions-chromium) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
diff --git a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md index 66fcff8e..75d8f397 100644 --- a/docs/screenshot/builders_api/HtmlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/HtmlScreenshotBuilder.md @@ -70,7 +70,7 @@ Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
do Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### content(string $template, array $context) ### contentFile(string $path) @@ -94,19 +94,19 @@ HTML file containing the header. Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#console-exceptions-chromium](https://gotenberg.dev/docs/routes#console-exceptions-chromium) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index 7345d32d..530335b3 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -80,11 +80,7 @@ Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
do Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) - -### content(string $template, array $context) -### contentFile(string $path) -The HTML file to convert into PDF. +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### footer(string $template, array $context) > [!TIP] @@ -104,19 +100,19 @@ HTML file containing the header. Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#console-exceptions-chromium](https://gotenberg.dev/docs/routes#console-exceptions-chromium) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
diff --git a/docs/screenshot/builders_api/UrlScreenshotBuilder.md b/docs/screenshot/builders_api/UrlScreenshotBuilder.md index 81c18d12..b34228df 100644 --- a/docs/screenshot/builders_api/UrlScreenshotBuilder.md +++ b/docs/screenshot/builders_api/UrlScreenshotBuilder.md @@ -78,7 +78,7 @@ Sets the duration (i.e., "1s", "2ms", etc.) to wait when loading an HTML
do Sets the JavaScript expression to wait before converting an HTML document to PDF until it returns true.

For instance: "window.status === 'ready'".
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#wait-before-rendering](https://gotenberg.dev/docs/routes#wait-before-rendering) +> See: [https://gotenberg.dev/docs/routes#wait-before-rendering-chromium](https://gotenberg.dev/docs/routes#wait-before-rendering-chromium) ### content(string $template, array $context) ### contentFile(string $path) @@ -102,19 +102,19 @@ HTML file containing the header. Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#console-exceptions](https://gotenberg.dev/docs/routes#console-exceptions) +> See: [https://gotenberg.dev/docs/routes#console-exceptions-chromium](https://gotenberg.dev/docs/routes#console-exceptions-chromium) ### failOnHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceHttpStatusCodes(array $statusCodes) Return a 409 Conflict response if the HTTP status code from at least one resource is not acceptable. (overrides any previous configuration).
> [!TIP] -> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium ) +> See: [https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium) ### failOnResourceLoadingFailed(bool $bool) Forces GotenbergPdf to return a 409 Conflict response if Chromium fails to load at least one resource.
(default false).
diff --git a/src/Builder/Behaviors/Chromium/FailOnTrait.php b/src/Builder/Behaviors/Chromium/FailOnTrait.php index 2fdb2b76..5beb77de 100644 --- a/src/Builder/Behaviors/Chromium/FailOnTrait.php +++ b/src/Builder/Behaviors/Chromium/FailOnTrait.php @@ -65,7 +65,7 @@ public function failOnResourceLoadingFailed(bool $bool = true): static * Forces GotenbergPdf to return a 409 Conflict response if there are * exceptions in the Chromium console. (default false). * - * @see https://gotenberg.dev/docs/routes#console-exceptions + * @see https://gotenberg.dev/docs/routes#console-exceptions-chromium */ #[ExposeSemantic(new BooleanNodeBuilder('fail_on_console_exceptions'))] public function failOnConsoleExceptions(bool $bool = true): static diff --git a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php index e993b5fe..6b8bc5ce 100644 --- a/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php +++ b/src/Builder/Behaviors/Chromium/WaitBeforeRenderingTrait.php @@ -34,7 +34,7 @@ public function waitDelay(string $delay): static * * For instance: "window.status === 'ready'". * - * @see https://gotenberg.dev/docs/routes#wait-before-rendering + * @see https://gotenberg.dev/docs/routes#wait-before-rendering-chromium */ #[ExposeSemantic(new ScalarNodeBuilder('wait_for_expression'))] public function waitForExpression(string $expression): static diff --git a/src/Builder/Pdf/MarkdownPdfBuilder.php b/src/Builder/Pdf/MarkdownPdfBuilder.php index 2ca8ab69..87692aad 100644 --- a/src/Builder/Pdf/MarkdownPdfBuilder.php +++ b/src/Builder/Pdf/MarkdownPdfBuilder.php @@ -21,6 +21,8 @@ final class MarkdownPdfBuilder extends AbstractBuilder implements BuilderAssetIn use ChromiumPdfTrait { content as wrapper; contentFile as wrapperFile; + content as private; + contentFile as private; } public const ENDPOINT = '/forms/chromium/convert/markdown'; @@ -45,19 +47,6 @@ public function files(string|\Stringable ...$paths): self return $this; } - /** - * @param array $context - */ - public function content(string $template, array $context = []): void - { - throw new \BadMethodCallException('Use wrapper() instead of content().'); - } - - public function contentFile(string $path): void - { - throw new \BadMethodCallException('Use wrapperFile() instead of contentFile().'); - } - protected function getEndpoint(): string { return self::ENDPOINT; diff --git a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php index bf9c8e60..be9cc088 100644 --- a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php +++ b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php @@ -21,6 +21,8 @@ final class MarkdownScreenshotBuilder extends AbstractBuilder implements Builder use ChromiumScreenshotTrait { content as wrapper; contentFile as wrapperFile; + content as private; + contentFile as private; } public const ENDPOINT = '/forms/chromium/screenshot/markdown'; @@ -45,19 +47,6 @@ public function files(string|\Stringable ...$paths): self return $this; } - /** - * @param array $context - */ - public function content(string $template, array $context = []): void - { - throw new \BadMethodCallException('Use wrapper() instead of content().'); - } - - public function contentFile(string $path): void - { - throw new \BadMethodCallException('Use wrapperFile() instead of contentFile().'); - } - protected function getEndpoint(): string { return self::ENDPOINT; From 360c6227d7a022a0c2d79a8c5db7ffa9f2604479 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Tue, 15 Apr 2025 09:24:37 +0200 Subject: [PATCH 21/30] Update docs/generate.php --- docs/generate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/generate.php b/docs/generate.php index 1edfe8c0..364e1d81 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -304,7 +304,7 @@ private function prepareBuilderFromClass(ReflectionClass $class): void } if (isset($parsedDocBlock['tags']['see'])) { - $this->parts['methods']['@'][$method->getShortName()]['tags']['see'] = array_unique(array_map('trim', array_merge( + $this->parts['methods']['@'][$method->getShortName()]['tags']['see'] = array_unique(array_map(trim(...), array_merge( $this->parts['methods']['@'][$method->getShortName()]['tags']['see'] ?? [], $parsedDocBlock['tags']['see'], ))); From f330fd25c1432ae8c71664dd4fd01dcaa385c43a Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Tue, 15 Apr 2025 09:58:32 +0200 Subject: [PATCH 22/30] update --- src/Formatter/AssetBaseDirFormatter.php | 2 +- tests/PHPStanRules/AlwaysUsedMethodRule.php | 39 ++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/Formatter/AssetBaseDirFormatter.php b/src/Formatter/AssetBaseDirFormatter.php index 45b5a413..07715207 100644 --- a/src/Formatter/AssetBaseDirFormatter.php +++ b/src/Formatter/AssetBaseDirFormatter.php @@ -15,7 +15,7 @@ public function __construct( private readonly string $projectDir, string $baseDir, ) { - $this->baseDir = rtrim($baseDir, '/'); + $this->baseDir = rtrim($baseDir, '/\\'); } public function resolve(string $path): string diff --git a/tests/PHPStanRules/AlwaysUsedMethodRule.php b/tests/PHPStanRules/AlwaysUsedMethodRule.php index 5f940344..9b3e03e2 100644 --- a/tests/PHPStanRules/AlwaysUsedMethodRule.php +++ b/tests/PHPStanRules/AlwaysUsedMethodRule.php @@ -1,16 +1,47 @@ isPrivate() && str_starts_with($methodReflection->getName(), 'normalize'); + if (!$methodReflection->isPrivate()) { + return false; + } + + if (!$methodReflection instanceof PhpMethodReflection) { + return false; + } + + $declaringClass = $methodReflection->getDeclaringClass(); + $className = $declaringClass->getName(); + + if (!$this->reflectionProvider->hasClass($className)) { + return false; + } + + try { + $refMethod = new \ReflectionMethod($className, $methodReflection->getName()); + foreach ($refMethod->getAttributes() as $attribute) { + if ($attribute->getName() === NormalizeGotenbergPayload::class) { + return true; + } + } + } catch (\ReflectionException) { + } + + return false; } } From c7392b3a683cd2bebbf75f3c039dfc6983a72926 Mon Sep 17 00:00:00 2001 From: "hubert.lenoir" Date: Tue, 15 Apr 2025 10:02:48 +0200 Subject: [PATCH 23/30] fix: remove old tests --- tests/Builder/Pdf/MarkdownPdfBuilderTest.php | 26 +++---------------- .../MarkdownScreenshotBuilderTest.php | 20 -------------- 2 files changed, 3 insertions(+), 43 deletions(-) diff --git a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php index b7d9b9db..b0d15256 100644 --- a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php +++ b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php @@ -48,7 +48,7 @@ public function testFileWithContentFile(): void ; $this->assertGotenbergEndpoint('/forms/chromium/convert/markdown'); - $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR . '/assets/file.md'); } public function testFileWithContent(): void @@ -73,7 +73,7 @@ public function load(string $class): object|null ; $this->assertGotenbergEndpoint('/forms/chromium/convert/markdown'); - $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR . '/assets/file.md'); } public function testWithStringableObject(): void @@ -92,7 +92,7 @@ public function __toString(): string ; $this->assertGotenbergEndpoint('/forms/chromium/convert/markdown'); - $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR . '/assets/file.md'); } public function testRequiredFileContent(): void @@ -126,24 +126,4 @@ public function testFilesExtensionRequirement(): void ->generate() ; } - - public function testToWrapWithContent(): void - { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Use wrapper() instead of content().'); - - $this->getBuilder() - ->content('templates/wrapper.html.twig', ['name' => 'John Doe']) - ; - } - - public function testToWrapWithContentFile(): void - { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Use wrapperFile() instead of contentFile().'); - - $this->getBuilder() - ->contentFile('files/wrapper.html') - ; - } } diff --git a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php index ab2c9c9e..15ad65ca 100644 --- a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php @@ -142,24 +142,4 @@ public function testFilesExtensionRequirement(): void ->generate() ; } - - public function testToWrapWithContent(): void - { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Use wrapper() instead of content().'); - - $this->getBuilder() - ->content('templates/wrapper.html.twig', ['name' => 'John Doe']) - ; - } - - public function testToWrapWithContentFile(): void - { - $this->expectException(\BadMethodCallException::class); - $this->expectExceptionMessage('Use wrapperFile() instead of contentFile().'); - - $this->getBuilder() - ->contentFile('files/wrapper.html') - ; - } } From e97e123270d6b02cd28824677bdea37a62833adf Mon Sep 17 00:00:00 2001 From: "hubert.lenoir" Date: Tue, 15 Apr 2025 11:37:58 +0200 Subject: [PATCH 24/30] fix: tests --- src/Builder/Pdf/MarkdownPdfBuilder.php | 26 ++++++++++++++++--- .../Screenshot/MarkdownScreenshotBuilder.php | 23 ++++++++++++++-- tests/Builder/Pdf/MarkdownPdfBuilderTest.php | 6 ++--- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/Builder/Pdf/MarkdownPdfBuilder.php b/src/Builder/Pdf/MarkdownPdfBuilder.php index 87692aad..9080bd9b 100644 --- a/src/Builder/Pdf/MarkdownPdfBuilder.php +++ b/src/Builder/Pdf/MarkdownPdfBuilder.php @@ -11,22 +11,42 @@ use Sensiolabs\GotenbergBundle\Builder\Util\ValidatorFactory; use Sensiolabs\GotenbergBundle\Enumeration\Part; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; +use Sensiolabs\GotenbergBundle\Exception\PdfPartRenderingException; /** - * @see https://gotenberg.dev/docs/routes#merge-pdfs-route + * @see https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route */ #[SemanticNode(type: 'pdf', name: 'markdown')] final class MarkdownPdfBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumPdfTrait { - content as wrapper; - contentFile as wrapperFile; content as private; contentFile as private; } public const ENDPOINT = '/forms/chromium/convert/markdown'; + /** + * The template that wraps the markdown content. + * + * @param string $template #Template + * @param array $context + * + * @throws PdfPartRenderingException if the template could not be rendered + */ + public function wrapper(string $template, array $context = []): self + { + return $this->content($template, $context); + } + + /** + * The HTML file that wraps the markdown content. + */ + public function wrapperFile(string $path): self + { + return $this->contentFile($path); + } + /** * Add Markdown into a PDF. * diff --git a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php index be9cc088..1116ea58 100644 --- a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php +++ b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php @@ -11,22 +11,41 @@ use Sensiolabs\GotenbergBundle\Builder\Util\ValidatorFactory; use Sensiolabs\GotenbergBundle\Enumeration\Part; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; +use Sensiolabs\GotenbergBundle\Exception\PdfPartRenderingException; /** * @see https://gotenberg.dev/docs/routes#screenshots-route + * @see https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route */ #[SemanticNode(type: 'screenshot', name: 'markdown')] final class MarkdownScreenshotBuilder extends AbstractBuilder implements BuilderAssetInterface { use ChromiumScreenshotTrait { - content as wrapper; - contentFile as wrapperFile; content as private; contentFile as private; } public const ENDPOINT = '/forms/chromium/screenshot/markdown'; + /** + * @param string $template #Template + * @param array $context + * + * @throws PdfPartRenderingException if the template could not be rendered + */ + public function wrapper(string $template, array $context = []): self + { + return $this->content($template, $context); + } + + /** + * The HTML file to convert into PDF. + */ + public function wrapperFile(string $path): self + { + return $this->contentFile($path); + } + /** * Add Markdown into a PDF. * diff --git a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php index b0d15256..880333db 100644 --- a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php +++ b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php @@ -48,7 +48,7 @@ public function testFileWithContentFile(): void ; $this->assertGotenbergEndpoint('/forms/chromium/convert/markdown'); - $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR . '/assets/file.md'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); } public function testFileWithContent(): void @@ -73,7 +73,7 @@ public function load(string $class): object|null ; $this->assertGotenbergEndpoint('/forms/chromium/convert/markdown'); - $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR . '/assets/file.md'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); } public function testWithStringableObject(): void @@ -92,7 +92,7 @@ public function __toString(): string ; $this->assertGotenbergEndpoint('/forms/chromium/convert/markdown'); - $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR . '/assets/file.md'); + $this->assertGotenbergFormDataFile('files', 'text/markdown', self::FIXTURE_DIR.'/assets/file.md'); } public function testRequiredFileContent(): void From a3516343f0b8da6b5db91fce30312c0c00a7bb1b Mon Sep 17 00:00:00 2001 From: "hubert.lenoir" Date: Tue, 15 Apr 2025 11:43:37 +0200 Subject: [PATCH 25/30] fix: doc --- docs/pdf/builders_api/MarkdownPdfBuilder.md | 6 ++++-- docs/screenshot/builders_api/MarkdownScreenshotBuilder.md | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/pdf/builders_api/MarkdownPdfBuilder.md b/docs/pdf/builders_api/MarkdownPdfBuilder.md index 53f67d76..1efdd88c 100644 --- a/docs/pdf/builders_api/MarkdownPdfBuilder.md +++ b/docs/pdf/builders_api/MarkdownPdfBuilder.md @@ -1,7 +1,7 @@ # MarkdownPdfBuilder > [!TIP] -> See: [https://gotenberg.dev/docs/routes#merge-pdfs-route](https://gotenberg.dev/docs/routes#merge-pdfs-route) +> See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) ### addMetadata(string $key, string $value) The metadata to write. @@ -44,8 +44,10 @@ Either the intervals or the page ranges to extract, depending on the selected mo Specify whether to put extracted pages into a single file or as many files as there are page ranges. Only works with pages mode. (default false). ### wrapper(string $template, array $context) +The template that wraps the markdown content.
+ ### wrapperFile(string $path) -The HTML file to convert into PDF. +The HTML file that wraps the markdown content. ### addAsset(Stringable|string $path) Adds a file, like an image, font, stylesheet, and so on. diff --git a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md index 530335b3..980ac60e 100644 --- a/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md +++ b/docs/screenshot/builders_api/MarkdownScreenshotBuilder.md @@ -1,7 +1,8 @@ # MarkdownScreenshotBuilder > [!TIP] -> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route) +> See: [https://gotenberg.dev/docs/routes#screenshots-route](https://gotenberg.dev/docs/routes#screenshots-route)
+> See: [https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route](https://gotenberg.dev/docs/routes#markdown-files-into-pdf-route) ### downloadFrom(array $downloadFrom) Sets download from to download each entry (file) in parallel (URLs MUST return a Content-Disposition header with a filename parameter.).
From 9f7e799487667cf8056c66a150040681dc2136aa Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Wed, 16 Apr 2025 11:36:37 +0200 Subject: [PATCH 26/30] Fix compsoer dependency analyser --- composer-dependency-analyser.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php index 4c7fe6a0..398ca0ec 100644 --- a/composer-dependency-analyser.php +++ b/composer-dependency-analyser.php @@ -17,7 +17,9 @@ ->ignoreErrorsOnPackage('async-aws/s3', [ ErrorType::DEV_DEPENDENCY_IN_PROD, ]) - ->disableExtensionsAnalysis() // TODO : Bug waiting for https://github.com/shipmonk-rnd/composer-dependency-analyser/issues/217 + ->ignoreErrorsOnExtension('ext-mbstring', [ + ErrorType::DEV_DEPENDENCY_IN_PROD, + ]) ->ignoreErrorsOnPackage('league/flysystem', [ ErrorType::DEV_DEPENDENCY_IN_PROD, ]) From 9f41d41ea08c9755f7e86da85f363a2fabd1d0f9 Mon Sep 17 00:00:00 2001 From: Steven Renaux Date: Mon, 14 Apr 2025 17:41:01 +0200 Subject: [PATCH 27/30] Add Service Subscriber Trait --- config/builder.php | 11 -------- docs/generate.php | 4 +-- phpstan.dist.neon | 4 --- src/Builder/AbstractBuilder.php | 26 ++++++++++++------- .../AssetBaseDirFormatterAwareTrait.php | 7 +++-- .../Dependencies/DependencyAwareTrait.php | 10 ------- .../Dependencies/LoggerAwareTrait.php | 9 ++++--- .../Dependencies/RequestAwareTrait.php | 9 ++++--- .../Behaviors/Dependencies/TwigAwareTrait.php | 9 ++++--- .../Dependencies/UrlGeneratorAwareTrait.php | 10 ++++--- ...WebhookConfigurationRegistryAwareTrait.php | 7 +++-- src/Builder/Pdf/HtmlPdfBuilder.php | 1 + .../CompilerPass/GotenbergPass.php | 3 +++ .../SensiolabsGotenbergExtension.php | 3 +++ tests/Builder/Behaviors/BehaviorTrait.php | 4 +-- .../Chromium/CookieTestCaseTrait.php | 10 +++---- .../Behaviors/WebhookTestCaseTrait.php | 8 +++--- tests/Builder/GotenbergBuilderTestCase.php | 21 +++++++++------ tests/Builder/Pdf/ConvertPdfBuilderTest.php | 4 +-- tests/Builder/Pdf/FlattenPdfBuilderTest.php | 4 +-- tests/Builder/Pdf/HtmlPdfBuilderTest.php | 22 ++++++++-------- .../Builder/Pdf/LibreOfficePdfBuilderTest.php | 4 +-- tests/Builder/Pdf/MarkdownPdfBuilderTest.php | 6 ++--- tests/Builder/Pdf/MergePdfBuilderTest.php | 4 +-- tests/Builder/Pdf/SplitPdfBuilderTest.php | 4 +-- tests/Builder/Pdf/UrlPdfBuilderTest.php | 14 +++++----- .../Screenshot/HtmlScreenshotBuilderTest.php | 8 +++--- .../MarkdownScreenshotBuilderTest.php | 8 +++--- .../Screenshot/UrlScreenshotBuilderTest.php | 12 ++++----- 29 files changed, 130 insertions(+), 116 deletions(-) delete mode 100644 src/Builder/Behaviors/Dependencies/DependencyAwareTrait.php diff --git a/config/builder.php b/config/builder.php index 17d39405..898e82ad 100644 --- a/config/builder.php +++ b/config/builder.php @@ -16,17 +16,6 @@ $services->set('.sensiolabs_gotenberg.abstract_builder', AbstractBuilder::class) ->abstract() - ->args([ - service('sensiolabs_gotenberg.client'), - service_locator([ - 'asset_base_dir_formatter' => service('.sensiolabs_gotenberg.asset.base_dir_formatter'), - 'webhook_configuration_registry' => service('.sensiolabs_gotenberg.webhook_configuration_registry'), - 'logger' => service('logger')->nullOnInvalid(), - 'request_stack' => service('request_stack')->nullOnInvalid(), - 'router' => service('router.default')->nullOnInvalid(), - 'twig' => service('twig')->nullOnInvalid(), - ]), - ]) ; $services->set('sensiolabs_gotenberg.builder_configurator', BuilderConfigurator::class) diff --git a/docs/generate.php b/docs/generate.php index 364e1d81..fd7debce 100755 --- a/docs/generate.php +++ b/docs/generate.php @@ -94,14 +94,14 @@ class BuilderParser private const EXCLUDED_METHODS = [ '__construct', - 'setLogger', - 'setConfigurations', 'generate', 'generateAsync', 'fileName', 'processor', 'getBodyBag', 'getHeadersBag', + 'setContainer', + 'getSubscribedServices', ]; private string $name; diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 3acdfcf2..eebddb47 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -23,7 +23,3 @@ parameters: message: "#^ Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\ArrayNodeDefinition|Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\VariableNodeDefinition::append\\(\\)\\.$#" count: 1 path: src/NodeBuilder/ArrayNodeBuilder.php - - - message: '#Class Sensiolabs\\GotenbergBundle\\Builder\\Pdf|Screenshot\\.* has an uninitialized readonly property \$dependencies#' - count: 11 - path: src/Builder diff --git a/src/Builder/AbstractBuilder.php b/src/Builder/AbstractBuilder.php index 18dadb1e..2bbca99c 100644 --- a/src/Builder/AbstractBuilder.php +++ b/src/Builder/AbstractBuilder.php @@ -2,7 +2,6 @@ namespace Sensiolabs\GotenbergBundle\Builder; -use Psr\Container\ContainerInterface; use Sensiolabs\GotenbergBundle\Builder\Attributes\NormalizeGotenbergPayload; use Sensiolabs\GotenbergBundle\Builder\Result\GotenbergAsyncResult; use Sensiolabs\GotenbergBundle\Builder\Result\GotenbergFileResult; @@ -10,12 +9,17 @@ use Sensiolabs\GotenbergBundle\Processor\NullProcessor; use Sensiolabs\GotenbergBundle\Processor\ProcessorInterface; use Symfony\Component\HttpFoundation\HeaderUtils; +use Symfony\Contracts\Service\Attribute\SubscribedService; +use Symfony\Contracts\Service\ServiceSubscriberInterface; +use Symfony\Contracts\Service\ServiceSubscriberTrait; /** * Builder for responses. */ -abstract class AbstractBuilder implements BuilderAsyncInterface, BuilderFileInterface +abstract class AbstractBuilder implements BuilderAsyncInterface, BuilderFileInterface, ServiceSubscriberInterface { + use ServiceSubscriberTrait; + private readonly BodyBag $bodyBag; private readonly HeadersBag $headersBag; @@ -27,10 +31,8 @@ abstract class AbstractBuilder implements BuilderAsyncInterface, BuilderFileInte /** @var ProcessorInterface|null */ private ProcessorInterface|null $processor; - public function __construct( - protected readonly GotenbergClientInterface $client, - protected readonly ContainerInterface $dependencies, - ) { + public function __construct() + { $this->bodyBag = new BodyBag(); $this->headersBag = new HeadersBag(); @@ -68,7 +70,7 @@ public function generate(): GotenbergFileResult $this->validatePayloadBody(); $payloadBody = iterator_to_array($this->normalizePayloadBody()); - $response = $this->client->call( + $response = $this->getClient()->call( $this->getEndpoint(), new Payload( $payloadBody, @@ -78,7 +80,7 @@ public function generate(): GotenbergFileResult return new GotenbergFileResult( $response, - $this->client->stream($response), + $this->getClient()->stream($response), $this->processor ?? new NullProcessor(), $this->headerDisposition, ); @@ -89,7 +91,7 @@ public function generateAsync(): GotenbergAsyncResult $this->validatePayloadBody(); $payloadBody = iterator_to_array($this->normalizePayloadBody()); - $response = $this->client->call( + $response = $this->getClient()->call( $this->getEndpoint(), new Payload( $payloadBody, @@ -116,6 +118,12 @@ protected function validatePayloadBody(): void { } + #[SubscribedService('sensiolabs_gotenberg.client')] + protected function getClient(): GotenbergClientInterface + { + return $this->container->get('sensiolabs_gotenberg.client'); + } + private function normalizePayloadBody(): \Generator { foreach (array_reverse($this->reflection->getMethods()) as $method) { diff --git a/src/Builder/Behaviors/Dependencies/AssetBaseDirFormatterAwareTrait.php b/src/Builder/Behaviors/Dependencies/AssetBaseDirFormatterAwareTrait.php index da03957f..2e01daa2 100644 --- a/src/Builder/Behaviors/Dependencies/AssetBaseDirFormatterAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/AssetBaseDirFormatterAwareTrait.php @@ -3,13 +3,16 @@ namespace Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; +use Symfony\Contracts\Service\Attribute\SubscribedService; +use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; trait AssetBaseDirFormatterAwareTrait { - use DependencyAwareTrait; + use ServiceMethodsSubscriberTrait; + #[SubscribedService('asset_base_dir_formatter')] protected function getAssetBaseDirFormatter(): AssetBaseDirFormatter { - return $this->dependencies->get('asset_base_dir_formatter'); + return $this->container->get('asset_base_dir_formatter'); } } diff --git a/src/Builder/Behaviors/Dependencies/DependencyAwareTrait.php b/src/Builder/Behaviors/Dependencies/DependencyAwareTrait.php deleted file mode 100644 index 6a37e696..00000000 --- a/src/Builder/Behaviors/Dependencies/DependencyAwareTrait.php +++ /dev/null @@ -1,10 +0,0 @@ -dependencies->has('logger') - || !($logger = $this->dependencies->get('logger')) instanceof LoggerInterface) { + !$this->container->has('logger') + || !($logger = $this->container->get('logger')) instanceof LoggerInterface) { return null; } diff --git a/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php b/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php index 55187456..c5975e01 100644 --- a/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php @@ -4,16 +4,19 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Contracts\Service\Attribute\SubscribedService; +use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; trait RequestAwareTrait { - use DependencyAwareTrait; + use ServiceMethodsSubscriberTrait; + #[SubscribedService('request_stack', nullable: true)] protected function getCurrentRequest(): Request|null { if ( - !$this->dependencies->has('request_stack') - || !($requestStack = $this->dependencies->get('request_stack')) instanceof RequestStack + !$this->container->has('request_stack') + || !($requestStack = $this->container->get('request_stack')) instanceof RequestStack ) { throw new \LogicException(\sprintf('RequestStack is required to use "%s" method. Try to run "composer require symfony/http-foundation".', __METHOD__)); } diff --git a/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php b/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php index ef3e6b6d..c21fa0b1 100644 --- a/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php @@ -2,17 +2,20 @@ namespace Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies; +use Symfony\Contracts\Service\Attribute\SubscribedService; +use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; use Twig\Environment; trait TwigAwareTrait { - use DependencyAwareTrait; + use ServiceMethodsSubscriberTrait; + #[SubscribedService('twig', nullable: true)] protected function getTwig(): Environment { if ( - !$this->dependencies->has('twig') - || !($environment = $this->dependencies->get('twig')) instanceof Environment + !$this->container->has('twig') + || !($environment = $this->container->get('twig')) instanceof Environment ) { throw new \LogicException(\sprintf('Twig is required to use "%s" method. Try to run "composer require symfony/twig-bundle".', __METHOD__)); } diff --git a/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php b/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php index 6fa09d9e..3e09dcd3 100644 --- a/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php @@ -2,17 +2,21 @@ namespace Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Contracts\Service\Attribute\SubscribedService; +use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; trait UrlGeneratorAwareTrait { - use DependencyAwareTrait; + use ServiceMethodsSubscriberTrait; + #[SubscribedService('router', nullable: true)] protected function getUrlGenerator(): UrlGeneratorInterface { if ( - !$this->dependencies->has('router') - || !($urlGenerator = $this->dependencies->get('router')) instanceof UrlGeneratorInterface + !$this->container->has('router') + || !($urlGenerator = $this->container->get('router')) instanceof UrlGeneratorInterface ) { throw new \LogicException(\sprintf('UrlGenerator is required to use "%s" method. Try to run "composer require symfony/routing".', __METHOD__)); } diff --git a/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php b/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php index fdd530e9..9dc777d9 100644 --- a/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php @@ -3,13 +3,16 @@ namespace Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies; use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistryInterface; +use Symfony\Contracts\Service\Attribute\SubscribedService; +use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; trait WebhookConfigurationRegistryAwareTrait { - use DependencyAwareTrait; + use ServiceMethodsSubscriberTrait; + #[SubscribedService('webhook_configuration_registry')] protected function getWebhookConfigurationRegistry(): WebhookConfigurationRegistryInterface { - return $this->dependencies->get('webhook_configuration_registry'); + return $this->container->get('webhook_configuration_registry'); } } diff --git a/src/Builder/Pdf/HtmlPdfBuilder.php b/src/Builder/Pdf/HtmlPdfBuilder.php index 502e0f9c..bf0a780b 100644 --- a/src/Builder/Pdf/HtmlPdfBuilder.php +++ b/src/Builder/Pdf/HtmlPdfBuilder.php @@ -8,6 +8,7 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; use Sensiolabs\GotenbergBundle\Enumeration\Part; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; +use Symfony\Contracts\Service\ServiceSubscriberInterface; /** * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route diff --git a/src/DependencyInjection/CompilerPass/GotenbergPass.php b/src/DependencyInjection/CompilerPass/GotenbergPass.php index cfa8759b..2132dcc3 100644 --- a/src/DependencyInjection/CompilerPass/GotenbergPass.php +++ b/src/DependencyInjection/CompilerPass/GotenbergPass.php @@ -24,6 +24,7 @@ public function process(ContainerBuilder $container): void $serviceDefinition = $container->getDefinition($serviceId); $serviceDefinition ->setShared(false) + ->addTag('container.service_subscriber') ; $class = $serviceDefinition->getClass(); @@ -32,6 +33,8 @@ public function process(ContainerBuilder $container): void $builderPerType[$type] ??= []; $builderPerType[$type][] = new Reference($serviceId); + + $serviceDefinition->setAutowired(true); } if ($container->hasDefinition('sensiolabs_gotenberg.pdf')) { diff --git a/src/DependencyInjection/SensiolabsGotenbergExtension.php b/src/DependencyInjection/SensiolabsGotenbergExtension.php index 8aa90fe2..c8e5b20c 100644 --- a/src/DependencyInjection/SensiolabsGotenbergExtension.php +++ b/src/DependencyInjection/SensiolabsGotenbergExtension.php @@ -2,6 +2,7 @@ namespace Sensiolabs\GotenbergBundle\DependencyInjection; +use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; use Sensiolabs\GotenbergBundle\Builder\Behaviors\WebhookTrait; use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Symfony\Component\Config\FileLocator; @@ -118,6 +119,8 @@ public function load(array $configs, ContainerBuilder $container): void ->addTag('sensiolabs_gotenberg.builder') ; + $container->registerForAutoconfiguration(AbstractBuilder::class); + // Configurators $configValueMapping = []; foreach ($defaultConfiguration['default_options'] as $type => $buildersOptions) { diff --git a/tests/Builder/Behaviors/BehaviorTrait.php b/tests/Builder/Behaviors/BehaviorTrait.php index 2e684b18..4385b9d6 100644 --- a/tests/Builder/Behaviors/BehaviorTrait.php +++ b/tests/Builder/Behaviors/BehaviorTrait.php @@ -15,7 +15,7 @@ */ trait BehaviorTrait { - protected Container $dependencies; + protected Container $container; /** * @return T @@ -36,6 +36,6 @@ protected function getDefaultBuilder(): BuilderInterface { $builder = $this->getBuilder(); - return $this->initializeBuilder($builder, $this->dependencies); + return $this->initializeBuilder($builder, $this->container); } } diff --git a/tests/Builder/Behaviors/Chromium/CookieTestCaseTrait.php b/tests/Builder/Behaviors/Chromium/CookieTestCaseTrait.php index 5f6851f9..0e297d35 100644 --- a/tests/Builder/Behaviors/Chromium/CookieTestCaseTrait.php +++ b/tests/Builder/Behaviors/Chromium/CookieTestCaseTrait.php @@ -126,7 +126,7 @@ public function testToAddMultipleTimeTheSameCookie(): void public function testToForwardCookiesWithNoCurrentRequest(): void { - $this->dependencies->set('request_stack', new RequestStack()); + $this->container->set('request_stack', new RequestStack()); $builder = $this->getDefaultBuilder() ->forwardCookie('my_cookie') @@ -141,8 +141,8 @@ public function testToForwardCookiesWithCurrentRequest(): void $request->setMethod('GET'); $request->cookies->set('my_cookie', new Cookie('my_cookie', 'value', domain: 'symfony.com')); - $this->dependencies->set('request_stack', new RequestStack([$request])); - $this->dependencies->set('logger', $this->getMockBuilder(LoggerInterface::class)); + $this->container->set('request_stack', new RequestStack([$request])); + $this->container->set('logger', $this->getMockBuilder(LoggerInterface::class)); $builder = $this->getDefaultBuilder() ->forwardCookie('my_cookie') @@ -156,8 +156,8 @@ public function testToForwardCookiesWithCurrentRequestWithoutCookies(): void $request = new Request(); $request->setMethod('GET'); - $this->dependencies->set('request_stack', new RequestStack([$request])); - $this->dependencies->set('logger', $this->getMockBuilder(LoggerInterface::class)); + $this->container->set('request_stack', new RequestStack([$request])); + $this->container->set('logger', $this->getMockBuilder(LoggerInterface::class)); $builder = $this->getDefaultBuilder() ->forwardCookie('my_cookie') diff --git a/tests/Builder/Behaviors/WebhookTestCaseTrait.php b/tests/Builder/Behaviors/WebhookTestCaseTrait.php index 0f71312b..663677af 100644 --- a/tests/Builder/Behaviors/WebhookTestCaseTrait.php +++ b/tests/Builder/Behaviors/WebhookTestCaseTrait.php @@ -23,7 +23,7 @@ abstract protected function assertGotenbergHeader(string $name, mixed $value): v public function testAddFullWebhookConfiguration(): void { - $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); + $this->container->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); $this->getDefaultBuilder() ->webhook([ @@ -58,7 +58,7 @@ public function testFullWebhookConfigurationWithRoute(): void ->willReturnOnConsecutiveCalls('http://example.com/success', 'http://example.com/error') ; - $this->dependencies->set('router', $router); + $this->container->set('router', $router); $this->getDefaultBuilder() ->webhook([ @@ -93,7 +93,7 @@ public function testFullWebhookConfigurationWithRouteParams(): void ->willReturnOnConsecutiveCalls('http://example.com/success', 'http://example.com/error') ; - $this->dependencies->set('router', $router); + $this->container->set('router', $router); $this->getDefaultBuilder() ->webhook([ @@ -301,7 +301,7 @@ public function get(string $name): array } }; - $this->dependencies->set('webhook_configuration_registry', $registry); + $this->container->set('webhook_configuration_registry', $registry); $this->getDefaultBuilder() ->webhookConfiguration('fake') diff --git a/tests/Builder/GotenbergBuilderTestCase.php b/tests/Builder/GotenbergBuilderTestCase.php index c38be58e..817c08ea 100644 --- a/tests/Builder/GotenbergBuilderTestCase.php +++ b/tests/Builder/GotenbergBuilderTestCase.php @@ -4,7 +4,6 @@ use PHPUnit\Framework\TestCase; use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\Filesystem\Path; @@ -20,7 +19,7 @@ abstract class GotenbergBuilderTestCase extends TestCase protected const FIXTURE_DIR = __DIR__.'/../Fixtures'; protected GotenbergClientAsserter $client; - protected Container $dependencies; + protected Container $container; /** @var T */ protected BuilderInterface $builder; @@ -29,27 +28,33 @@ protected function setUp(): void parent::setUp(); $this->client = new GotenbergClientAsserter(); - $this->dependencies = new Container(); + $this->container = new Container(); - $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(static::FIXTURE_DIR, static::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(static::FIXTURE_DIR, static::FIXTURE_DIR)); + $this->container->set('sensiolabs_gotenberg.client', $this->client); } /** * @return T */ - abstract protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): BuilderInterface; + abstract protected function createBuilder(): BuilderInterface; /** * @return T */ protected function getBuilder(): BuilderInterface { - return $this->builder ??= $this->createBuilder($this->client, $this->dependencies); + $builder = $this->createBuilder(); + if (method_exists($builder, 'setContainer')) { + $builder->setContainer($this->container); + } + + return $this->builder ??= $builder; } - protected function getDependencies(): Container + protected function getContainer(): Container { - return $this->dependencies; + return $this->container; } protected function assertGotenbergEndpoint(string $endpoint): void diff --git a/tests/Builder/Pdf/ConvertPdfBuilderTest.php b/tests/Builder/Pdf/ConvertPdfBuilderTest.php index ba67365b..c854464d 100644 --- a/tests/Builder/Pdf/ConvertPdfBuilderTest.php +++ b/tests/Builder/Pdf/ConvertPdfBuilderTest.php @@ -27,9 +27,9 @@ final class ConvertPdfBuilderTest extends GotenbergBuilderTestCase /** @use WebhookTestCaseTrait */ use WebhookTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): ConvertPdfBuilder + protected function createBuilder(): ConvertPdfBuilder { - return new ConvertPdfBuilder($client, $dependencies); + return new ConvertPdfBuilder(); } /** diff --git a/tests/Builder/Pdf/FlattenPdfBuilderTest.php b/tests/Builder/Pdf/FlattenPdfBuilderTest.php index 1c04dd91..db44eeea 100644 --- a/tests/Builder/Pdf/FlattenPdfBuilderTest.php +++ b/tests/Builder/Pdf/FlattenPdfBuilderTest.php @@ -23,9 +23,9 @@ final class FlattenPdfBuilderTest extends GotenbergBuilderTestCase /** @use WebhookTestCaseTrait */ use WebhookTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): FlattenPdfBuilder + protected function createBuilder(): FlattenPdfBuilder { - return new FlattenPdfBuilder($client, $dependencies); + return new FlattenPdfBuilder(); } /** diff --git a/tests/Builder/Pdf/HtmlPdfBuilderTest.php b/tests/Builder/Pdf/HtmlPdfBuilderTest.php index 4cdbac2e..0c9cab05 100644 --- a/tests/Builder/Pdf/HtmlPdfBuilderTest.php +++ b/tests/Builder/Pdf/HtmlPdfBuilderTest.php @@ -24,9 +24,9 @@ final class HtmlPdfBuilderTest extends GotenbergBuilderTestCase /** @use ChromiumPdfTestCaseTrait */ use ChromiumPdfTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): HtmlPdfBuilder + protected function createBuilder(): HtmlPdfBuilder { - return new HtmlPdfBuilder($client, $dependencies); + return new HtmlPdfBuilder(); } /** @@ -51,7 +51,7 @@ public function testRequiredFormData(): void public function testOutputFilename(): void { - $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); $this->getBuilder() ->contentFile('files/content.html') @@ -65,7 +65,7 @@ public function testOutputFilename(): void public function testWidth(): void { - $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); $this->getBuilder() ->contentFile('files/content.html') @@ -84,7 +84,7 @@ public function testWidth(): void public function testWithTwigContentFile(): void { - $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ 'strict_variables' => true, @@ -97,7 +97,7 @@ public function load(string $class): object|null } }); - $this->dependencies->set('twig', $twig); + $this->container->set('twig', $twig); $this->getBuilder() ->content('templates/content.html.twig', ['name' => 'world']) @@ -124,7 +124,7 @@ public function load(string $class): object|null public function testWithTwigAndHeaderFooterParts(): void { - $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ 'strict_variables' => true, @@ -137,7 +137,7 @@ public function load(string $class): object|null } }); - $this->dependencies->set('twig', $twig); + $this->container->set('twig', $twig); $this->getBuilder() ->header('templates/header.html.twig', ['name' => 'header']) @@ -196,7 +196,7 @@ public function load(string $class): object|null public function testFilesAsHeaderAndFooter(): void { - $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); $this->getBuilder() ->headerFile('files/header.html') @@ -219,7 +219,7 @@ public function testWithInvalidTwigTemplate(): void $this->expectException(PdfPartRenderingException::class); $this->expectExceptionMessage('Could not render template "templates/invalid.html.twig" into PDF part "index.html". Unexpected character "!".'); - $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); $twig = new Environment(new FilesystemLoader(self::FIXTURE_DIR), [ 'strict_variables' => true, @@ -232,7 +232,7 @@ public function load(string $class): object|null } }); - $this->dependencies->set('twig', $twig); + $this->container->set('twig', $twig); $this->getBuilder() ->content('templates/invalid.html.twig', ['name' => 'world']) diff --git a/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php b/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php index 99e8ba4b..a8cf8beb 100644 --- a/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php +++ b/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php @@ -21,9 +21,9 @@ class LibreOfficePdfBuilderTest extends GotenbergBuilderTestCase /** @use LibreOfficeTestCaseTrait */ use LibreOfficeTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): LibreOfficePdfBuilder + protected function createBuilder(): LibreOfficePdfBuilder { - return new LibreOfficePdfBuilder($client, $dependencies); + return new LibreOfficePdfBuilder(); } /** diff --git a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php index 880333db..e2146f89 100644 --- a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php +++ b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php @@ -23,9 +23,9 @@ final class MarkdownPdfBuilderTest extends GotenbergBuilderTestCase /** @use ChromiumPdfTestCaseTrait */ use ChromiumPdfTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): MarkdownPdfBuilder + protected function createBuilder(): MarkdownPdfBuilder { - return new MarkdownPdfBuilder($client, $dependencies); + return new MarkdownPdfBuilder(); } /** @@ -64,7 +64,7 @@ public function load(string $class): object|null } }); - $this->dependencies->set('twig', $twig); + $this->container->set('twig', $twig); $this->getBuilder() ->files('assets/file.md') diff --git a/tests/Builder/Pdf/MergePdfBuilderTest.php b/tests/Builder/Pdf/MergePdfBuilderTest.php index c72c15f3..f61ac55f 100644 --- a/tests/Builder/Pdf/MergePdfBuilderTest.php +++ b/tests/Builder/Pdf/MergePdfBuilderTest.php @@ -35,9 +35,9 @@ final class MergePdfBuilderTest extends GotenbergBuilderTestCase /** @use WebhookTestCaseTrait */ use WebhookTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): MergePdfBuilder + protected function createBuilder(): MergePdfBuilder { - return new MergePdfBuilder($client, $dependencies); + return new MergePdfBuilder(); } /** diff --git a/tests/Builder/Pdf/SplitPdfBuilderTest.php b/tests/Builder/Pdf/SplitPdfBuilderTest.php index 27c588e0..48860e76 100644 --- a/tests/Builder/Pdf/SplitPdfBuilderTest.php +++ b/tests/Builder/Pdf/SplitPdfBuilderTest.php @@ -40,9 +40,9 @@ final class SplitPdfBuilderTest extends GotenbergBuilderTestCase /** @use WebhookTestCaseTrait */ use WebhookTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): SplitPdfBuilder + protected function createBuilder(): SplitPdfBuilder { - return new SplitPdfBuilder($client, $dependencies); + return new SplitPdfBuilder(); } /** diff --git a/tests/Builder/Pdf/UrlPdfBuilderTest.php b/tests/Builder/Pdf/UrlPdfBuilderTest.php index d36f3b50..dc99bfbe 100644 --- a/tests/Builder/Pdf/UrlPdfBuilderTest.php +++ b/tests/Builder/Pdf/UrlPdfBuilderTest.php @@ -23,9 +23,9 @@ final class UrlPdfBuilderTest extends GotenbergBuilderTestCase /** @use ChromiumPdfTestCaseTrait */ use ChromiumPdfTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): UrlPdfBuilder + protected function createBuilder(): UrlPdfBuilder { - return new UrlPdfBuilder($client, $dependencies); + return new UrlPdfBuilder(); } /** @@ -33,8 +33,8 @@ protected function createBuilder(GotenbergClientInterface $client, Container $de */ protected function initializeBuilder(BuilderInterface $builder, Container $container): UrlPdfBuilder { - if (!$this->dependencies->has('router')) { - $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); + if (!$this->container->has('router')) { + $this->container->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); } return $builder @@ -54,7 +54,7 @@ public function testRequiredFormData(): void public function testOutputFilename(): void { - $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); + $this->container->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); $this->getBuilder() ->url('https://example.com') @@ -73,7 +73,7 @@ public function testToGenerateWithRequestContext(): void $routeCollection->add('article_read', new Route('/article/{id}', methods: Request::METHOD_GET)); $requestContext = new RequestContext(); - $this->dependencies->set('router', new UrlGenerator($routeCollection, $requestContext)); + $this->container->set('router', new UrlGenerator($routeCollection, $requestContext)); $requestContext->setHost('example'); @@ -94,7 +94,7 @@ public function testPdfGenerationFromAGivenRoute(): void $routeCollection = new RouteCollection(); $routeCollection->add('article_read', new Route('/article/{id}', methods: Request::METHOD_GET)); - $this->dependencies->set('router', new UrlGenerator($routeCollection, new RequestContext())); + $this->container->set('router', new UrlGenerator($routeCollection, new RequestContext())); $this->getBuilder() ->route('article_read', ['id' => 1]) diff --git a/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php b/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php index 41e4c7c1..8a91b625 100644 --- a/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php @@ -23,9 +23,9 @@ final class HtmlScreenshotBuilderTest extends GotenbergBuilderTestCase /** @use ChromiumScreenshotTestCaseTrait */ use ChromiumScreenshotTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): HtmlScreenshotBuilder + protected function createBuilder(): HtmlScreenshotBuilder { - return new HtmlScreenshotBuilder($client, $dependencies); + return new HtmlScreenshotBuilder(); } /** @@ -40,7 +40,7 @@ protected function initializeBuilder(BuilderInterface $builder, Container $conta public function testOutputFilename(): void { - $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); $this->getBuilder() ->contentFile('files/content.html') @@ -65,7 +65,7 @@ public function load(string $class): object|null } }); - $this->dependencies->set('twig', $twig); + $this->container->set('twig', $twig); $this->getBuilder() ->content('templates/content.html.twig', ['name' => 'world']) diff --git a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php index 15ad65ca..6dcd9b64 100644 --- a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php @@ -24,9 +24,9 @@ final class MarkdownScreenshotBuilderTest extends GotenbergBuilderTestCase /** @use ChromiumScreenshotTestCaseTrait */ use ChromiumScreenshotTestCaseTrait; - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): MarkdownScreenshotBuilder + protected function createBuilder(): MarkdownScreenshotBuilder { - return new MarkdownScreenshotBuilder($client, $dependencies); + return new MarkdownScreenshotBuilder(); } /** @@ -42,7 +42,7 @@ protected function initializeBuilder(BuilderInterface $builder, Container $conta public function testOutputFilename(): void { - $this->dependencies->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); + $this->container->set('asset_base_dir_formatter', new AssetBaseDirFormatter(self::FIXTURE_DIR, self::FIXTURE_DIR)); $this->getBuilder() ->wrapperFile('files/content.html') @@ -80,7 +80,7 @@ public function load(string $class): object|null } }); - $this->dependencies->set('twig', $twig); + $this->container->set('twig', $twig); $this->getBuilder() ->files('assets/file.md') diff --git a/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php b/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php index 23869712..16c33f70 100644 --- a/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php @@ -27,12 +27,12 @@ protected function setUp(): void { parent::setUp(); - $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); + $this->container->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); } - protected function createBuilder(GotenbergClientInterface $client, Container $dependencies): UrlScreenshotBuilder + protected function createBuilder(): UrlScreenshotBuilder { - return new UrlScreenshotBuilder($client, $dependencies); + return new UrlScreenshotBuilder(); } /** @@ -57,7 +57,7 @@ public function testRequiredFormData(): void public function testOutputFilename(): void { - $this->dependencies->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); + $this->container->set('router', new UrlGenerator(new RouteCollection(), new RequestContext())); $this->getBuilder() ->url('https://example.com') @@ -75,7 +75,7 @@ public function testPdfGenerationFromAGivenRoute(): void $routeCollection = new RouteCollection(); $routeCollection->add('article_read', new Route('/article/{id}', methods: Request::METHOD_GET)); - $this->dependencies->set('router', new UrlGenerator($routeCollection, new RequestContext())); + $this->container->set('router', new UrlGenerator($routeCollection, new RequestContext())); $this->getBuilder() ->route('article_read', ['id' => 1]) @@ -94,7 +94,7 @@ public function testToGenerateWithRequestContext(): void $routeCollection->add('article_read', new Route('/article/{id}', methods: Request::METHOD_GET)); $requestContext = new RequestContext(); - $this->dependencies->set('router', new UrlGenerator($routeCollection, new RequestContext())); + $this->container->set('router', new UrlGenerator($routeCollection, new RequestContext())); $requestContext->setHost('example'); From a9b00e2bc8e0adb7d445700422e897b2a8355f44 Mon Sep 17 00:00:00 2001 From: Steven Renaux Date: Wed, 23 Apr 2025 15:05:11 +0200 Subject: [PATCH 28/30] Fix README for fonts --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 53e5a71f..e29393d8 100644 --- a/README.md +++ b/README.md @@ -221,9 +221,10 @@ class YourController 1. [Configuration](./docs/configuration.md) 2. [Processing (saving for example)](./docs/processing.md) -2. [Working with assets](./docs/assets.md) -3. [Builders API](./docs/builders_api.md) -4. [Async & Webhooks](./docs/webhook.md) +3. [Working with assets](./docs/assets.md) +4. [Builders API](./docs/builders_api.md) +5. [Async & Webhooks](./docs/webhook.md) +6. [Working with fonts](./docs/fonts.md) #### PDF From c8c97375b3a5b79b77fdb7d2e8d5ac61cb336d48 Mon Sep 17 00:00:00 2001 From: Adrien Roches Date: Thu, 24 Apr 2025 12:13:13 +0200 Subject: [PATCH 29/30] Remove autowire & hack symfony --- config/builder.php | 2 -- src/Builder/AbstractBuilder.php | 3 +++ .../AssetBaseDirFormatterAwareTrait.php | 4 +-- .../Dependencies/LoggerAwareTrait.php | 4 +-- .../Dependencies/RequestAwareTrait.php | 4 +-- .../Behaviors/Dependencies/TwigAwareTrait.php | 9 ++++--- .../Dependencies/UrlGeneratorAwareTrait.php | 10 ++++--- ...WebhookConfigurationRegistryAwareTrait.php | 4 +-- src/Builder/Pdf/HtmlPdfBuilder.php | 1 - .../CompilerPass/GotenbergPass.php | 27 ++++++++++++++++++- tests/Builder/Pdf/ConvertPdfBuilderTest.php | 1 - tests/Builder/Pdf/FlattenPdfBuilderTest.php | 1 - tests/Builder/Pdf/HtmlPdfBuilderTest.php | 1 - .../Builder/Pdf/LibreOfficePdfBuilderTest.php | 1 - tests/Builder/Pdf/MarkdownPdfBuilderTest.php | 1 - tests/Builder/Pdf/MergePdfBuilderTest.php | 1 - tests/Builder/Pdf/SplitPdfBuilderTest.php | 1 - tests/Builder/Pdf/UrlPdfBuilderTest.php | 1 - .../Screenshot/HtmlScreenshotBuilderTest.php | 1 - .../MarkdownScreenshotBuilderTest.php | 1 - .../Screenshot/UrlScreenshotBuilderTest.php | 1 - 21 files changed, 49 insertions(+), 30 deletions(-) diff --git a/config/builder.php b/config/builder.php index 898e82ad..0ff85709 100644 --- a/config/builder.php +++ b/config/builder.php @@ -4,8 +4,6 @@ use Sensiolabs\GotenbergBundle\Configurator\BuilderConfigurator; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg; -use function Symfony\Component\DependencyInjection\Loader\Configurator\service; -use function Symfony\Component\DependencyInjection\Loader\Configurator\service_locator; return static function (ContainerConfigurator $container): void { $services = $container->services(); diff --git a/src/Builder/AbstractBuilder.php b/src/Builder/AbstractBuilder.php index 2bbca99c..4dd6623a 100644 --- a/src/Builder/AbstractBuilder.php +++ b/src/Builder/AbstractBuilder.php @@ -2,6 +2,7 @@ namespace Sensiolabs\GotenbergBundle\Builder; +use Psr\Container\ContainerInterface; use Sensiolabs\GotenbergBundle\Builder\Attributes\NormalizeGotenbergPayload; use Sensiolabs\GotenbergBundle\Builder\Result\GotenbergAsyncResult; use Sensiolabs\GotenbergBundle\Builder\Result\GotenbergFileResult; @@ -20,6 +21,8 @@ abstract class AbstractBuilder implements BuilderAsyncInterface, BuilderFileInte { use ServiceSubscriberTrait; + protected ContainerInterface $container; + private readonly BodyBag $bodyBag; private readonly HeadersBag $headersBag; diff --git a/src/Builder/Behaviors/Dependencies/AssetBaseDirFormatterAwareTrait.php b/src/Builder/Behaviors/Dependencies/AssetBaseDirFormatterAwareTrait.php index 2e01daa2..38dad8e6 100644 --- a/src/Builder/Behaviors/Dependencies/AssetBaseDirFormatterAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/AssetBaseDirFormatterAwareTrait.php @@ -4,11 +4,11 @@ use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; use Symfony\Contracts\Service\Attribute\SubscribedService; -use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; +use Symfony\Contracts\Service\ServiceSubscriberTrait; trait AssetBaseDirFormatterAwareTrait { - use ServiceMethodsSubscriberTrait; + use ServiceSubscriberTrait; #[SubscribedService('asset_base_dir_formatter')] protected function getAssetBaseDirFormatter(): AssetBaseDirFormatter diff --git a/src/Builder/Behaviors/Dependencies/LoggerAwareTrait.php b/src/Builder/Behaviors/Dependencies/LoggerAwareTrait.php index cb2e184e..cdad83ff 100644 --- a/src/Builder/Behaviors/Dependencies/LoggerAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/LoggerAwareTrait.php @@ -4,11 +4,11 @@ use Psr\Log\LoggerInterface; use Symfony\Contracts\Service\Attribute\SubscribedService; -use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; +use Symfony\Contracts\Service\ServiceSubscriberTrait; trait LoggerAwareTrait { - use ServiceMethodsSubscriberTrait; + use ServiceSubscriberTrait; #[SubscribedService('logger', nullable: true)] protected function getLogger(): LoggerInterface|null diff --git a/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php b/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php index c5975e01..a4230d50 100644 --- a/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/RequestAwareTrait.php @@ -5,11 +5,11 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Contracts\Service\Attribute\SubscribedService; -use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; +use Symfony\Contracts\Service\ServiceSubscriberTrait; trait RequestAwareTrait { - use ServiceMethodsSubscriberTrait; + use ServiceSubscriberTrait; #[SubscribedService('request_stack', nullable: true)] protected function getCurrentRequest(): Request|null diff --git a/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php b/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php index c21fa0b1..d5628dbb 100644 --- a/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/TwigAwareTrait.php @@ -3,15 +3,18 @@ namespace Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies; use Symfony\Contracts\Service\Attribute\SubscribedService; -use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; +use Symfony\Contracts\Service\ServiceSubscriberTrait; use Twig\Environment; +/** + * @method Environment getTwig() + */ trait TwigAwareTrait { - use ServiceMethodsSubscriberTrait; + use ServiceSubscriberTrait; #[SubscribedService('twig', nullable: true)] - protected function getTwig(): Environment + protected function getTwig(): Environment|null { if ( !$this->container->has('twig') diff --git a/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php b/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php index 3e09dcd3..ab48cff8 100644 --- a/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/UrlGeneratorAwareTrait.php @@ -2,17 +2,19 @@ namespace Sensiolabs\GotenbergBundle\Builder\Behaviors\Dependencies; -use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Contracts\Service\Attribute\SubscribedService; -use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; +use Symfony\Contracts\Service\ServiceSubscriberTrait; +/** + * @method UrlGeneratorInterface getUrlGenerator() + */ trait UrlGeneratorAwareTrait { - use ServiceMethodsSubscriberTrait; + use ServiceSubscriberTrait; #[SubscribedService('router', nullable: true)] - protected function getUrlGenerator(): UrlGeneratorInterface + protected function getUrlGenerator(): UrlGeneratorInterface|null { if ( !$this->container->has('router') diff --git a/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php b/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php index 9dc777d9..8528a095 100644 --- a/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php +++ b/src/Builder/Behaviors/Dependencies/WebhookConfigurationRegistryAwareTrait.php @@ -4,11 +4,11 @@ use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistryInterface; use Symfony\Contracts\Service\Attribute\SubscribedService; -use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; +use Symfony\Contracts\Service\ServiceSubscriberTrait; trait WebhookConfigurationRegistryAwareTrait { - use ServiceMethodsSubscriberTrait; + use ServiceSubscriberTrait; #[SubscribedService('webhook_configuration_registry')] protected function getWebhookConfigurationRegistry(): WebhookConfigurationRegistryInterface diff --git a/src/Builder/Pdf/HtmlPdfBuilder.php b/src/Builder/Pdf/HtmlPdfBuilder.php index bf0a780b..502e0f9c 100644 --- a/src/Builder/Pdf/HtmlPdfBuilder.php +++ b/src/Builder/Pdf/HtmlPdfBuilder.php @@ -8,7 +8,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderAssetInterface; use Sensiolabs\GotenbergBundle\Enumeration\Part; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; -use Symfony\Contracts\Service\ServiceSubscriberInterface; /** * @see https://gotenberg.dev/docs/routes#html-file-into-pdf-route diff --git a/src/DependencyInjection/CompilerPass/GotenbergPass.php b/src/DependencyInjection/CompilerPass/GotenbergPass.php index 2132dcc3..0623e243 100644 --- a/src/DependencyInjection/CompilerPass/GotenbergPass.php +++ b/src/DependencyInjection/CompilerPass/GotenbergPass.php @@ -5,6 +5,7 @@ use Sensiolabs\GotenbergBundle\Debug\Builder\TraceableBuilder; use Sensiolabs\GotenbergBundle\DependencyInjection\BuilderStack; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Compiler\RegisterServiceSubscribersPass; use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -19,6 +20,8 @@ public function __construct( public function process(ContainerBuilder $container): void { + $clone = new ContainerBuilder(); + $builderPerType = []; foreach ($container->findTaggedServiceIds('sensiolabs_gotenberg.builder') as $serviceId => $tags) { $serviceDefinition = $container->getDefinition($serviceId); @@ -34,7 +37,7 @@ public function process(ContainerBuilder $container): void $builderPerType[$type] ??= []; $builderPerType[$type][] = new Reference($serviceId); - $serviceDefinition->setAutowired(true); + $clone->setDefinition($serviceId, $serviceDefinition); } if ($container->hasDefinition('sensiolabs_gotenberg.pdf')) { @@ -49,6 +52,28 @@ public function process(ContainerBuilder $container): void ; } + $pass = new RegisterServiceSubscribersPass(); + $pass->process($clone); + + foreach ($clone->findTaggedServiceIds('sensiolabs_gotenberg.builder') as $serviceId => $tags) { + $definition = $clone->getDefinition($serviceId); + + if (!$definition->hasTag('container.service_subscriber.locator')) { + continue; + } + + $locatorFactoryId = $definition->getTag('container.service_subscriber.locator')[0]['id']; + $locatorId = str_replace(".{$serviceId}", '', $locatorFactoryId); + + $locatorMap = $clone->getDefinition($locatorId)->getArgument(0); + + $definition = $container->getDefinition($serviceId); + $definition->clearTag('container.service_subscriber'); + + $locatorReference = ServiceLocatorTagPass::register($container, $locatorMap, $serviceId); + $definition->addMethodCall('setContainer', [$locatorReference]); + } + if (!$container->has('sensiolabs_gotenberg.data_collector')) { return; } diff --git a/tests/Builder/Pdf/ConvertPdfBuilderTest.php b/tests/Builder/Pdf/ConvertPdfBuilderTest.php index c854464d..459df31f 100644 --- a/tests/Builder/Pdf/ConvertPdfBuilderTest.php +++ b/tests/Builder/Pdf/ConvertPdfBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\ConvertPdfBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\DownloadFromTestCaseTrait; diff --git a/tests/Builder/Pdf/FlattenPdfBuilderTest.php b/tests/Builder/Pdf/FlattenPdfBuilderTest.php index db44eeea..ee740f64 100644 --- a/tests/Builder/Pdf/FlattenPdfBuilderTest.php +++ b/tests/Builder/Pdf/FlattenPdfBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\FlattenPdfBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\DownloadFromTestCaseTrait; diff --git a/tests/Builder/Pdf/HtmlPdfBuilderTest.php b/tests/Builder/Pdf/HtmlPdfBuilderTest.php index 0c9cab05..7ba71d23 100644 --- a/tests/Builder/Pdf/HtmlPdfBuilderTest.php +++ b/tests/Builder/Pdf/HtmlPdfBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Exception\PdfPartRenderingException; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; diff --git a/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php b/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php index a8cf8beb..10543573 100644 --- a/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php +++ b/tests/Builder/Pdf/LibreOfficePdfBuilderTest.php @@ -5,7 +5,6 @@ use PHPUnit\Framework\Attributes\DataProvider; use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\LibreOfficePdfBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Enumeration\SplitMode; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; diff --git a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php index e2146f89..3ae0f4d9 100644 --- a/tests/Builder/Pdf/MarkdownPdfBuilderTest.php +++ b/tests/Builder/Pdf/MarkdownPdfBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\MarkdownPdfBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\ChromiumPdfTestCaseTrait; diff --git a/tests/Builder/Pdf/MergePdfBuilderTest.php b/tests/Builder/Pdf/MergePdfBuilderTest.php index f61ac55f..e62cb5ea 100644 --- a/tests/Builder/Pdf/MergePdfBuilderTest.php +++ b/tests/Builder/Pdf/MergePdfBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\MergePdfBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\DownloadFromTestCaseTrait; diff --git a/tests/Builder/Pdf/SplitPdfBuilderTest.php b/tests/Builder/Pdf/SplitPdfBuilderTest.php index 48860e76..52a72069 100644 --- a/tests/Builder/Pdf/SplitPdfBuilderTest.php +++ b/tests/Builder/Pdf/SplitPdfBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\SplitPdfBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Enumeration\SplitMode; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; diff --git a/tests/Builder/Pdf/UrlPdfBuilderTest.php b/tests/Builder/Pdf/UrlPdfBuilderTest.php index dc99bfbe..05a16f35 100644 --- a/tests/Builder/Pdf/UrlPdfBuilderTest.php +++ b/tests/Builder/Pdf/UrlPdfBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Pdf\UrlPdfBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\ChromiumPdfTestCaseTrait; use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; diff --git a/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php b/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php index 8a91b625..7ca36e30 100644 --- a/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/HtmlScreenshotBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\ChromiumScreenshotTestCaseTrait; diff --git a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php index 6dcd9b64..a5216070 100644 --- a/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/MarkdownScreenshotBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; diff --git a/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php b/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php index 16c33f70..1970b12c 100644 --- a/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php +++ b/tests/Builder/Screenshot/UrlScreenshotBuilderTest.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\BuilderInterface; use Sensiolabs\GotenbergBundle\Builder\Screenshot\UrlScreenshotBuilder; -use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException; use Sensiolabs\GotenbergBundle\Tests\Builder\Behaviors\ChromiumScreenshotTestCaseTrait; use Sensiolabs\GotenbergBundle\Tests\Builder\GotenbergBuilderTestCase; From 10f564a11e8186da3fc8a345d070589a01d339b8 Mon Sep 17 00:00:00 2001 From: Steven Renaux Date: Mon, 28 Apr 2025 11:57:47 +0200 Subject: [PATCH 30/30] Remove hack symfony --- config/builder.php | 4 +++ .../CompilerPass/GotenbergPass.php | 26 ------------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/config/builder.php b/config/builder.php index 0ff85709..e6c95bee 100644 --- a/config/builder.php +++ b/config/builder.php @@ -1,9 +1,11 @@ services(); @@ -14,6 +16,8 @@ $services->set('.sensiolabs_gotenberg.abstract_builder', AbstractBuilder::class) ->abstract() + ->call('setContainer', [service(ContainerInterface::class)]) + ->tag('container.service_subscriber') ; $services->set('sensiolabs_gotenberg.builder_configurator', BuilderConfigurator::class) diff --git a/src/DependencyInjection/CompilerPass/GotenbergPass.php b/src/DependencyInjection/CompilerPass/GotenbergPass.php index 0623e243..aa2c58e7 100644 --- a/src/DependencyInjection/CompilerPass/GotenbergPass.php +++ b/src/DependencyInjection/CompilerPass/GotenbergPass.php @@ -20,8 +20,6 @@ public function __construct( public function process(ContainerBuilder $container): void { - $clone = new ContainerBuilder(); - $builderPerType = []; foreach ($container->findTaggedServiceIds('sensiolabs_gotenberg.builder') as $serviceId => $tags) { $serviceDefinition = $container->getDefinition($serviceId); @@ -36,8 +34,6 @@ public function process(ContainerBuilder $container): void $builderPerType[$type] ??= []; $builderPerType[$type][] = new Reference($serviceId); - - $clone->setDefinition($serviceId, $serviceDefinition); } if ($container->hasDefinition('sensiolabs_gotenberg.pdf')) { @@ -52,28 +48,6 @@ public function process(ContainerBuilder $container): void ; } - $pass = new RegisterServiceSubscribersPass(); - $pass->process($clone); - - foreach ($clone->findTaggedServiceIds('sensiolabs_gotenberg.builder') as $serviceId => $tags) { - $definition = $clone->getDefinition($serviceId); - - if (!$definition->hasTag('container.service_subscriber.locator')) { - continue; - } - - $locatorFactoryId = $definition->getTag('container.service_subscriber.locator')[0]['id']; - $locatorId = str_replace(".{$serviceId}", '', $locatorFactoryId); - - $locatorMap = $clone->getDefinition($locatorId)->getArgument(0); - - $definition = $container->getDefinition($serviceId); - $definition->clearTag('container.service_subscriber'); - - $locatorReference = ServiceLocatorTagPass::register($container, $locatorMap, $serviceId); - $definition->addMethodCall('setContainer', [$locatorReference]); - } - if (!$container->has('sensiolabs_gotenberg.data_collector')) { return; }