Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dumazeau committed Sep 7, 2022
1 parent a4fe174 commit 1ac8df5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Domain/Entity/PdfTemplateConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/Domain/Pdf/AbstractPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -55,6 +55,7 @@ protected function updatePage(Page $page): void
{
}

/** @return array<string, mixed> */
protected function getPdfOptions(): array
{
return ['printBackground' => true];
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/Domain/Pdf/Trait/PdfGeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ trait PdfGeneratorTrait
#[Required]
public ConfigurationInterface $configuration;

/** @return array<string, mixed> */
abstract protected function getPdfOptions(): array;
abstract protected function updatePage(Page $page): void;

Expand Down
6 changes: 5 additions & 1 deletion src/Domain/Pdf/Trait/PdfProtectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1ac8df5

Please sign in to comment.