Skip to content

Commit

Permalink
Fix reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenRenaux committed Oct 12, 2024
1 parent 2812299 commit 558f3dd
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 170 deletions.
3 changes: 3 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ Enabled byd efault but can be disabled via the `sensiolabs_gotenberg.controller_

## download from

> [!WARNING]
> URL of the file. It MUST return a `Content-Disposition` header with a filename parameter.

To download files resource from URLs.

``` yaml
Expand Down
4 changes: 2 additions & 2 deletions docs/pdf/builders_api/HtmlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ Resets the metadata.
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.).

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

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

* `withDownloadFrom(array $formFields, array $downloadFrom)`:

* `addCookies(array $cookies)`:
Add cookies to store in the Chromium cookie jar.

4 changes: 2 additions & 2 deletions docs/pdf/builders_api/LibreOfficePdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ Specify if the resolution of each image is reduced to the resolution specified b
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.

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

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

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

* `withDownloadFrom(array $formFields, array $downloadFrom)`:

4 changes: 2 additions & 2 deletions docs/pdf/builders_api/MarkdownPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ Resets the metadata.
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.).

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

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

* `withDownloadFrom(array $formFields, array $downloadFrom)`:

* `addCookies(array $cookies)`:
Add cookies to store in the Chromium cookie jar.

4 changes: 2 additions & 2 deletions docs/pdf/builders_api/UrlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ Resets the metadata.
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.).

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

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

* `withDownloadFrom(array $formFields, array $downloadFrom)`:

* `addCookies(array $cookies)`:
Add cookies to store in the Chromium cookie jar.

3 changes: 3 additions & 0 deletions docs/pdf/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ class YourController

### download from

> [!WARNING]
> URL of the file. It MUST return a `Content-Disposition` header with a filename parameter.
To download files resource from URLs.

```php
Expand Down
3 changes: 3 additions & 0 deletions docs/pdf/office-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ class YourController
### download from

> [!WARNING]
> URL of the file. It MUST return a `Content-Disposition` header with a filename parameter.
To download files resource from URLs.

```php
Expand Down
4 changes: 2 additions & 2 deletions docs/screenshot/builders_api/HtmlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ Adds additional files, like images, fonts, stylesheets, and so on (overrides any
Adds a file, like an image, font, stylesheet, and so on.

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

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

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

* `withDownloadFrom(array $formFields, array $downloadFrom)`:

* `addCookies(array $cookies)`:
Add cookies to store in the Chromium cookie jar.

4 changes: 2 additions & 2 deletions docs/screenshot/builders_api/MarkdownScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ Adds additional files, like images, fonts, stylesheets, and so on (overrides any
Adds a file, like an image, font, stylesheet, and so on.

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

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

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

* `withDownloadFrom(array $formFields, array $downloadFrom)`:

* `addCookies(array $cookies)`:
Add cookies to store in the Chromium cookie jar.

4 changes: 2 additions & 2 deletions docs/screenshot/builders_api/UrlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ Adds additional files, like images, fonts, stylesheets, and so on (overrides any
Adds a file, like an image, font, stylesheet, and so on.

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

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

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

* `withDownloadFrom(array $formFields, array $downloadFrom)`:

* `addCookies(array $cookies)`:
Add cookies to store in the Chromium cookie jar.

3 changes: 3 additions & 0 deletions docs/screenshot/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class YourController

### download from

> [!WARNING]
> URL of the file. It MUST return a `Content-Disposition` header with a filename parameter.
To download files resource from URLs.

```php
Expand Down
53 changes: 53 additions & 0 deletions src/Builder/DownloadFromTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Sensiolabs\GotenbergBundle\Builder;

use Sensiolabs\GotenbergBundle\Exception\MissingRequiredFieldException;

trait DownloadFromTrait
{
/**
* Sets download from to download each entry (file) in parallel (default None).
* (URLs MUST return a Content-Disposition header with a filename parameter.).
*
* @see https://gotenberg.dev/docs/routes#download-from
*
* @param list<array{url: string, extraHttpHeaders?: array<string, string>}> $downloadFrom
*/
abstract public function downloadFrom(array $downloadFrom): static;

/**
* @param array{downloadFrom?: array<string, array{url: string, extraHttpHeaders?: array<string, string>}>} $formFields
* @param list<array{url: string, extraHttpHeaders?: array<string, string>}> $downloadFrom
*/
public 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;
}

private function downloadFromNormalizer(array $value, callable $encoder): array
{
$downloadsFrom = array_values($value);
$data = [];

array_push($data, ...$downloadsFrom);

return $encoder('downloadFrom', $data);
}
}
25 changes: 0 additions & 25 deletions src/Builder/Pdf/AbstractChromiumPdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,31 +522,6 @@ public function addMetadata(string $key, string $value): static
return $this;
}

/**
* Sets download from to download each entry (file) in parallel (default None).
* (URLs MUST return a Content-Disposition header with a filename parameter.).
*
* @see https://gotenberg.dev/docs/routes#download-from
*
* @param list<array{url: string, extraHttpHeaders: array<string, string>}> $downloadFrom
*/
public function downloadFrom(array $downloadFrom): static
{
if ([] === $downloadFrom) {
unset($this->formFields['downloadFrom']);

return $this;
}

$this->formFields['downloadFrom'] = [];

foreach ($downloadFrom as $file) {
$this->formFields['downloadFrom'][] = $file;
}

return $this;
}

protected function withPdfPartFile(Part $pdfPart, string $path): static
{
$dataPart = new DataPart(
Expand Down
14 changes: 11 additions & 3 deletions src/Builder/Pdf/AbstractPdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
namespace Sensiolabs\GotenbergBundle\Builder\Pdf;

use Sensiolabs\GotenbergBundle\Builder\DefaultBuilderTrait;
use Sensiolabs\GotenbergBundle\Builder\DownloadFromTrait;
use Sensiolabs\GotenbergBundle\Client\GotenbergClientInterface;
use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter;

abstract class AbstractPdfBuilder implements PdfBuilderInterface
{
use DefaultBuilderTrait;
use DownloadFromTrait;

public function __construct(
GotenbergClientInterface $gotenbergClient,
Expand All @@ -21,9 +23,15 @@ public function __construct(
'metadata' => function (mixed $value): array {
return $this->encodeData('metadata', $value);
},
'downloadFrom' => function (mixed $value): array {
return $this->encodeData('downloadFrom', $value);
},
'downloadFrom' => fn (array $value): array => $this->downloadFromNormalizer($value, $this->encodeData(...)),
];
}

/**
* @param list<array{url: string, extraHttpHeaders: array<string, string>}> $downloadFrom
*/
public function downloadFrom(array $downloadFrom): static
{
return $this->withDownloadFrom($this->formFields, $downloadFrom);
}
}
25 changes: 0 additions & 25 deletions src/Builder/Pdf/ConvertPdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,6 @@ public function getMultipartFormData(): array
return parent::getMultipartFormData();
}

/**
* Sets download from to download each entry (file) in parallel (default None).
* (URLs MUST return a Content-Disposition header with a filename parameter.).
*
* @see https://gotenberg.dev/docs/routes#download-from
*
* @param list<array{url: string, extraHttpHeaders: array<string, string>}> $downloadFrom
*/
public function downloadFrom(array $downloadFrom): static
{
if ([] === $downloadFrom) {
unset($this->formFields['downloadFrom']);

return $this;
}

$this->formFields['downloadFrom'] = [];

foreach ($downloadFrom as $file) {
$this->formFields['downloadFrom'][] = $file;
}

return $this;
}

protected function getEndpoint(): string
{
return self::ENDPOINT;
Expand Down
27 changes: 1 addition & 26 deletions src/Builder/Pdf/LibreOfficePdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function setConfigurations(array $configurations): static
/**
* Set the password for opening the source file.
*/
public function password(string $password): self
public function password(#[\SensitiveParameter] string $password): self
{
$this->formFields['password'] = $password;

Expand Down Expand Up @@ -347,31 +347,6 @@ public function getMultipartFormData(): array
return parent::getMultipartFormData();
}

/**
* Sets download from to download each entry (file) in parallel (default None).
* (URLs MUST return a Content-Disposition header with a filename parameter.).
*
* @see https://gotenberg.dev/docs/routes#download-from
*
* @param list<array{url: string, extraHttpHeaders: array<string, string>}> $downloadFrom
*/
public function downloadFrom(array $downloadFrom): self
{
if ([] === $downloadFrom) {
unset($this->formFields['downloadFrom']);

return $this;
}

$this->formFields['downloadFrom'] = [];

foreach ($downloadFrom as $file) {
$this->formFields['downloadFrom'][] = $file;
}

return $this;
}

protected function getEndpoint(): string
{
return self::ENDPOINT;
Expand Down
25 changes: 0 additions & 25 deletions src/Builder/Pdf/MergePdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,6 @@ public function getMultipartFormData(): array
return parent::getMultipartFormData();
}

/**
* Sets download from to download each entry (file) in parallel (default None).
* (URLs MUST return a Content-Disposition header with a filename parameter.).
*
* @see https://gotenberg.dev/docs/routes#download-from
*
* @param list<array{url: string, extraHttpHeaders: array<string, string>}> $downloadFrom
*/
public function downloadFrom(array $downloadFrom): static
{
if ([] === $downloadFrom) {
unset($this->formFields['downloadFrom']);

return $this;
}

$this->formFields['downloadFrom'] = [];

foreach ($downloadFrom as $file) {
$this->formFields['downloadFrom'][] = $file;
}

return $this;
}

protected function getEndpoint(): string
{
return self::ENDPOINT;
Expand Down
Loading

0 comments on commit 558f3dd

Please sign in to comment.