Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Async generation #84

Merged
merged 26 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9915a29
Add ability to generate asynchronously using webhooks
maelanleborgne Jun 19, 2024
ec46e92
switch to constructor injection
maelanleborgne Sep 9, 2024
b26c12f
cleanup after review
maelanleborgne Oct 3, 2024
f97d4f5
Merge branch 'main' of github.com:Neirda24/GotenbergBundle into featu…
Neirda24 Oct 24, 2024
abd6e47
[UPDATE] Allow to set extra headers when using webhook
Neirda24 Oct 24, 2024
0c6cb61
[UPDATE] Auto docs
Neirda24 Oct 24, 2024
9fb37d7
[UPDATE] Remove custom id generator for the moment
Neirda24 Oct 31, 2024
ed70e51
[UPDATE] Remove strict types
Neirda24 Oct 31, 2024
f6509f6
[UPDATE] Docs
Neirda24 Oct 31, 2024
a40ec71
[UPDATE] Doc & doc generation
Neirda24 Nov 1, 2024
9faba1a
Merge branch 'main' of github.com:sensiolabs/GotenbergBundle into fea…
Neirda24 Nov 1, 2024
967bfad
[Fix] A few stuff
Neirda24 Nov 1, 2024
823faba
[UPDATE] A few stuff
Neirda24 Nov 1, 2024
83e1d26
[UPDATE] Add webhook methods
Neirda24 Nov 3, 2024
42a8544
[UPDATE] Exclude some methods to auto docs
Neirda24 Nov 3, 2024
a574f51
[UPDATE] Exclude some methods to auto docs
Neirda24 Nov 3, 2024
a9694cb
[UPDATE] Change equality check
Neirda24 Nov 3, 2024
8d39bd9
Update profiler icons + Fix webhook configuration + fix some tests
Neirda24 Nov 15, 2024
ebb4656
[Update] a few things
Neirda24 Nov 15, 2024
0f00fdf
fix typo
Neirda24 Nov 15, 2024
ee72e12
fix typo
Neirda24 Nov 15, 2024
eb474ad
Add documentation for webhook
Neirda24 Nov 16, 2024
44764dd
Update docs for webhooks
Neirda24 Nov 16, 2024
f8a1de9
Update docs for webhooks
Neirda24 Nov 16, 2024
c461a88
Add tests on async trait
Neirda24 Nov 16, 2024
931943a
[FIX] CI
Neirda24 Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/builder_pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
service('sensiolabs_gotenberg.webhook_configuration_registry'),
service('request_stack'),
service('twig')->nullOnInvalid(),
])
Expand All @@ -33,6 +34,7 @@
->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(),
Expand All @@ -47,6 +49,7 @@
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
service('sensiolabs_gotenberg.webhook_configuration_registry'),
service('request_stack'),
service('twig')->nullOnInvalid(),
])
Expand All @@ -59,6 +62,7 @@
->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')
Expand All @@ -69,6 +73,7 @@
->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')
Expand All @@ -79,6 +84,7 @@
->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')
Expand Down
3 changes: 3 additions & 0 deletions config/builder_screenshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
service('sensiolabs_gotenberg.webhook_configuration_registry'),
service('request_stack'),
service('twig')->nullOnInvalid(),
])
Expand All @@ -30,6 +31,7 @@
->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(),
Expand All @@ -44,6 +46,7 @@
->args([
service('sensiolabs_gotenberg.client'),
service('sensiolabs_gotenberg.asset.base_dir_formatter'),
service('sensiolabs_gotenberg.webhook_configuration_registry'),
service('request_stack'),
service('twig')->nullOnInvalid(),
])
Expand Down
11 changes: 11 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Sensiolabs\GotenbergBundle\GotenbergScreenshot;
use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface;
use Sensiolabs\GotenbergBundle\Twig\GotenbergAssetExtension;
use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistry;
use Sensiolabs\GotenbergBundle\Webhook\WebhookConfigurationRegistryInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Filesystem\Filesystem;
use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
Expand Down Expand Up @@ -68,4 +70,13 @@
$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(),
])
->tag('sensiolabs_gotenberg.webhook_configuration_registry')
->alias(WebhookConfigurationRegistryInterface::class, 'sensiolabs_gotenberg.webhook_configuration_registry')
;
};
16 changes: 9 additions & 7 deletions docs/builders_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

## Pdf

* [HtmlPdfBuilder](./pdf/builders_api/HtmlPdfBuilder.md)
* [UrlPdfBuilder](./pdf/builders_api/UrlPdfBuilder.md)
* [MarkdownPdfBuilder](./pdf/builders_api/MarkdownPdfBuilder.md)
* [LibreOfficePdfBuilder](./pdf/builders_api/LibreOfficePdfBuilder.md)
* [HtmlPdfBuilder](./Pdf/builders_api/HtmlPdfBuilder.md)
* [UrlPdfBuilder](./Pdf/builders_api/UrlPdfBuilder.md)
* [MarkdownPdfBuilder](./Pdf/builders_api/MarkdownPdfBuilder.md)
* [LibreOfficePdfBuilder](./Pdf/builders_api/LibreOfficePdfBuilder.md)
* [MergePdfBuilder](./Pdf/builders_api/MergePdfBuilder.md)
* [ConvertPdfBuilder](./Pdf/builders_api/ConvertPdfBuilder.md)

## Screenshot

* [HtmlScreenshotBuilder](./screenshot/builders_api/HtmlScreenshotBuilder.md)
* [UrlScreenshotBuilder](./screenshot/builders_api/UrlScreenshotBuilder.md)
* [MarkdownScreenshotBuilder](./screenshot/builders_api/MarkdownScreenshotBuilder.md)
* [HtmlScreenshotBuilder](./Screenshot/builders_api/HtmlScreenshotBuilder.md)
* [UrlScreenshotBuilder](./Screenshot/builders_api/UrlScreenshotBuilder.md)
* [MarkdownScreenshotBuilder](./Screenshot/builders_api/MarkdownScreenshotBuilder.md)

26 changes: 23 additions & 3 deletions docs/generate.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env php
<?php

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\UrlPdfBuilder;
use Sensiolabs\GotenbergBundle\Builder\Screenshot\HtmlScreenshotBuilder;
use Sensiolabs\GotenbergBundle\Builder\Screenshot\MarkdownScreenshotBuilder;
Expand All @@ -23,6 +25,8 @@
UrlPdfBuilder::class,
MarkdownPdfBuilder::class,
LibreOfficePdfBuilder::class,
MergePdfBuilder::class,
ConvertPdfBuilder::class,
],
'Screenshot' => [
HtmlScreenshotBuilder::class,
Expand All @@ -36,6 +40,7 @@
'setLogger',
'setConfigurations',
'generate',
'generateAsync',
'getMultipartFormData',
];

Expand All @@ -59,7 +64,7 @@ function parseDocComment(string $rawDocComment): string
{
$result = '';

$lines = explode("\n", $rawDocComment);
$lines = explode("\n", trim($rawDocComment, "\n"));
array_shift($lines);
array_pop($lines);

Expand Down Expand Up @@ -89,13 +94,28 @@ function parseBuilder(ReflectionClass $builder): string
$builderName = $builder->getShortName();
$markdown .= "# {$builderName}\n\n";

$builderComment = $builder->getDocComment();

if (false !== $builderComment) {
$markdown .= parseDocComment($builderComment)."\n";
}

$methods = [];
foreach ($builder->getInterfaces() as $interface) {
foreach ($interface->getMethods() as $method) {
if ('' !== ($method->getDocComment() ?: '')) {
$methods[$method->getName()] = parseDocComment($method->getDocComment());
}
}
}

foreach ($builder->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if (\in_array($method->getName(), EXCLUDED_METHODS, true) === true) {
continue;
}

$methodSignature = parseMethodSignature($method);
$docComment = parseDocComment($method->getDocComment() ?: '');
$docComment = parseDocComment($methods[$method->getShortName()] ?? $method->getDocComment() ?: '');

$markdown .= <<<"MARKDOWN"
* `{$methodSignature}`:
Expand All @@ -118,7 +138,7 @@ function saveFile(InputInterface $input, string $filename, string $contents): vo
$summary = "# Builders API\n\n";

foreach (BUILDERS as $type => $builderClasses) {
$subDirectory = strtolower($type).'/builders_api';
$subDirectory = "{$type}/builders_api";
$directory = __DIR__.'/'.$subDirectory;

if (!@mkdir($directory, recursive: true) && !is_dir($directory)) {
Expand Down
25 changes: 25 additions & 0 deletions docs/pdf/builders_api/ConvertPdfBuilder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ConvertPdfBuilder

* `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.

* `files(string $paths)`:

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $webhook)`:
Providing an existing $webhook from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

* `webhookUrls(string $successWebhook, ?string $errorWebhook)`:
Allows to set both $successWebhook and $errorWebhook URLs. If $errorWebhook is not provided, it will fallback to $successWebhook one.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

* `fileName(string $fileName, string $headerDisposition)`:

* `processor(Sensiolabs\GotenbergBundle\Processor\ProcessorInterface $processor)`:

9 changes: 9 additions & 0 deletions docs/pdf/builders_api/HtmlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ The metadata to write.

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $webhook)`:
Providing an existing $webhook from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

* `webhookUrls(string $successWebhook, ?string $errorWebhook)`:
Allows to set both $successWebhook and $errorWebhook URLs. If $errorWebhook is not provided, it will fallback to $successWebhook one.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

* `fileName(string $fileName, string $headerDisposition)`:

* `processor(Sensiolabs\GotenbergBundle\Processor\ProcessorInterface $processor)`:
Expand Down
9 changes: 9 additions & 0 deletions docs/pdf/builders_api/LibreOfficePdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ If the form field reduceImageResolution is set to true, tell if all images will

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $webhook)`:
Providing an existing $webhook from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

* `webhookUrls(string $successWebhook, ?string $errorWebhook)`:
Allows to set both $successWebhook and $errorWebhook URLs. If $errorWebhook is not provided, it will fallback to $successWebhook one.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

* `fileName(string $fileName, string $headerDisposition)`:

* `processor(Sensiolabs\GotenbergBundle\Processor\ProcessorInterface $processor)`:
Expand Down
9 changes: 9 additions & 0 deletions docs/pdf/builders_api/MarkdownPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ The metadata to write.

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $webhook)`:
Providing an existing $webhook from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

* `webhookUrls(string $successWebhook, ?string $errorWebhook)`:
Allows to set both $successWebhook and $errorWebhook URLs. If $errorWebhook is not provided, it will fallback to $successWebhook one.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

* `fileName(string $fileName, string $headerDisposition)`:

* `processor(Sensiolabs\GotenbergBundle\Processor\ProcessorInterface $processor)`:
Expand Down
33 changes: 33 additions & 0 deletions docs/pdf/builders_api/MergePdfBuilder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# MergePdfBuilder

Merge `n` pdf files into a single one.

* `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.

* `files(string $paths)`:

* `metadata(array $metadata)`:
Resets the metadata.

* `addMetadata(string $key, string $value)`:
The metadata to write.

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $webhook)`:
Providing an existing $webhook from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

* `webhookUrls(string $successWebhook, ?string $errorWebhook)`:
Allows to set both $successWebhook and $errorWebhook URLs. If $errorWebhook is not provided, it will fallback to $successWebhook one.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

* `fileName(string $fileName, string $headerDisposition)`:

* `processor(Sensiolabs\GotenbergBundle\Processor\ProcessorInterface $processor)`:

9 changes: 9 additions & 0 deletions docs/pdf/builders_api/UrlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ The metadata to write.

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $webhook)`:
Providing an existing $webhook from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

* `webhookUrls(string $successWebhook, ?string $errorWebhook)`:
Allows to set both $successWebhook and $errorWebhook URLs. If $errorWebhook is not provided, it will fallback to $successWebhook one.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

* `fileName(string $fileName, string $headerDisposition)`:

* `processor(Sensiolabs\GotenbergBundle\Processor\ProcessorInterface $processor)`:
Expand Down
9 changes: 9 additions & 0 deletions docs/screenshot/builders_api/HtmlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ Adds a file, like an image, font, stylesheet, and so on.

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $webhook)`:
Providing an existing $webhook from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

* `webhookUrls(string $successWebhook, ?string $errorWebhook)`:
Allows to set both $successWebhook and $errorWebhook URLs. If $errorWebhook is not provided, it will fallback to $successWebhook one.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

* `fileName(string $fileName, string $headerDisposition)`:

* `processor(Sensiolabs\GotenbergBundle\Processor\ProcessorInterface $processor)`:
Expand Down
9 changes: 9 additions & 0 deletions docs/screenshot/builders_api/MarkdownScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ Adds a file, like an image, font, stylesheet, and so on.

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $webhook)`:
Providing an existing $webhook from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

* `webhookUrls(string $successWebhook, ?string $errorWebhook)`:
Allows to set both $successWebhook and $errorWebhook URLs. If $errorWebhook is not provided, it will fallback to $successWebhook one.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

* `fileName(string $fileName, string $headerDisposition)`:

* `processor(Sensiolabs\GotenbergBundle\Processor\ProcessorInterface $processor)`:
Expand Down
9 changes: 9 additions & 0 deletions docs/screenshot/builders_api/UrlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ Adds a file, like an image, font, stylesheet, and so on.

* `downloadFrom(array $downloadFrom)`:

* `webhookConfiguration(string $webhook)`:
Providing an existing $webhook from the configuration file, it will correctly set both success and error webhook URLs as well as extra_http_headers if defined.

* `webhookUrls(string $successWebhook, ?string $errorWebhook)`:
Allows to set both $successWebhook and $errorWebhook URLs. If $errorWebhook is not provided, it will fallback to $successWebhook one.

* `webhookExtraHeaders(array $extraHeaders)`:
Extra headers that will be provided to the webhook endpoint. May it either be Success or Error.

* `fileName(string $fileName, string $headerDisposition)`:

* `processor(Sensiolabs\GotenbergBundle\Processor\ProcessorInterface $processor)`:
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnRisky="true"
failOnWarning="true">
<php>
Expand Down
11 changes: 11 additions & 0 deletions src/Builder/AsyncBuilderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Sensiolabs\GotenbergBundle\Builder;

interface AsyncBuilderInterface
{
/**
* Generates a file asynchronously.
*/
public function generateAsync(): void;
}
Loading