-
Notifications
You must be signed in to change notification settings - Fork 12
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
Showing
17 changed files
with
399 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
use Sensiolabs\GotenbergBundle\Builder\AbstractBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
use function Symfony\Component\DependencyInjection\Loader\Configurator\service; | ||
|
||
return static function (ContainerConfigurator $container): void { | ||
$services = $container->services(); | ||
|
||
$services->defaults() | ||
->tag('monolog.logger', ['channel' => 'sensiolabs_gotenberg']) | ||
; | ||
|
||
$services->set('.sensiolabs_gotenberg.abstract_builder', AbstractBuilder::class) | ||
->abstract() | ||
->args([ | ||
service('sensiolabs_gotenberg.client'), | ||
service('sensiolabs_gotenberg.asset.base_dir_formatter'), | ||
]) | ||
; | ||
}; |
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,60 @@ | ||
<?php | ||
|
||
namespace Sensiolabs\GotenbergBundle\Builder\Behaviors; | ||
|
||
use Sensiolabs\GotenbergBundle\Client\BodyBag; | ||
use Sensiolabs\GotenbergBundle\Enumeration\PdfFormat; | ||
use Sensiolabs\GotenbergBundle\Exception\JsonEncodingException; | ||
use Symfony\Component\OptionsResolver\Options; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @see https://gotenberg.dev/docs/routes#pdfa-chromium | ||
*/ | ||
trait MetadataTrait | ||
{ | ||
abstract protected function getBodyBag(): BodyBag; | ||
|
||
protected function configure(OptionsResolver $bodyOptionsResolver, OptionsResolver $headersOptionsResolver): void | ||
{ | ||
$bodyOptionsResolver | ||
->define('metadata') | ||
->info('Add metadata.') | ||
->normalize(function (Options $options, mixed $value): string { | ||
try { | ||
return json_encode($value, \JSON_THROW_ON_ERROR); | ||
} catch (\JsonException $exception) { | ||
throw new JsonEncodingException(\sprintf('Could not encode property "%s" into JSON', $key), previous: $exception); | ||
} | ||
}) | ||
; | ||
} | ||
|
||
/** | ||
* Resets the metadata. | ||
* | ||
* @see https://gotenberg.dev/docs/routes#metadata-chromium | ||
* @see https://gotenberg.dev/docs/routes#metadata-libreoffice | ||
* @see https://gotenberg.dev/docs/routes#write-pdf-metadata-route | ||
* @see https://gotenberg.dev/docs/routes#merge-pdfs-route | ||
* @see https://exiftool.org/TagNames/XMP.html#pdf | ||
* | ||
* @param array<string, mixed> $metadata | ||
*/ | ||
public function metadata(array $metadata): static | ||
{ | ||
$this->getBodyBag()->set('metadata', $metadata); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* The metadata to write. | ||
*/ | ||
public function addMetadata(string $key, string $value): static | ||
{ | ||
$this->getBodyBag()->set('metadata', [$key => $value] + $this->getBodyBag()->get('metadata', [])); | ||
|
||
return $this; | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace Sensiolabs\GotenbergBundle\Builder\Behaviors; | ||
|
||
use Sensiolabs\GotenbergBundle\Client\BodyBag; | ||
use Sensiolabs\GotenbergBundle\Enumeration\PdfFormat; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
/** | ||
* @see https://gotenberg.dev/docs/routes#pdfa-chromium | ||
*/ | ||
trait PdfFormatTrait | ||
{ | ||
abstract protected function getBodyBag(): BodyBag; | ||
|
||
protected function configure(OptionsResolver $bodyOptionsResolver, OptionsResolver $headersOptionsResolver): void | ||
{ | ||
$bodyOptionsResolver | ||
->define('pdfa') | ||
->info('Convert the resulting PDF into the given PDF/A format.') | ||
->allowedValues( | ||
...array_map(fn (PdfFormat $p): string => $p->value, PdfFormat::cases()), | ||
) | ||
; | ||
$bodyOptionsResolver | ||
->define('pdfua') | ||
->info('Enable PDF for Universal Access for optimal accessibility.') | ||
->allowedTypes('bool') | ||
; | ||
} | ||
|
||
/** | ||
* Convert the resulting PDF into the given PDF/A format. | ||
*/ | ||
public function pdfFormat(PdfFormat $format): self | ||
{ | ||
$this->getBodyBag()->set('pdfa', $format->value); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Enable PDF for Universal Access for optimal accessibility. | ||
*/ | ||
public function pdfUniversalAccess(bool $bool = true): self | ||
{ | ||
$this->getBodyBag()->set('pdfua', $bool); | ||
|
||
return $this; | ||
} | ||
} |
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.