Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| PageDecorator | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| withHeader | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| withFooter | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| withWatermark | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isEmpty | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Writer; |
| 6 | |
| 7 | /** |
| 8 | * Holds the optional per-page render hooks registered on a {@see Pdf} |
| 9 | * document: header, footer, and watermark closures. |
| 10 | * |
| 11 | * Each closure has the signature `function(PageContext $ctx): void` and |
| 12 | * is invoked once per page during a deferred render pass, after all |
| 13 | * flow content has been placed but before the PDF bytes are generated. |
| 14 | */ |
| 15 | final class PageDecorator |
| 16 | { |
| 17 | public function __construct( |
| 18 | public readonly ?\Closure $header = null, |
| 19 | public readonly ?\Closure $footer = null, |
| 20 | public readonly ?\Closure $watermark = null, |
| 21 | ) {} |
| 22 | |
| 23 | public function withHeader(?\Closure $header): self |
| 24 | { |
| 25 | return new self($header, $this->footer, $this->watermark); |
| 26 | } |
| 27 | |
| 28 | public function withFooter(?\Closure $footer): self |
| 29 | { |
| 30 | return new self($this->header, $footer, $this->watermark); |
| 31 | } |
| 32 | |
| 33 | public function withWatermark(?\Closure $watermark): self |
| 34 | { |
| 35 | return new self($this->header, $this->footer, $watermark); |
| 36 | } |
| 37 | |
| 38 | public function isEmpty(): bool |
| 39 | { |
| 40 | return $this->header === null && $this->footer === null && $this->watermark === null; |
| 41 | } |
| 42 | } |