From 1ac8df566c37b6d08e76fcab4bfd985af14c8f96 Mon Sep 17 00:00:00 2001 From: Dumazeau Date: Wed, 7 Sep 2022 17:02:21 +0200 Subject: [PATCH] Initial commit --- src/Domain/Entity/PdfTemplateConfiguration.php | 1 + src/Domain/Pdf/AbstractPdf.php | 7 ++++--- src/Domain/Pdf/Trait/PdfGeneratorTrait.php | 1 + src/Domain/Pdf/Trait/PdfProtectionTrait.php | 6 +++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Domain/Entity/PdfTemplateConfiguration.php b/src/Domain/Entity/PdfTemplateConfiguration.php index b8207a4..9595a39 100644 --- a/src/Domain/Entity/PdfTemplateConfiguration.php +++ b/src/Domain/Entity/PdfTemplateConfiguration.php @@ -7,6 +7,7 @@ use Doctrine\ORM\Mapping as ORM; use RichId\PdfTemplateBundle\Infrastructure\Repository\PdfTemplateConfigurationRepository; +/** @phpstan-ignore-next-line */ #[ORM\Entity(repositoryClass: PdfTemplateConfigurationRepository::class)] #[ORM\Table(name: 'module_pdf_template_configuration')] class PdfTemplateConfiguration diff --git a/src/Domain/Pdf/AbstractPdf.php b/src/Domain/Pdf/AbstractPdf.php index cd77da2..265ae83 100644 --- a/src/Domain/Pdf/AbstractPdf.php +++ b/src/Domain/Pdf/AbstractPdf.php @@ -43,7 +43,7 @@ abstract class AbstractPdf public ConfigurationInterface $configuration; #[Required] - public FilesystemMap $filesystemMap; + public FilesystemMap $filesystemMap; /* @phpstan-ignore-line */ abstract public function getPdfSlug(): string; @@ -55,6 +55,7 @@ protected function updatePage(Page $page): void { } + /** @return array */ protected function getPdfOptions(): array { return ['printBackground' => true]; @@ -114,13 +115,13 @@ final protected function getPdf(): string $fs = $seveableModel !== null ? $this->filesystemMap->get($seveableModel->getFilesystemName()) : null; - if ($fs !== null && $fs->has($seveableModel->getFileName()) && !$seveableModel->canForceNewGeneration()) { + if ($seveableModel !== null && $fs !== null && $fs->has($seveableModel->getFileName()) && !$seveableModel->canForceNewGeneration()) { return $fs->get($seveableModel->getFileName())->getContent(); } $pdf = $this->generatePdf(); - if ($fs !== null && $seveableModel->canSave()) { + if ($seveableModel !== null && $fs !== null && $seveableModel->canSave()) { $fs->createFile($seveableModel->getFileName())->setContent($pdf); } diff --git a/src/Domain/Pdf/Trait/PdfGeneratorTrait.php b/src/Domain/Pdf/Trait/PdfGeneratorTrait.php index 5d98edf..c74e5d5 100644 --- a/src/Domain/Pdf/Trait/PdfGeneratorTrait.php +++ b/src/Domain/Pdf/Trait/PdfGeneratorTrait.php @@ -14,6 +14,7 @@ trait PdfGeneratorTrait #[Required] public ConfigurationInterface $configuration; + /** @return array */ abstract protected function getPdfOptions(): array; abstract protected function updatePage(Page $page): void; diff --git a/src/Domain/Pdf/Trait/PdfProtectionTrait.php b/src/Domain/Pdf/Trait/PdfProtectionTrait.php index d0b72c1..2740e22 100644 --- a/src/Domain/Pdf/Trait/PdfProtectionTrait.php +++ b/src/Domain/Pdf/Trait/PdfProtectionTrait.php @@ -17,7 +17,11 @@ private function internalProtectPdf(string $pdf): string for ($i = 1; $i <= $pageCount; $i++) { $tplidx = $encoder->importPage($i); $specs = $encoder->getTemplateSize($tplidx); - $encoder->addPage($specs['orientation'], [$specs['width'], $specs['height']]); + + if (\is_array($specs)) { + $encoder->addPage($specs['orientation'], [$specs['width'], $specs['height']]); + } + $encoder->useTemplate($tplidx); }