From ff4cf528b1ac415fd0e7748a073831ff5094f0d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Nov 2022 23:31:40 +0000 Subject: [PATCH 1/7] Bump ramsey/composer-install from 1 to 2 Bumps [ramsey/composer-install](https://github.com/ramsey/composer-install) from 1 to 2. - [Release notes](https://github.com/ramsey/composer-install/releases) - [Commits](https://github.com/ramsey/composer-install/compare/v1...v2) --- updated-dependencies: - dependency-name: ramsey/composer-install dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/phpstan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 977b975..980cb79 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -20,7 +20,7 @@ jobs: coverage: none - name: Install composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 - name: Run PHPStan run: ./vendor/bin/phpstan --error-format=github From 9812b234f639f33408cd1164851a020274465815 Mon Sep 17 00:00:00 2001 From: sten Date: Wed, 5 Apr 2023 12:54:48 +0000 Subject: [PATCH 2/7] Fix styling --- src/Exceptions/ConfigurationException.php | 20 +- src/Exceptions/ConversionException.php | 20 +- src/Exceptions/InvalidMarginUnitException.php | 8 +- src/Exceptions/PdfApiException.php | 18 +- src/Exceptions/TimeoutException.php | 20 +- .../UnsuccessfulHttpResponseException.php | 56 +- src/Options/PdfOptions.php | 478 +++++++++--------- src/Options/PdfPageMargin.php | 56 +- 8 files changed, 338 insertions(+), 338 deletions(-) diff --git a/src/Exceptions/ConfigurationException.php b/src/Exceptions/ConfigurationException.php index a70e6e2..6145c39 100644 --- a/src/Exceptions/ConfigurationException.php +++ b/src/Exceptions/ConfigurationException.php @@ -1,16 +1,16 @@ field = $field; + public static function create(string $field): self + { + $exception = new ConfigurationException("The Laravel Puppeteer PDF Converter library is not properly configured. Check if $field is properly configured."); + $exception->field = $field; - return $exception; - } + return $exception; } +} diff --git a/src/Exceptions/ConversionException.php b/src/Exceptions/ConversionException.php index c96f725..a72f0f1 100644 --- a/src/Exceptions/ConversionException.php +++ b/src/Exceptions/ConversionException.php @@ -1,15 +1,15 @@ message = $apiErrorFields['message']; - } - - return $this; + if (array_key_exists('message', $apiErrorFields)) { + $this->message = $apiErrorFields['message']; } + + return $this; } +} diff --git a/src/Exceptions/TimeoutException.php b/src/Exceptions/TimeoutException.php index 632c5be..f70e5e9 100644 --- a/src/Exceptions/TimeoutException.php +++ b/src/Exceptions/TimeoutException.php @@ -1,15 +1,15 @@ websiteStatusCode = $apiErrorFields['websiteStatusCode']; - } + protected $websiteStatusCode = null; - return $this; + public function setApiError(array $apiErrorFields): parent + { + parent::setApiError($apiErrorFields); + if (array_key_exists('websiteStatusCode', $apiErrorFields)) { + $this->websiteStatusCode = $apiErrorFields['websiteStatusCode']; } - /** - * Returns the HTTP status code that was returned by the webpage url that was requested to be converted. - * @return int - */ - public function getWebsiteStatusCode(): int - { - return $this->websiteStatusCode; - } + return $this; + } + + /** + * Returns the HTTP status code that was returned by the webpage url that was requested to be converted. + * @return int + */ + public function getWebsiteStatusCode(): int + { + return $this->websiteStatusCode; } +} diff --git a/src/Options/PdfOptions.php b/src/Options/PdfOptions.php index 77f7320..4df8cd3 100644 --- a/src/Options/PdfOptions.php +++ b/src/Options/PdfOptions.php @@ -1,281 +1,281 @@ setPdfOptionsFromConfig(); - } - - private function setPdfOptionsFromConfig(): void - { - $this->width = $this->getPdfOptionFromConfig('pdf_width'); - $this->height = $this->getPdfOptionFromConfig('pdf_height'); - $this->scale = $this->getPdfOptionFromConfig('pdf_scale'); - $this->pageMarginTop = $this->getPdfMarginFromConfig('paper_margin_top'); - $this->pageMarginBottom = $this->getPdfMarginFromConfig('paper_margin_bottom'); - $this->pageMarginLeft = $this->getPdfMarginFromConfig('paper_margin_left'); - $this->pageMarginRight = $this->getPdfMarginFromConfig('paper_margin_right'); - } + //set default the configuration PDF options and allow override with setters. + $this->setPdfOptionsFromConfig(); + } - /** - * Adds a configuration if it exists, to the PDF options array for the API. - * @param string $configKey - * @return int|string|null - */ - private function getPdfOptionFromConfig(string $configKey) - { - $configField = "puppeteer-pdf-converter.$configKey"; + private function setPdfOptionsFromConfig(): void + { + $this->width = $this->getPdfOptionFromConfig('pdf_width'); + $this->height = $this->getPdfOptionFromConfig('pdf_height'); + $this->scale = $this->getPdfOptionFromConfig('pdf_scale'); + $this->pageMarginTop = $this->getPdfMarginFromConfig('paper_margin_top'); + $this->pageMarginBottom = $this->getPdfMarginFromConfig('paper_margin_bottom'); + $this->pageMarginLeft = $this->getPdfMarginFromConfig('paper_margin_left'); + $this->pageMarginRight = $this->getPdfMarginFromConfig('paper_margin_right'); + } - return config($configField, null); - } + /** + * Adds a configuration if it exists, to the PDF options array for the API. + * @param string $configKey + * @return int|string|null + */ + private function getPdfOptionFromConfig(string $configKey) + { + $configField = "puppeteer-pdf-converter.$configKey"; - private function getPdfMarginFromConfig(string $configKey): ?PdfPageMargin - { - $marginFromConfig = $this->getPdfOptionFromConfig($configKey); + return config($configField, null); + } - if ($marginFromConfig) { - $margin = $this->parsePdfMarginFromConfigString($marginFromConfig, PdfPageMargin::MARGIN_IN_PIXELS); - if (! $margin) { - $margin = $this->parsePdfMarginFromConfigString($marginFromConfig, PdfPageMargin::MARGIN_IN_CM); - } + private function getPdfMarginFromConfig(string $configKey): ?PdfPageMargin + { + $marginFromConfig = $this->getPdfOptionFromConfig($configKey); - return $margin; + if ($marginFromConfig) { + $margin = $this->parsePdfMarginFromConfigString($marginFromConfig, PdfPageMargin::MARGIN_IN_PIXELS); + if (! $margin) { + $margin = $this->parsePdfMarginFromConfigString($marginFromConfig, PdfPageMargin::MARGIN_IN_CM); } - return null; + return $margin; } - private function parsePdfMarginFromConfigString(string $marginFromConfig, string $marginUnit): ?PdfPageMargin - { - if ($marginFromConfig) { - if (strpos($marginFromConfig, $marginUnit) !== false) { - $margin = strstr($marginFromConfig, $marginUnit, true); + return null; + } - return new PdfPageMargin($margin, $marginUnit); - } - } + private function parsePdfMarginFromConfigString(string $marginFromConfig, string $marginUnit): ?PdfPageMargin + { + if ($marginFromConfig) { + if (strpos($marginFromConfig, $marginUnit) !== false) { + $margin = strstr($marginFromConfig, $marginUnit, true); - return null; + return new PdfPageMargin($margin, $marginUnit); + } } - /** - * Returns the PDF option in an array formatted as query strings for the API. - * @return array - */ - public function getApiPdfOptions(): array - { - $options = []; - if ($this->width) { - $options['width'] = $this->width; - } - if ($this->height) { - $options['height'] = $this->height; - } - if ($this->scale) { - $options['scale'] = $this->scale; - } - if ($this->pageMarginTop) { - $options['paper_margin_top'] = $this->pageMarginTop->getApiValue(); - } - if ($this->pageMarginBottom) { - $options['paper_margin_bottom'] = $this->pageMarginBottom->getApiValue(); - } - if ($this->pageMarginLeft) { - $options['paper_margin_left'] = $this->pageMarginLeft->getApiValue(); - } - if ($this->pageMarginRight) { - $options['paper_margin_right'] = $this->pageMarginRight->getApiValue(); - } + return null; + } - return $options; + /** + * Returns the PDF option in an array formatted as query strings for the API. + * @return array + */ + public function getApiPdfOptions(): array + { + $options = []; + if ($this->width) { + $options['width'] = $this->width; + } + if ($this->height) { + $options['height'] = $this->height; + } + if ($this->scale) { + $options['scale'] = $this->scale; + } + if ($this->pageMarginTop) { + $options['paper_margin_top'] = $this->pageMarginTop->getApiValue(); + } + if ($this->pageMarginBottom) { + $options['paper_margin_bottom'] = $this->pageMarginBottom->getApiValue(); + } + if ($this->pageMarginLeft) { + $options['paper_margin_left'] = $this->pageMarginLeft->getApiValue(); + } + if ($this->pageMarginRight) { + $options['paper_margin_right'] = $this->pageMarginRight->getApiValue(); } - //GETTERS & SETTERS: + return $options; + } - /** - * @return int - */ - public function getWidth(): int - { - return $this->width; - } + //GETTERS & SETTERS: - /** - * @param int $width - * @return PdfOptions - */ - public function setWidth(int $width): self - { - $this->width = $width; + /** + * @return int + */ + public function getWidth(): int + { + return $this->width; + } - return $this; - } + /** + * @param int $width + * @return PdfOptions + */ + public function setWidth(int $width): self + { + $this->width = $width; - /** - * @return int - */ - public function getHeight(): int - { - return $this->height; - } + return $this; + } - /** - * @param int $height - * @return PdfOptions - */ - public function setHeight(int $height): self - { - $this->height = $height; + /** + * @return int + */ + public function getHeight(): int + { + return $this->height; + } - return $this; - } + /** + * @param int $height + * @return PdfOptions + */ + public function setHeight(int $height): self + { + $this->height = $height; - /** - * @return float - */ - public function getScale(): float - { - return $this->scale; - } + return $this; + } - /** - * @param float $scale - * @return PdfOptions - */ - public function setScale(float $scale): self - { - $this->scale = $scale; + /** + * @return float + */ + public function getScale(): float + { + return $this->scale; + } - return $this; - } + /** + * @param float $scale + * @return PdfOptions + */ + public function setScale(float $scale): self + { + $this->scale = $scale; - /** - * Sets all page margins at once. - * @param PdfPageMargin $pageMargin - * @return $this - */ - public function setPageMargins(PdfPageMargin $pageMargin): self - { - $this->setPageMarginTop($pageMargin); - $this->setPageMarginBottom($pageMargin); - $this->setPageMarginLeft($pageMargin); - $this->setPageMarginRight($pageMargin); - - return $this; - } + return $this; + } - /** - * @return PdfPageMargin - */ - public function getPageMarginTop(): PdfPageMargin - { - return $this->pageMarginTop; - } + /** + * Sets all page margins at once. + * @param PdfPageMargin $pageMargin + * @return $this + */ + public function setPageMargins(PdfPageMargin $pageMargin): self + { + $this->setPageMarginTop($pageMargin); + $this->setPageMarginBottom($pageMargin); + $this->setPageMarginLeft($pageMargin); + $this->setPageMarginRight($pageMargin); - /** - * @param PdfPageMargin $pageMarginTop - * @return PdfOptions - */ - public function setPageMarginTop(PdfPageMargin $pageMarginTop): self - { - $this->pageMarginTop = $pageMarginTop; + return $this; + } - return $this; - } + /** + * @return PdfPageMargin + */ + public function getPageMarginTop(): PdfPageMargin + { + return $this->pageMarginTop; + } - /** - * @return PdfPageMargin - */ - public function getPageMarginBottom(): PdfPageMargin - { - return $this->pageMarginBottom; - } + /** + * @param PdfPageMargin $pageMarginTop + * @return PdfOptions + */ + public function setPageMarginTop(PdfPageMargin $pageMarginTop): self + { + $this->pageMarginTop = $pageMarginTop; - /** - * @param PdfPageMargin $pageMarginBottom - * @return PdfOptions - */ - public function setPageMarginBottom(PdfPageMargin $pageMarginBottom): self - { - $this->pageMarginBottom = $pageMarginBottom; + return $this; + } - return $this; - } + /** + * @return PdfPageMargin + */ + public function getPageMarginBottom(): PdfPageMargin + { + return $this->pageMarginBottom; + } - /** - * @return PdfPageMargin - */ - public function getPageMarginLeft(): PdfPageMargin - { - return $this->pageMarginLeft; - } + /** + * @param PdfPageMargin $pageMarginBottom + * @return PdfOptions + */ + public function setPageMarginBottom(PdfPageMargin $pageMarginBottom): self + { + $this->pageMarginBottom = $pageMarginBottom; - /** - * @param PdfPageMargin $pageMarginLeft - * @return PdfOptions - */ - public function setPageMarginLeft(PdfPageMargin $pageMarginLeft): self - { - $this->pageMarginLeft = $pageMarginLeft; + return $this; + } - return $this; - } + /** + * @return PdfPageMargin + */ + public function getPageMarginLeft(): PdfPageMargin + { + return $this->pageMarginLeft; + } - /** - * @return PdfPageMargin - */ - public function getPageMarginRight(): PdfPageMargin - { - return $this->pageMarginRight; - } + /** + * @param PdfPageMargin $pageMarginLeft + * @return PdfOptions + */ + public function setPageMarginLeft(PdfPageMargin $pageMarginLeft): self + { + $this->pageMarginLeft = $pageMarginLeft; - /** - * @param PdfPageMargin $pageMarginRight - * @return PdfOptions - */ - public function setPageMarginRight(PdfPageMargin $pageMarginRight): self - { - $this->pageMarginRight = $pageMarginRight; + return $this; + } - return $this; - } + /** + * @return PdfPageMargin + */ + public function getPageMarginRight(): PdfPageMargin + { + return $this->pageMarginRight; + } + + /** + * @param PdfPageMargin $pageMarginRight + * @return PdfOptions + */ + public function setPageMarginRight(PdfPageMargin $pageMarginRight): self + { + $this->pageMarginRight = $pageMarginRight; + + return $this; } +} diff --git a/src/Options/PdfPageMargin.php b/src/Options/PdfPageMargin.php index e748f23..aa1f464 100644 --- a/src/Options/PdfPageMargin.php +++ b/src/Options/PdfPageMargin.php @@ -1,36 +1,36 @@ margin = $margin; - $this->unit = $unit; + if ($unit !== self::MARGIN_IN_CM && $unit !== self::MARGIN_IN_PIXELS) { + throw new InvalidMarginUnitException("The margin unit is not accepted: $unit"); } - public function getApiValue(): string - { - return $this->margin . $this->unit; - } + $this->margin = $margin; + $this->unit = $unit; + } + + public function getApiValue(): string + { + return $this->margin . $this->unit; } +} From 50e48e861f4b5c0a800173896f7f9b0cf44e7664 Mon Sep 17 00:00:00 2001 From: sten Date: Wed, 5 Apr 2023 12:56:22 +0000 Subject: [PATCH 3/7] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82b77c4..bbf7047 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `statikbe/laravel-puppeteer-pdf-converter` will be documented in this file. +## v1.2.0 - 2023-04-05 + +Laravel 10 support + ## v1.1.0 - 2022-10-11 - Fix bug in convertRoute to pass PdfOptions From 41a154fd0e3ffc3dfbc04aeb2a8af0cac4f4d04d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Apr 2023 23:58:20 +0000 Subject: [PATCH 4/7] Bump dependabot/fetch-metadata from 1.3.6 to 1.4.0 Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.3.6 to 1.4.0. - [Release notes](https://github.com/dependabot/fetch-metadata/releases) - [Commits](https://github.com/dependabot/fetch-metadata/compare/v1.3.6...v1.4.0) --- updated-dependencies: - dependency-name: dependabot/fetch-metadata dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/dependabot-auto-merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 32f7754..8fc6538 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -13,7 +13,7 @@ jobs: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v1.3.6 + uses: dependabot/fetch-metadata@v1.4.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" From b02e3396d32f7dd13be6fdbe9fb76447f36330aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 May 2023 23:58:07 +0000 Subject: [PATCH 5/7] Bump dependabot/fetch-metadata from 1.4.0 to 1.5.0 Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.4.0 to 1.5.0. - [Release notes](https://github.com/dependabot/fetch-metadata/releases) - [Commits](https://github.com/dependabot/fetch-metadata/compare/v1.4.0...v1.5.0) --- updated-dependencies: - dependency-name: dependabot/fetch-metadata dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/dependabot-auto-merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 8fc6538..950d114 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -13,7 +13,7 @@ jobs: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v1.4.0 + uses: dependabot/fetch-metadata@v1.5.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" From 776cf8e9538ecd29ee6ee051f5bce043593fb367 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 May 2023 23:58:00 +0000 Subject: [PATCH 6/7] Bump dependabot/fetch-metadata from 1.5.0 to 1.5.1 Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.5.0 to 1.5.1. - [Release notes](https://github.com/dependabot/fetch-metadata/releases) - [Commits](https://github.com/dependabot/fetch-metadata/compare/v1.5.0...v1.5.1) --- updated-dependencies: - dependency-name: dependabot/fetch-metadata dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/dependabot-auto-merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 950d114..4af8e6b 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -13,7 +13,7 @@ jobs: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v1.5.0 + uses: dependabot/fetch-metadata@v1.5.1 with: github-token: "${{ secrets.GITHUB_TOKEN }}" From f915152bb26f4825daedf516d9d426fd882cc6ab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:37:15 +0000 Subject: [PATCH 7/7] Bump dependabot/fetch-metadata from 1.5.1 to 1.6.0 Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.5.1 to 1.6.0. - [Release notes](https://github.com/dependabot/fetch-metadata/releases) - [Commits](https://github.com/dependabot/fetch-metadata/compare/v1.5.1...v1.6.0) --- updated-dependencies: - dependency-name: dependabot/fetch-metadata dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/dependabot-auto-merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 4af8e6b..ca2197d 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -13,7 +13,7 @@ jobs: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v1.5.1 + uses: dependabot/fetch-metadata@v1.6.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}"