Skip to content

Commit 29e8378

Browse files
committed
Merge branch 'release/3.1.0'
2 parents 04c20ca + 4efdc40 commit 29e8378

File tree

7 files changed

+44
-78
lines changed

7 files changed

+44
-78
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [3.1.0] - 2022-08-24
8+
### Changed
9+
- Upgraded DomPDF library to version 2
10+
- Upgraded other dependences
11+
- Raised minimum PHP version to 7
12+
713
## [3.0.0] - 2021-06-01
814
### Changed
915
- Refactored logic for pdf attachment files

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This library offers an easy-to-use API for PDF generation and merging.
77

88
Requirements
99
------------
10-
- PHP >= 5.6
10+
- PHP >= 7
1111

1212
Usage
1313
-----

composer.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,24 @@
2525
}
2626
},
2727
"require": {
28-
"php": "^5.6|^7|^8",
29-
"dompdf/dompdf": "^0.8|^1.0",
28+
"php": "^7|^8",
29+
"dompdf/dompdf": "^2.0",
3030
"setasign/fpdi": "^2.0",
3131
"tecnickcom/tcpdf": "^6.4"
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": "^7",
35-
"phpstan/phpstan": "^0.12.11",
36-
"phpstan/phpstan-phpunit": "^0.12.6",
37-
"roave/backward-compatibility-check": "^5.0"
34+
"phpunit/phpunit": "^9",
35+
"phpstan/phpstan": "^1.8",
36+
"phpstan/phpstan-phpunit": "^1.1",
37+
"roave/backward-compatibility-check": "^7.0"
3838
},
3939
"suggest": {
4040
"vianetz/signaturportal-api": "Use this library to sign your generated PDF documents.",
4141
"zf1/zend-pdf": "Necessary if you want to use Zend_Pdf for merging. By default this package uses the fpdi merger."
42+
},
43+
"config": {
44+
"allow-plugins": {
45+
"ocramius/package-versions": true
46+
}
4247
}
4348
}

src/Model/Config.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121

2222
final class Config
2323
{
24-
/** @var string */
25-
const PAPER_ORIENTATION_LANDSCAPE = 'landscape';
26-
27-
/** @var string */
28-
const PAPER_ORIENTATION_PORTRAIT = 'portrait';
24+
public const PAPER_ORIENTATION_LANDSCAPE = 'landscape';
25+
public const PAPER_ORIENTATION_PORTRAIT = 'portrait';
2926

3027
/**
3128
* @var string
@@ -34,15 +31,15 @@ final class Config
3431
private $pdfSize = 'a4';
3532

3633
/** @var string */
37-
private $pdfOrientation;
34+
private $pdfOrientation = self::PAPER_ORIENTATION_PORTRAIT;
3835

3936
/** @var string */
4037
private $pdfAuthor = '';
4138

4239
/** @var string */
4340
private $pdfTitle = '';
4441

45-
/** @var boolean */
42+
/** @var bool */
4643
private $isDebugMode = false;
4744

4845
/** @var string */

src/Model/Generator/AbstractGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ protected function writeDebugFile($fileContents)
9696
}
9797

9898
$debugFilename = $this->config->getTempDir() . DIRECTORY_SEPARATOR . self::DEBUG_FILE_NAME;
99-
return (@file_put_contents($debugFilename, $fileContents) !== false);
99+
return @file_put_contents($debugFilename, $fileContents) !== false;
100100
}
101101
}

src/Model/Generator/Dompdf.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,14 @@
3131
*/
3232
final class Dompdf extends AbstractGenerator
3333
{
34-
const TOTAL_PAGE_COUNT_PLACEHOLDER = '__PDF_TPC__';
34+
private const TOTAL_PAGE_COUNT_PLACEHOLDER = '__PDF_TPC__';
3535

36-
/**
37-
* @var \Dompdf\Dompdf
38-
*/
36+
/** @var \Dompdf\Dompdf */
3937
private $domPdf;
4038

4139
/**
4240
* Render the pdf document.
4341
*
44-
* @param DocumentInterface $documentModel
45-
*
4642
* @return string|null
4743
* @throws \Exception
4844
*/
@@ -69,27 +65,20 @@ protected function initPdf()
6965

7066
$this->domPdf->setPaper($this->config->getPdfSize(), $this->config->getPdfOrientation());
7167

72-
$this->domPdf->add_info('Creator', $this->config->getPdfAuthor());
73-
$this->domPdf->add_info('Title', $this->config->getPdfTitle());
68+
$this->domPdf->addInfo('Creator', $this->config->getPdfAuthor());
69+
$this->domPdf->addInfo('Title', $this->config->getPdfTitle());
7470

7571
return $this;
7672
}
7773

7874
/**
7975
* Return HTML contents for one single document that is later merged with the others.
8076
*
81-
* @param DocumentInterface $documentModel
82-
*
83-
* @return string
8477
* @throws \Exception
8578
*/
86-
protected function getHtmlContentsForDocument(DocumentInterface $documentModel)
79+
protected function getHtmlContentsForDocument(DocumentInterface $documentModel): string
8780
{
88-
try {
89-
$htmlContents = $documentModel->getHtmlContents();
90-
} catch (\Exception $ex) {
91-
throw $ex;
92-
}
81+
$htmlContents = $documentModel->getHtmlContents();
9382

9483
$htmlContents = $this->replaceSpecialChars($htmlContents);
9584
$this->writeDebugFile($htmlContents);
@@ -111,10 +100,7 @@ private function getDompdfOptions()
111100
);
112101
}
113102

114-
/**
115-
* @return void
116-
*/
117-
private function injectPageCount()
103+
private function injectPageCount(): void
118104
{
119105
$canvas = $this->domPdf->getCanvas();
120106
$pdf = $canvas->get_cpdf();

src/Test/PdfTest.php

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* @section LICENSE
46
* This file is created by vianetz <[email protected]>.
@@ -25,30 +27,21 @@
2527

2628
final class PdfTest extends TestCase
2729
{
28-
/**
29-
* @return \Vianetz\Pdf\Model\Document
30-
*/
31-
private function getDocumentMock()
30+
private function getDocumentMock(): \Vianetz\Pdf\Model\Document
3231
{
3332
/** @var \Vianetz\Pdf\Model\Document $document */
3433
$document = new \Vianetz\Pdf\Model\Document();
35-
$document->setHtmlContents('<html>test</html>');
34+
$document->setHtmlContents('<html><body>This is the <strong>pdf-generator</strong> test!</body></html>');
3635

3736
return $document;
3837
}
3938

40-
/**
41-
* @return \Vianetz\Pdf\Model\Pdf
42-
*/
43-
private function getPdfMock(Config $config = null)
39+
private function getPdfMock(?Config $config = null): \Vianetz\Pdf\Model\Pdf
4440
{
4541
return PdfFactory::general()->create($config);
4642
}
4743

48-
/**
49-
* @return void
50-
*/
51-
public function tearDown()
44+
public function tearDown(): void
5245
{
5346
parent::tearDown();
5447

@@ -57,21 +50,15 @@ public function tearDown()
5750
@rmdir('./tmp/');
5851
}
5952

60-
/**
61-
* @return void
62-
*/
63-
public function testAddOneDocumentIncreasesDocumentCounterByOne()
53+
public function testAddOneDocumentIncreasesDocumentCounterByOne(): void
6454
{
6555
$pdfMock = $this->getPdfMock();
6656
$pdfMock->addDocument($this->getDocumentMock());
6757

6858
$this->assertEquals(1, $pdfMock->countDocuments());
6959
}
7060

71-
/**
72-
* @return void
73-
*/
74-
public function testAddThreeDocumentsIncreasesDocumentCounterByThree()
61+
public function testAddThreeDocumentsIncreasesDocumentCounterByThree(): void
7562
{
7663
$pdfMock = $this->getPdfMock();
7764
$pdfMock->addDocument($this->getDocumentMock())
@@ -81,30 +68,21 @@ public function testAddThreeDocumentsIncreasesDocumentCounterByThree()
8168
$this->assertEquals(3, $pdfMock->countDocuments());
8269
}
8370

84-
/**
85-
* @return void
86-
*/
87-
public function testGetContentsReturnsExceptionIfNoDocumentsAdded()
71+
public function testGetContentsReturnsExceptionIfNoDocumentsAdded(): void
8872
{
8973
$this->expectException(NoDataException::class);
9074
$this->getPdfMock()->getContents();
9175
}
9276

93-
/**
94-
* @return void
95-
*/
96-
public function testGetContentsReturnsExpectedResult()
77+
public function testGetContentsReturnsNonEmptyResult(): void
9778
{
9879
$pdfMock = $this->getPdfMock();
9980
$pdfMock->addDocument($this->getDocumentMock());
10081

10182
$this->assertNotEmpty($pdfMock->getContents());
10283
}
10384

104-
/**
105-
* @return void
106-
*/
107-
public function testDebugModeGeneratesDebugFile()
85+
public function testDebugModeGeneratesDebugFile(): void
10886
{
10987
$config = new Config();
11088
$config->setIsDebugMode(true)
@@ -116,20 +94,14 @@ public function testDebugModeGeneratesDebugFile()
11694
$this->assertFileExists(AbstractGenerator::DEBUG_FILE_NAME);
11795
}
11896

119-
/**
120-
* @return void
121-
*/
122-
public function testConfigTempDirMayNotBeNull()
97+
public function testConfigTempDirMayNotBeNull(): void
12398
{
12499
$config = new Config();
125100

126101
$this->assertNotEmpty($config->getTempDir());
127102
}
128103

129-
/**
130-
* @return void
131-
*/
132-
public function testNoExceptionIfTempDirNotWritable()
104+
public function testNoExceptionIfTempDirNotWritable(): void
133105
{
134106
@mkdir('./tmp', 0000);
135107

@@ -140,6 +112,6 @@ public function testNoExceptionIfTempDirNotWritable()
140112
$pdfMock->addDocument($this->getDocumentMock())
141113
->render();
142114

143-
$this->assertDirectoryNotIsWritable('tmp/');
115+
$this->assertDirectoryIsNotWritable('tmp/');
144116
}
145117
}

0 commit comments

Comments
 (0)