diff --git a/README.md b/README.md index 174fc23e..c710f0f9 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ class YourController { return $gotenberg->url() ->url('https://sensiolabs.com/fr/') - ->generate() + ->build() ->stream() // will return directly a stream response ; } @@ -108,7 +108,7 @@ class YourController ->content('twig_simple_pdf.html.twig', [ 'my_var' => 'value' ]) - ->generate() + ->build() ->stream() // will return directly a stream response ; } @@ -167,7 +167,7 @@ class YourController { return $gotenberg->url() ->url('https://sensiolabs.com/fr/') - ->generate() + ->build() ->stream() ; } @@ -194,7 +194,7 @@ class YourController ->content('twig_simple_pdf.html.twig', [ 'my_var' => 'value' ]) - ->generate() + ->build() ->stream() ; } diff --git a/docs/assets.md b/docs/assets.md index e7755154..f4798fd4 100644 --- a/docs/assets.md +++ b/docs/assets.md @@ -11,23 +11,23 @@ You can add assets in several ways, and it's available for most builders. > As a reminder, we can only load assets in the content. And not in Header or Footer. > For more information about [Header and Footer restriction](https://gotenberg.dev/docs/routes#header-footer-chromium) > -> By default the assets are fetch in the `assets` folder of your application. +> By default, the assets are fetch in the `assets` folder of your application. > If your assets files are in another folder, you can override the > default value of `assets_directory` in your configuration file > `config/sensiolabs_gotenberg.yml`. > > The asset path resolution depends on certain criteria: > - If an absolute path is provided in `{{ gotenberg_asset() }}`, `assets()` - > or `addAsset`, this path will be applied and not the one in the configuration file. +> or `addAsset`, this path will be applied and not the one in the configuration file. > > - If a path is provided in `{{ gotenberg_asset() }}`, `assets()` - > or `addAsset`, it will be treated as a relative path from the `assets_directory` configuration. +> or `addAsset`, it will be treated as a relative path from the `assets_directory` configuration. > > - If an absolute path is provided in the configuration file (`assets_directory`), the path applied - > in `{{ gotenberg_asset() }}`, `assets()` or `addAsset` will have `assets_directory` as base path. +> in `{{ gotenberg_asset() }}`, `assets()` or `addAsset` will have `assets_directory` as base path. > > - If a relative path is provided in the configuration file (`assets_directory`), the path applied - > will have the root of the project as base path followed by the path from the configuration file. +> will have the root of the project as base path followed by the path from the configuration file. > >
> Examples @@ -49,8 +49,7 @@ You can add assets in several ways, and it's available for most builders. ## Twig file - ->build() - ->streamResponse()n asset path. +`{{ gotenberg_asset() }}` Twig function will help you to generate an asset path. This function work as [asset() Twig function](https://symfony.com/doc/current/templates.html#linking-to-css-javascript-and-image-assets). You can provide an absolute path. @@ -97,9 +96,9 @@ class YourController public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response { return $gotenberg->html() - ->content('t - ->build() - ->streamResponse() + ->content('twig_simple_pdf.html.twig') + ->generate() + ->stream() ; } } @@ -143,8 +142,8 @@ class YourController 'img/ceo.jpeg', 'img/admin.jpeg' ) - ->build() - ->streamResponse() + ->generate() + ->stream() ; } } @@ -167,8 +166,8 @@ class YourController '../img/ceo.jpeg', '../img/admin.jpeg' ) - ->build() - ->streamResponse() + ->generate() + ->stream() ; } } @@ -192,9 +191,9 @@ class YourController '../img/ceo.jpeg', '../img/admin.jpeg' ) - ->addAsset(' - ->build() - ->streamResponse() + ->addAsset('../img/developer.jpeg') + ->generate() + ->stream() ; } } diff --git a/docs/pdf/convert-builder.md b/docs/pdf/convert-builder.md index 0758767f..b2c3c020 100644 --- a/docs/pdf/convert-builder.md +++ b/docs/pdf/convert-builder.md @@ -29,6 +29,7 @@ class YourController 'document_2.pdf', ) ->generate() + ->stream() ; } } @@ -59,6 +60,7 @@ class YourController ) ->pdfFormat(PdfFormat::Pdf1b) ->generate() + ->stream() ; } } @@ -86,6 +88,7 @@ class YourController ) ->pdfUniversalAccess() // is same as `->pdfUniversalAccess(true)` ->generate() + ->stream() ; } } diff --git a/docs/pdf/customization.md b/docs/pdf/customization.md index 4bbf1491..6f49c1a1 100644 --- a/docs/pdf/customization.md +++ b/docs/pdf/customization.md @@ -76,6 +76,7 @@ class YourController ]) ->paperSize(21, 29.7, Unit::Centimeters) ->generate() + ->stream() ; } } @@ -103,6 +104,7 @@ class YourController ]) ->paperStandardSize(PaperSize::A4) ->generate() + ->stream() ; } } @@ -155,6 +157,7 @@ class YourController ]) ->paperWidth(15, Unit::Inches) ->generate() + ->stream() ; } } @@ -186,6 +189,7 @@ class YourController ]) ->paperHeight(15, Unit::Inches) ->generate() + ->stream() ; } } @@ -218,6 +222,7 @@ class YourController ]) ->margins(1, 2, 3, 4, Unit::Inches) ->generate() + ->stream() ; } } @@ -245,6 +250,7 @@ class YourController ->marginLeft(4, Unit::Picas) ->marginRight(4, Unit::Millimeters) ->generate() + ->stream() ; } } @@ -274,6 +280,7 @@ class YourController ]) ->preferCssPageSize() ->generate() + ->stream() ; } } @@ -300,6 +307,7 @@ class YourController ]) ->printBackground() ->generate() + ->stream() ; } } @@ -326,6 +334,7 @@ class YourController ]) ->omitBackground() ->generate() + ->stream() ; } } @@ -352,6 +361,7 @@ class YourController ]) ->landscape() ->generate() + ->stream() ; } } @@ -378,6 +388,7 @@ class YourController ]) ->scale(2.5) ->generate() + ->stream() ; } } @@ -404,6 +415,7 @@ class YourController ]) ->nativePageRanges('1-5') ->generate() + ->stream() ; } } @@ -455,6 +467,7 @@ class YourController 'my_var' => 'value' ]) ->generate() + ->stream() ; } } @@ -483,6 +496,7 @@ class YourController ->contentFile('content.html') ->footerFile('footer.html') ->generate() + ->stream() ; } } @@ -505,6 +519,7 @@ class YourController ->contentFile('../templates/html/content.html') ->footerFile('../templates/html/footer.html') ->generate() + ->stream() ; } } @@ -537,6 +552,7 @@ class YourController ]) ->waitDelay('5s') ->generate() + ->stream() ; } } @@ -565,6 +581,7 @@ class YourController ]) ->waitForExpression("window.globalVar === 'ready'") ->generate() + ->stream() ; } } @@ -597,6 +614,7 @@ class YourController ]) ->emulatedMediaType(EmulatedMediaType::Screen) ->generate() + ->stream() ; } } @@ -633,6 +651,7 @@ class YourController 'sameSite' => 'Lax', ]]) ->generate() + ->stream() ; } } @@ -669,6 +688,7 @@ class YourController 'sameSite' => 'Lax', ]) ->generate() + ->stream() ; } } @@ -702,6 +722,7 @@ class YourController 'sameSite' => 'Lax', ]]) ->generate() + ->stream() ; } } @@ -731,6 +752,7 @@ class YourController 'MyHeader' => 'MyValue' ]) ->generate() + ->stream() ; } } @@ -764,6 +786,7 @@ class YourController 'MyHeader' => 'MyValue' ]) ->generate() + ->stream() ; } } @@ -792,6 +815,7 @@ class YourController ]) ->failOnHttpStatusCodes([401, 403]) ->generate() + ->stream() ; } } @@ -823,6 +847,7 @@ class YourController ]) ->failOnConsoleExceptions() ->generate() + ->stream() ; } } @@ -856,6 +881,7 @@ class YourController ]) ->skipNetworkIdleEvent() ->generate() + ->stream() ; } } @@ -888,6 +914,7 @@ class YourController ]) ->metadata(['Author' => 'SensioLabs', 'Subject' => 'Gotenberg']) ->generate() + ->stream() ; } } @@ -918,6 +945,7 @@ class YourController ]) ->addMetadata('key', 'value') ->generate() + ->stream() ; } } @@ -948,6 +976,7 @@ class YourController ]) ->pdfFormat(PdfFormat::Pdf1b) ->generate() + ->stream() ; } } @@ -978,6 +1007,7 @@ class YourController ]) ->pdfUniversalAccess() ->generate() + ->stream() ; } } diff --git a/docs/pdf/header-footer.md b/docs/pdf/header-footer.md index f3931b91..452ccabc 100644 --- a/docs/pdf/header-footer.md +++ b/docs/pdf/header-footer.md @@ -48,6 +48,7 @@ class YourController 'my_var' => 'value' ]) ->generate() + ->stream() ; } } @@ -75,6 +76,7 @@ class YourController ->contentFile('content.html') ->footerFile('footer.html') ->generate() + ->stream() ; } } @@ -97,6 +99,7 @@ class YourController ->contentFile('../templates/html/content.html') ->footerFile('../templates/html/footer.html') ->generate() + ->stream() ; } } diff --git a/docs/pdf/html-builder.md b/docs/pdf/html-builder.md index bc3a6f05..2680482e 100644 --- a/docs/pdf/html-builder.md +++ b/docs/pdf/html-builder.md @@ -39,6 +39,7 @@ class YourController return $gotenberg->html() ->contentFile('../templates/content.html') ->generate() + ->stream() ; } } @@ -62,6 +63,7 @@ class YourController 'my_var' => 'value' ]) ->generate() + ->stream() ; } } diff --git a/docs/pdf/markdown-builder.md b/docs/pdf/markdown-builder.md index ed1b6728..d2cb8711 100644 --- a/docs/pdf/markdown-builder.md +++ b/docs/pdf/markdown-builder.md @@ -59,6 +59,7 @@ class YourController ->wrapperFile('../templates/wrapper.html') ->files('content.md') ->generate() + ->stream() ; } } @@ -104,6 +105,7 @@ class YourController ]) ->files('content.md') ->generate() + ->stream() ; } } @@ -132,6 +134,7 @@ class YourController 'footer.md', ) ->generate() + ->stream() ; } } diff --git a/docs/pdf/merge-builder.md b/docs/pdf/merge-builder.md index 01f1d7a1..7047b63c 100644 --- a/docs/pdf/merge-builder.md +++ b/docs/pdf/merge-builder.md @@ -24,6 +24,7 @@ class YourController 'document_2.pdf', ) ->generate() + ->stream() ; } } @@ -54,6 +55,7 @@ class YourController ) ->pdfFormat(PdfFormat::Pdf1b) ->generate() + ->stream() ; } } @@ -81,6 +83,7 @@ class YourController ) ->pdfUniversalAccess() // is same as `->pdfUniversalAccess(true)` ->generate() + ->stream() ; } } @@ -108,6 +111,7 @@ class YourController ) ->metadata(['Author' => 'SensioLabs', 'Subject' => 'Gotenberg']) ->generate() + ->stream() ; } } @@ -135,6 +139,7 @@ class YourController ) ->addMetadata('key', 'value') ->generate() + ->stream() ; } } diff --git a/docs/pdf/office-builder.md b/docs/pdf/office-builder.md index 5771f321..d4c2274d 100644 --- a/docs/pdf/office-builder.md +++ b/docs/pdf/office-builder.md @@ -33,7 +33,8 @@ class YourController { return $gotenberg->office() ->files('document.txt') - ->generate() // will return directly a stream response + ->generate() + ->stream() // will return directly a stream response ; } } @@ -53,7 +54,8 @@ class YourController { return $gotenberg->office() ->files('document_one.txt', 'document_two.odt') - ->generate() // will download a zip file with two PDF files + ->generate() + ->stream() // will download a zip file with two PDF files ; } } @@ -78,6 +80,7 @@ class YourController ->files('document_one.txt', 'document_two.odt') ->merge() // is same as ->merge(true) ->generate() + ->stream() ; } } @@ -105,6 +108,7 @@ class YourController ->files('document.txt') ->landscape() // is same as `->landscape(true)` ->generate() + ->stream() ; } } @@ -132,6 +136,7 @@ class YourController ->files('document.txt') ->nativePageRanges('1-5') ->generate() + ->stream() ; } } @@ -160,6 +165,7 @@ class YourController ->files('document.txt') ->exportFormFields() // is same as `->exportFormFields(false)` ->generate() + ->stream() ; } } @@ -187,6 +193,7 @@ class YourController ->files('document.txt') ->singlePageSheets() // is same as `->singlePageSheets(true)` ->generate() + ->stream() ; } } @@ -214,6 +221,7 @@ class YourController ->files('document.txt') ->pdfFormat(PdfFormat::Pdf1b) ->generate() + ->stream() ; } } @@ -241,6 +249,7 @@ class YourController ->files('document.txt') ->pdfUniversalAccess() // is same as `->pdfUniversalAccess(true)` ->generate() + ->stream() ; } } @@ -268,6 +277,7 @@ class YourController ->files('document.txt') ->metadata(['Author' => 'SensioLabs', 'Subject' => 'Gotenberg']) ->generate() + ->stream() ; } } @@ -292,6 +302,7 @@ class YourController ->files('document.txt') ->addMetadata('key', 'value') ->generate() + ->stream() ; } } diff --git a/docs/pdf/url-builder.md b/docs/pdf/url-builder.md index b8fda9b5..458ebe62 100644 --- a/docs/pdf/url-builder.md +++ b/docs/pdf/url-builder.md @@ -18,6 +18,7 @@ class YourController return $gotenberg->url() ->url('https://sensiolabs.com/fr/') ->generate() + ->stream() ; } } @@ -52,6 +53,7 @@ class YourController 'my_var' => 'value' ]) ->generate() + ->stream() ; } } @@ -80,6 +82,7 @@ class YourController 'footer.md', ) ->generate() + ->stream() ; } } diff --git a/docs/screenshot/customization.md b/docs/screenshot/customization.md index 403d3942..4948aeea 100644 --- a/docs/screenshot/customization.md +++ b/docs/screenshot/customization.md @@ -53,6 +53,7 @@ class YourController ]) ->width(600) ->generate() + ->stream() ; } } @@ -82,6 +83,7 @@ class YourController ]) ->height(600) ->generate() + ->stream() ; } } @@ -111,6 +113,7 @@ class YourController ]) ->clip() ->generate() + ->stream() ; } } @@ -142,6 +145,7 @@ class YourController ->quality(50) ->format(ScreenshotFormat::Jpeg) ->generate() + ->stream() ; } } @@ -171,6 +175,7 @@ class YourController ]) ->omitBackground() ->generate() + ->stream() ; } } @@ -199,6 +204,7 @@ class YourController ]) ->optimizeForSpeed(true) ->generate() + ->stream() ; } } @@ -226,6 +232,7 @@ class YourController ->html() ->waitDelay('5s') ->generate() + ->stream() ; } } @@ -251,6 +258,7 @@ class YourController ->html() ->waitForExpression("window.globalVar === 'ready'") ->generate() + ->stream() ; } } @@ -280,6 +288,7 @@ class YourController ->html() ->emulatedMediaType(EmulatedMediaType::Screen) ->generate() + ->stream() ; } } @@ -313,6 +322,7 @@ class YourController 'sameSite' => 'Lax', ]]) ->generate() + ->stream() ; } } @@ -346,6 +356,7 @@ class YourController 'sameSite' => 'Lax', ]) ->generate() + ->stream() ; } } @@ -376,6 +387,7 @@ class YourController 'sameSite' => 'Lax', ]]) ->generate() + ->stream() ; } } @@ -402,6 +414,7 @@ class YourController 'MyHeader' => 'MyValue' ]) ->generate() + ->stream() ; } } @@ -432,6 +445,7 @@ class YourController 'MyHeader' => 'MyValue' ]) ->generate() + ->stream() ; } } @@ -457,6 +471,7 @@ class YourController ->html() ->failOnHttpStatusCodes([401, 403]) ->generate() + ->stream() ; } } @@ -485,6 +500,7 @@ class YourController ->html() ->failOnConsoleExceptions() ->generate() + ->stream() ; } } @@ -515,6 +531,7 @@ class YourController ->html() ->skipNetworkIdleEvent() ->generate() + ->stream() ; } } @@ -545,6 +562,7 @@ class YourController ->html() ->format(ScreenshotFormat::Webp) ->generate() + ->stream() ; } } diff --git a/docs/screenshot/html-builder.md b/docs/screenshot/html-builder.md index 1f08b26d..5aab94a3 100644 --- a/docs/screenshot/html-builder.md +++ b/docs/screenshot/html-builder.md @@ -40,6 +40,7 @@ class YourController return $gotenberg->html() ->contentFile('../templates/content.html') ->generate() + ->stream() ; } } @@ -63,6 +64,7 @@ class YourController 'my_var' => 'value' ]) ->generate() + ->stream() ; } } diff --git a/docs/screenshot/markdown-builder.md b/docs/screenshot/markdown-builder.md index 7eda1d98..2ed19c2e 100644 --- a/docs/screenshot/markdown-builder.md +++ b/docs/screenshot/markdown-builder.md @@ -60,6 +60,7 @@ class YourController ->wrapperFile('../templates/wrapper.html') ->files('content.md') ->generate() + ->stream() ; } } @@ -105,6 +106,7 @@ class YourController ]) ->files('content.md') ->generate() + ->stream() ; } } @@ -133,6 +135,7 @@ class YourController 'footer.md', ) ->generate() + ->stream() ; } } diff --git a/docs/screenshot/url-builder.md b/docs/screenshot/url-builder.md index 5e6d2933..bb3bf745 100644 --- a/docs/screenshot/url-builder.md +++ b/docs/screenshot/url-builder.md @@ -18,6 +18,7 @@ class YourController return $gotenberg->url() ->url('https://sensiolabs.com/fr/') ->generate() + ->stream() ; } } @@ -52,6 +53,7 @@ class YourController 'my_var' => 'value' ]) ->generate() + ->stream() ; } } @@ -80,6 +82,7 @@ class YourController 'footer.md', ) ->generate() + ->stream() ; } } diff --git a/src/Builder/Pdf/AbstractPdfBuilder.php b/src/Builder/Pdf/AbstractPdfBuilder.php index 39a1c7d5..9eddae3d 100644 --- a/src/Builder/Pdf/AbstractPdfBuilder.php +++ b/src/Builder/Pdf/AbstractPdfBuilder.php @@ -4,7 +4,6 @@ use Sensiolabs\GotenbergBundle\Builder\DefaultBuilderTrait; use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface; -use Sensiolabs\GotenbergBundle\Client\GotenbergResponse; use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter; abstract class AbstractPdfBuilder implements PdfBuilderInterface diff --git a/src/Builder/Pdf/PdfBuilderInterface.php b/src/Builder/Pdf/PdfBuilderInterface.php index 73756f50..b889eb6d 100644 --- a/src/Builder/Pdf/PdfBuilderInterface.php +++ b/src/Builder/Pdf/PdfBuilderInterface.php @@ -7,7 +7,7 @@ interface PdfBuilderInterface { /** - * Generates the PDF and returns the query. + * Generates the PDF and returns the result. */ public function generate(): GotenbergFileResult; } diff --git a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php index 943d8477..0fd47c4e 100644 --- a/src/Builder/Screenshot/MarkdownScreenshotBuilder.php +++ b/src/Builder/Screenshot/MarkdownScreenshotBuilder.php @@ -38,6 +38,7 @@ public function files(string ...$paths): self $this->formFields['files'] = []; foreach ($paths as $path) { + $path = (string) $path; $this->assertFileExtension($path, ['md']); $dataPart = new DataPart(new DataPartFile($this->asset->resolve($path))); diff --git a/src/Builder/Screenshot/ScreenshotBuilderInterface.php b/src/Builder/Screenshot/ScreenshotBuilderInterface.php index e300cafd..dd8eec60 100644 --- a/src/Builder/Screenshot/ScreenshotBuilderInterface.php +++ b/src/Builder/Screenshot/ScreenshotBuilderInterface.php @@ -7,7 +7,7 @@ interface ScreenshotBuilderInterface { /** - * Generates the Screenshot and returns the query. + * Generates the Screenshot and returns the result. */ public function generate(): GotenbergFileResult; } diff --git a/src/Debug/Builder/TraceableScreenshotBuilder.php b/src/Debug/Builder/TraceableScreenshotBuilder.php index 557f017a..69abeaf5 100644 --- a/src/Debug/Builder/TraceableScreenshotBuilder.php +++ b/src/Debug/Builder/TraceableScreenshotBuilder.php @@ -2,8 +2,8 @@ namespace Sensiolabs\GotenbergBundle\Debug\Builder; +use Sensiolabs\GotenbergBundle\Builder\GotenbergFileResult; use Sensiolabs\GotenbergBundle\Builder\Screenshot\ScreenshotBuilderInterface; -use Sensiolabs\GotenbergBundle\Client\GotenbergResponse; use Symfony\Component\Stopwatch\Stopwatch; final class TraceableScreenshotBuilder implements ScreenshotBuilderInterface @@ -28,7 +28,7 @@ public function __construct( ) { } - public function generate(): GotenbergResponse + public function generate(): GotenbergFileResult { $name = self::$count.'.'.$this->inner::class.'::'.__FUNCTION__; ++self::$count; @@ -38,17 +38,17 @@ public function generate(): GotenbergResponse $swEvent->stop(); $fileName = 'Unknown'; - if ($response->headers->has('Content-Disposition')) { + if ($response->getHeaders()->has('Content-Disposition')) { $matches = []; /* @see https://onlinephp.io/c/c2606 */ - preg_match('#[^;]*;\sfilename="?(?P[^"]*)"?#', $response->headers->get('Content-Disposition', ''), $matches); + preg_match('#[^;]*;\sfilename="?(?P[^"]*)"?#', $response->getHeaders()->get('Content-Disposition', ''), $matches); $fileName = $matches['fileName']; } $lengthInBytes = null; - if ($response->headers->has('Content-Length')) { - $lengthInBytes = abs((int) $response->headers->get('Content-Length')); + if ($response->getHeaders()->has('Content-Length')) { + $lengthInBytes = abs((int) $response->getHeaders()->get('Content-Length')); } $this->screenshots[] = [ diff --git a/src/SensiolabsGotenbergBundle.php b/src/SensiolabsGotenbergBundle.php index 937fdca6..4bb8d83e 100644 --- a/src/SensiolabsGotenbergBundle.php +++ b/src/SensiolabsGotenbergBundle.php @@ -13,7 +13,7 @@ public function getPath(): string return \dirname(__DIR__); } - public function build(ContainerBuilder $container): void + public function generate(ContainerBuilder $container): void { $container->addCompilerPass(new GotenbergPass()); } diff --git a/tests/Builder/Pdf/HtmlPdfBuilderTest.php b/tests/Builder/Pdf/HtmlPdfBuilderTest.php index 9d661d45..e32c7e89 100644 --- a/tests/Builder/Pdf/HtmlPdfBuilderTest.php +++ b/tests/Builder/Pdf/HtmlPdfBuilderTest.php @@ -10,6 +10,7 @@ use Sensiolabs\GotenbergBundle\Builder\Pdf\HtmlPdfBuilder; 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\GotenbergAssetExtension; use Symfony\Component\HttpFoundation\RequestStack;