Skip to content

Commit

Permalink
[RELEASE_8.13.0] Add new fields form Chromium (sensiolabs#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenRenaux authored Nov 20, 2024
1 parent 7d86472 commit ee33766
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 34 deletions.
8 changes: 8 additions & 0 deletions docs/pdf/builders_api/HtmlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ document. (default None).
Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).

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

* `failOnResourceLoadingFailed(bool $bool)`:
Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).

* `failOnConsoleExceptions(bool $bool)`:
Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
Expand Down
8 changes: 8 additions & 0 deletions docs/pdf/builders_api/MarkdownPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ document. (default None).
Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).

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

* `failOnResourceLoadingFailed(bool $bool)`:
Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).

* `failOnConsoleExceptions(bool $bool)`:
Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
Expand Down
8 changes: 8 additions & 0 deletions docs/pdf/builders_api/UrlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ document. (default None).
Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).

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

* `failOnResourceLoadingFailed(bool $bool)`:
Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).

* `failOnConsoleExceptions(bool $bool)`:
Forces GotenbergPdf to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
Expand Down
66 changes: 66 additions & 0 deletions docs/pdf/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
[extraHttpHeaders](#extraHttpHeaders)
[addExtraHttpHeaders](#addExtraHttpHeaders)
[failOnHttpStatusCodes](#failOnHttpStatusCodes)
[failOnResourceHttpStatusCodes](#failOnResourceHttpStatusCodes)
[failOnResourceLoadingFailed](#failOnResourceLoadingFailed)
[failOnConsoleExceptions](#failOnConsoleExceptions)
[skipNetworkIdleEvent](#skipNetworkIdleEvent)

Expand Down Expand Up @@ -896,6 +898,70 @@ class YourController
> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium).
### failOnResourceHttpStatusCodes

default: `None`

Return a 409 Conflict response if the HTTP status code from at least one resource
is not acceptable.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg
->html()
->content('content.html.twig', [
'my_var' => 'value'
])
->failOnResourceHttpStatusCodes([401, 403])
->generate()
->stream()
;
}
}
```

> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium).
### failOnResourceLoadingFailed

default: `false`

Return a 409 Conflict response if there are exceptions to load at least one resource
in the Chromium.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg
->html()
->content('content.html.twig', [
'my_var' => 'value'
])
->failOnResourceLoadingFailed()
->generate()
->stream()
;
}
}
```

> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#network-errors-chromium).
### failOnConsoleExceptions

default: `false`
Expand Down
8 changes: 8 additions & 0 deletions docs/screenshot/builders_api/HtmlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ document. (default None).
Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).

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

* `failOnResourceLoadingFailed(bool $bool)`:
Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).

* `failOnConsoleExceptions(bool $bool)`:
Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
Expand Down
8 changes: 8 additions & 0 deletions docs/screenshot/builders_api/MarkdownScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ document. (default None).
Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).

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

* `failOnResourceLoadingFailed(bool $bool)`:
Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).

* `failOnConsoleExceptions(bool $bool)`:
Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
Expand Down
8 changes: 8 additions & 0 deletions docs/screenshot/builders_api/UrlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ document. (default None).
Return a 409 Conflict response if the HTTP status code from
the main page is not acceptable. (default [499,599]). (overrides any previous configuration).

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

* `failOnResourceLoadingFailed(bool $bool)`:
Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions load at least one resource. (default false).

* `failOnConsoleExceptions(bool $bool)`:
Forces GotenbergScreenshot to return a 409 Conflict response if there are
exceptions in the Chromium console. (default false).
Expand Down
66 changes: 66 additions & 0 deletions docs/screenshot/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
[extraHttpHeaders](#extraHttpHeaders)
[addExtraHttpHeaders](#addExtraHttpHeaders)
[failOnHttpStatusCodes](#failOnHttpStatusCodes)
[failOnResourceHttpStatusCodes](#failOnResourceHttpStatusCodes)
[failOnResourceLoadingFailed](#failOnResourceLoadingFailed)
[failOnConsoleExceptions](#failOnConsoleExceptions)
[skipNetworkIdleEvent](#skipNetworkIdleEvent)

Expand Down Expand Up @@ -555,6 +557,70 @@ class YourController
> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium).
### failOnResourceHttpStatusCodes

default: `None`

Return a 409 Conflict response if the HTTP status code from at least one resource
is not acceptable.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg
->html()
->content('content.html.twig', [
'my_var' => 'value'
])
->failOnResourceHttpStatusCodes([401, 403])
->generate()
->stream()
;
}
}
```

> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#invalid-http-status-codes-chromium).
### failOnResourceLoadingFailed

default: `false`

Return a 409 Conflict response if there are exceptions to load at least one resource
in the Chromium.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergPdfInterface;

class YourController
{
public function yourControllerMethod(GotenbergPdfInterface $gotenberg): Response
{
return $gotenberg
->html()
->content('content.html.twig', [
'my_var' => 'value'
])
->failOnResourceLoadingFailed()
->generate()
->stream()
;
}
}
```

> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#network-errors-chromium).
### failOnConsoleExceptions

default: `false`
Expand Down
33 changes: 33 additions & 0 deletions src/Builder/Pdf/AbstractChromiumPdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function __construct(
'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(...)),
];

Expand Down Expand Up @@ -460,6 +463,34 @@ public function failOnHttpStatusCodes(array $statusCodes): static
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<int<100, 599>> $statusCodes
*/
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
*/
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).
Expand Down Expand Up @@ -600,6 +631,8 @@ protected function addConfiguration(string $configurationName, mixed $value): vo
'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),
Expand Down
33 changes: 33 additions & 0 deletions src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public function __construct(
'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(...)),
];

Expand Down Expand Up @@ -283,6 +286,34 @@ public function failOnHttpStatusCodes(array $statusCodes): static
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<int<100, 599>> $statusCodes
*/
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
*/
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).
Expand Down Expand Up @@ -383,6 +414,8 @@ private function addConfiguration(string $configurationName, mixed $value): void
'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),
Expand Down
20 changes: 20 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ private function addChromiumPdfOptionsNode(ArrayNodeDefinition $parent): void
->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()
Expand Down Expand Up @@ -450,6 +460,16 @@ private function addChromiumScreenshotOptionsNode(ArrayNodeDefinition $parent):
->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()
Expand Down
Loading

0 comments on commit ee33766

Please sign in to comment.