-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Added - Support for PHP 8.2 ### Changed - [BREAKING] Header and footer config with dedicated classes instead of arrays - Linting to `pint` - Unit tests to `pest` ### Removed - Support for PHP 7.4
- Loading branch information
Showing
20 changed files
with
904 additions
and
539 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
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
vendor/ | ||
coverage/ | ||
tests/output.pdf | ||
.phpunit.result.cache | ||
composer.lock | ||
coverage.xml | ||
junit.xml |
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,69 @@ | ||
# Upgrade Guide | ||
|
||
## v2 to v3 | ||
The only breaking chance in this release is the way a header and/or footer configuration is done. | ||
In version 2 this was done with simple arrays, in v3 dedicated classes were introduced to make the | ||
configuration type safe and bullet proof. | ||
|
||
### Header/Footer Configuration | ||
```php | ||
// Before | ||
use Karriere\PdfMerge\PdfMerge; | ||
|
||
new PdfMerge([ | ||
'ln' => 'header_logo.png', | ||
'lw' => 20, | ||
'ht' => 'title', | ||
'hs' => 'more text', | ||
'tc' => [255, 255, 255], | ||
'lc' => [0, 0, 0]. | ||
], | ||
[ | ||
'tc' => [255, 255, 255], | ||
'lc' => [0, 0, 0]. | ||
]); | ||
|
||
// After | ||
use Karriere\PdfMerge\Config\FooterConfig; | ||
use Karriere\PdfMerge\Config\HeaderConfig; | ||
use Karriere\PdfMerge\Config\RGB; | ||
use Karriere\PdfMerge\PdfMerge; | ||
|
||
new PdfMerge( | ||
new HeaderConfig( | ||
imagePath: 'header_logo.png', | ||
logoWidthMM: 20, | ||
title: 'Header', | ||
text: 'This is a header text', | ||
textColor: new RGB(200, 200, 200), | ||
lineColor: new RGB(0, 0, 255), | ||
), | ||
new FooterConfig( | ||
textColor: new RGB(100, 100, 100), | ||
lineColor: new RGB(255, 0, 0), | ||
margin: 20, | ||
), | ||
); | ||
``` | ||
|
||
The above example shows the full feature set of header/footer configuration, but when using named arguments you can | ||
choose a subset of configuration values as well because all other values have defaults in place: | ||
|
||
```php | ||
use Karriere\PdfMerge\Config\FooterConfig; | ||
use Karriere\PdfMerge\Config\HeaderConfig; | ||
use Karriere\PdfMerge\Config\RGB; | ||
use Karriere\PdfMerge\PdfMerge; | ||
|
||
new PdfMerge( | ||
new HeaderConfig( | ||
imagePath: 'header_logo.png', | ||
text: 'This is a header text', | ||
textColor: new RGB(200, 200, 200), | ||
), | ||
new FooterConfig( | ||
lineColor: new RGB(255, 0, 0), | ||
), | ||
); | ||
``` | ||
|
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,5 @@ | ||
parameters: | ||
paths: | ||
- src | ||
level: max | ||
treatPhpDocTypesAsCertain: true |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
colors="true" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Pdf Merge Test Suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
{ | ||
"preset": "psr12", | ||
"rules": { | ||
"concat_space": { | ||
"spacing": "one" | ||
} | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Karriere\PdfMerge\Config; | ||
|
||
class FooterConfig | ||
{ | ||
/** | ||
* @param ?RGB $textColor RGB array color for text | ||
* @param ?RGB $lineColor RGB array color for line | ||
* @param int $margin minimum distance (in "user units") between footer and bottom page margin | ||
*/ | ||
public function __construct( | ||
private ?RGB $textColor = null, | ||
private ?RGB $lineColor = null, | ||
private int $margin = 0, | ||
) { | ||
} | ||
|
||
public function textColor(): RGB | ||
{ | ||
return $this->textColor ?: new RGB(); | ||
} | ||
|
||
public function lineColor(): RGB | ||
{ | ||
return $this->lineColor ?: new RGB(); | ||
} | ||
|
||
public function margin(): int | ||
{ | ||
return $this->margin; | ||
} | ||
} |
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,54 @@ | ||
<?php | ||
|
||
namespace Karriere\PdfMerge\Config; | ||
|
||
class HeaderConfig | ||
{ | ||
/** | ||
* @param string $imagePath header image logo | ||
* @param int $logoWidthMM header image logo width in mm | ||
* @param string $title string to print as title on document header | ||
* @param string $text string to print on document header | ||
* @param ?RGB $textColor RGB array color for text | ||
* @param ?RGB $lineColor RGB array color for line | ||
*/ | ||
public function __construct( | ||
private string $imagePath = '', | ||
private int $logoWidthMM = 0, | ||
private string $title = '', | ||
private string $text = '', | ||
private ?RGB $textColor = null, | ||
private ?RGB $lineColor = null, | ||
) { | ||
} | ||
|
||
public function imagePath(): string | ||
{ | ||
return $this->imagePath; | ||
} | ||
|
||
public function logoWidthMM(): int | ||
{ | ||
return $this->logoWidthMM; | ||
} | ||
|
||
public function title(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function text(): string | ||
{ | ||
return $this->text; | ||
} | ||
|
||
public function textColor(): RGB | ||
{ | ||
return $this->textColor ?: new RGB(); | ||
} | ||
|
||
public function lineColor(): RGB | ||
{ | ||
return $this->lineColor ?: new RGB(); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Karriere\PdfMerge\Config; | ||
|
||
class RGB | ||
{ | ||
public function __construct(private int $red = 0, private int $green = 0, private int $blue = 0) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<int> | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [$this->red, $this->green, $this->blue]; | ||
} | ||
} |
Oops, something went wrong.