-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2812299
commit 558f3dd
Showing
20 changed files
with
111 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.