Skip to content

Commit

Permalink
Add PHP 8.2. Support (#17)
Browse files Browse the repository at this point in the history
### 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
lentex authored Mar 1, 2023
1 parent 9228f25 commit 5742169
Show file tree
Hide file tree
Showing 20 changed files with 904 additions and 539 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ "7.4", "8.0", "8.1" ]
php: [ "8.0", "8.1", "8.2" ]

runs-on: ubuntu-latest
name: PHP@${{ matrix.php }}
Expand All @@ -22,7 +22,7 @@ jobs:
with:
php-version: ${{ matrix.php }}

- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
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
12 changes: 12 additions & 0 deletions changelog.md → CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.0] - 2023-03-01
### 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

## [2.1.0] - 2022-12-07
### Added
- Support for merging PDFs with mixed orientations (portrait and landscape)
Expand Down
29 changes: 27 additions & 2 deletions readme.md → README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<a href="https://www.karriere.at/" target="_blank"><img width="200" src="https://raw.githubusercontent.com/karriereat/.github/main/profile/logo.svg"></a>
<span>&nbsp;&nbsp;&nbsp;</span>
![](https://github.com/karriereat/pdf-merge/workflows/test/badge.svg)
![](https://github.com/karriereat/pdf-merge/workflows/lint/badge.svg)
![](https://github.com/karriereat/pdf-merge/workflows/CI/badge.svg)
[![Packagist Downloads](https://img.shields.io/packagist/dt/karriere/pdf-merge.svg?style=flat-square)](https://packagist.org/packages/karriere/pdf-merge)

# Pdf Merge Solution for PHP

Expand Down Expand Up @@ -37,6 +37,31 @@ You can check if a file was already added for merging by calling:
$pdfMerge->contains('/path/to/file.pdf');
```

### Configuring header and footer
You can also configure the header of footer of all pages like this:

```php
use Karriere\PdfMerge\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,
),
);
```

All config properties have default values, so you don't have to pass them all.

## License

Apache License 2.0 Please see [LICENSE](LICENSE) for more information.
69 changes: 69 additions & 0 deletions UPGRADE.md
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),
),
);
```

28 changes: 18 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
"license": "Apache-2.0",
"authors": [
{
"name": "Johannes Pichler",
"email": "johannes.pichler@karriere.at",
"name": "Alexander Lentner",
"email": "alexander.lentner@karriere.at",
"role": "Maintainer"
}
],
"require": {
"php": "^7.4 | ^8.0",
"php": "8.0.* | 8.1.* | 8.2.*",
"tecnickcom/tcpdf": "^6.3"
},
"require-dev": {
"phpstan/phpstan": "^1.8",
"phpunit/phpunit": "^8.0 || ^9.0",
"squizlabs/php_codesniffer": "^3.0"
"laravel/pint": "^1.5 | ^1.6",
"pestphp/pest": "^1.22",
"phpstan/phpstan": "^1.10"
},
"autoload": {
"psr-4": {
Expand All @@ -35,11 +35,19 @@
}
},
"scripts": {
"test": "phpunit",
"lint": "phpcs src/ --standard=PSR12",
"analyse": "phpstan analyse src --level 5"
"analyse": "phpstan analyse --memory-limit 512M",
"lint": "pint --test",
"lint:verbose": "pint -v --test",
"fix": "pint",
"test": "vendor/bin/pest",
"coverage": "vendor/bin/pest --coverage --ci --coverage-html coverage --coverage-clover coverage.xml --log-junit junit.xml",
"report": "vendor/bin/pest --coverage",
"report:html": "vendor/bin/pest --coverage --coverage-html coverage"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
paths:
- src
level: max
treatPhpDocTypesAsCertain: true
17 changes: 17 additions & 0 deletions phpunit.xml
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>
22 changes: 0 additions & 22 deletions phpunit.xml.dist

This file was deleted.

8 changes: 8 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"preset": "psr12",
"rules": {
"concat_space": {
"spacing": "one"
}
}
}
33 changes: 33 additions & 0 deletions src/Config/FooterConfig.php
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;
}
}
54 changes: 54 additions & 0 deletions src/Config/HeaderConfig.php
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();
}
}
18 changes: 18 additions & 0 deletions src/Config/RGB.php
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];
}
}
Loading

0 comments on commit 5742169

Please sign in to comment.