Skip to content

Commit

Permalink
Add MAX_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
Dumazeau committed Dec 15, 2022
1 parent a08b27c commit 26732da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Domain/Pdf/AbstractPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ abstract class AbstractPdf
protected const TEMPLATING_FOLDER = 'pdf';
protected const MODIFICATION_ALLOWED = true;
protected const OTHER_PAGES = [];
protected const MAX_TIMEOUT = 10000;

#[Required]
public TemplatingInterface $templating;
Expand Down Expand Up @@ -114,7 +115,7 @@ protected function skippedIf(): bool

final protected function generatePdf(): string
{
$pdf = $this->internalGeneratePdf($this->getContent());
$pdf = $this->internalGeneratePdf($this->getContent(), static::MAX_TIMEOUT);
$othersPages = $this->generateOtherPages();

if (!empty($othersPages)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Domain/Pdf/Trait/PdfGeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ trait PdfGeneratorTrait
abstract protected function getPdfOptions(): array;
abstract protected function updatePage(Page $page): void;

private function internalGeneratePdf(string $content): string
private function internalGeneratePdf(string $content, int $timeout = 10000): string
{
$browserFactory = new BrowserFactory($this->configuration->getChromeBinary());
$browser = $browserFactory->createBrowser(['customFlags' => $this->configuration->getChromeCustomFlags()]);

try {
$page = $browser->createPage();
$page->setHtml($content);
$page->setHtml($content, $timeout);
$this->updatePage($page);
$pdf = \base64_decode($page->pdf($this->getPdfOptions())->getBase64());

Expand Down

0 comments on commit 26732da

Please sign in to comment.