1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace TheCodingMachine\Gotenberg; |
6
|
|
|
|
7
|
|
|
use function count; |
8
|
|
|
|
9
|
|
|
abstract class ChromeRequest extends Request implements GotenbergRequestInterface |
10
|
|
|
{ |
11
|
|
|
private const WAIT_DELAY = 'waitDelay'; |
12
|
|
|
private const PAPER_WIDTH = 'paperWidth'; |
13
|
|
|
private const PAPER_HEIGHT = 'paperHeight'; |
14
|
|
|
private const MARGIN_TOP = 'marginTop'; |
15
|
|
|
private const MARGIN_BOTTOM = 'marginBottom'; |
16
|
|
|
private const MARGIN_LEFT = 'marginLeft'; |
17
|
|
|
private const MARGIN_RIGHT = 'marginRight'; |
18
|
|
|
private const LANDSCAPE = 'landscape'; |
19
|
|
|
private const GOOGLE_CHROME_RPCC_BUFFER_SIZE = 'googleChromeRpccBufferSize'; |
20
|
|
|
|
21
|
|
|
/** @var float|null */ |
22
|
|
|
private $waitDelay; |
23
|
|
|
|
24
|
|
|
/** @var Document|null */ |
25
|
|
|
private $header; |
26
|
|
|
|
27
|
|
|
/** @var Document|null */ |
28
|
|
|
private $footer; |
29
|
|
|
|
30
|
|
|
/** @var float|null */ |
31
|
|
|
private $paperWidth; |
32
|
|
|
|
33
|
|
|
/** @var float|null */ |
34
|
|
|
private $paperHeight; |
35
|
|
|
|
36
|
|
|
/** @var float|null */ |
37
|
|
|
private $marginTop; |
38
|
|
|
|
39
|
|
|
/** @var float|null */ |
40
|
|
|
private $marginBottom; |
41
|
|
|
|
42
|
|
|
/** @var float|null */ |
43
|
|
|
private $marginLeft; |
44
|
|
|
|
45
|
|
|
/** @var float|null */ |
46
|
|
|
private $marginRight; |
47
|
|
|
|
48
|
|
|
/** @var bool */ |
49
|
|
|
private $landscape; |
50
|
|
|
|
51
|
|
|
/** @var int|null */ |
52
|
|
|
private $googleChromeRpccBufferSize; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array<string,mixed> |
56
|
|
|
*/ |
57
|
|
|
public function getFormValues(): array |
58
|
|
|
{ |
59
|
|
|
$values = parent::getFormValues(); |
60
|
|
|
if ($this->waitDelay !== null) { |
61
|
|
|
$values[self::WAIT_DELAY] = $this->waitDelay; |
62
|
|
|
} |
63
|
|
|
if ($this->paperWidth !== null) { |
64
|
|
|
$values[self::PAPER_WIDTH] = $this->paperWidth; |
65
|
|
|
} |
66
|
|
|
if ($this->paperHeight !== null) { |
67
|
|
|
$values[self::PAPER_HEIGHT] = $this->paperHeight; |
68
|
|
|
} |
69
|
|
|
if ($this->marginTop !== null) { |
70
|
|
|
$values[self::MARGIN_TOP] = $this->marginTop; |
71
|
|
|
} |
72
|
|
|
if ($this->marginBottom !== null) { |
73
|
|
|
$values[self::MARGIN_BOTTOM] = $this->marginBottom; |
74
|
|
|
} |
75
|
|
|
if ($this->marginLeft !== null) { |
76
|
|
|
$values[self::MARGIN_LEFT] = $this->marginLeft; |
77
|
|
|
} |
78
|
|
|
if ($this->marginRight !== null) { |
79
|
|
|
$values[self::MARGIN_RIGHT] = $this->marginRight; |
80
|
|
|
} |
81
|
|
|
if ($this->googleChromeRpccBufferSize !== null) { |
82
|
|
|
$values[self::GOOGLE_CHROME_RPCC_BUFFER_SIZE] = $this->googleChromeRpccBufferSize; |
83
|
|
|
} |
84
|
|
|
$values[self::LANDSCAPE] = $this->landscape; |
85
|
|
|
|
86
|
|
|
return $values; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return array<string,Document> |
91
|
|
|
*/ |
92
|
|
|
public function getFormFiles(): array |
93
|
|
|
{ |
94
|
|
|
$files = []; |
95
|
|
|
if (! empty($this->header)) { |
96
|
|
|
$files['header.html'] = $this->header; |
97
|
|
|
} |
98
|
|
|
if (! empty($this->footer)) { |
99
|
|
|
$files['footer.html'] = $this->footer; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $files; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setWaitDelay(?float $waitDelay): void |
106
|
|
|
{ |
107
|
|
|
$this->waitDelay = $waitDelay; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param float[] $paperSize |
112
|
|
|
* |
113
|
|
|
* @throws RequestException |
114
|
|
|
*/ |
115
|
|
|
public function setPaperSize(array $paperSize): void |
116
|
|
|
{ |
117
|
|
|
if (count($paperSize) !== 2) { |
118
|
|
|
throw new RequestException('Wrong paper size.'); |
119
|
|
|
} |
120
|
|
|
$this->paperWidth = $paperSize[0]; |
121
|
|
|
$this->paperHeight = $paperSize[1]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param float[] $margins |
126
|
|
|
* |
127
|
|
|
* @throws RequestException |
128
|
|
|
*/ |
129
|
|
|
public function setMargins(array $margins): void |
130
|
|
|
{ |
131
|
|
|
if (count($margins) !== 4) { |
132
|
|
|
throw new RequestException('Wrong margins.'); |
133
|
|
|
} |
134
|
|
|
$this->marginTop = $margins[0]; |
135
|
|
|
$this->marginBottom = $margins[1]; |
136
|
|
|
$this->marginLeft = $margins[2]; |
137
|
|
|
$this->marginRight = $margins[3]; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function setHeader(?Document $header): void |
141
|
|
|
{ |
142
|
|
|
$this->header = $header; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function setFooter(?Document $footer): void |
146
|
|
|
{ |
147
|
|
|
$this->footer = $footer; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function setPaperWidth(?float $paperWidth): void |
151
|
|
|
{ |
152
|
|
|
$this->paperWidth = $paperWidth; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function setPaperHeight(?float $paperHeight): void |
156
|
|
|
{ |
157
|
|
|
$this->paperHeight = $paperHeight; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function setMarginTop(?float $marginTop): void |
161
|
|
|
{ |
162
|
|
|
$this->marginTop = $marginTop; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function setMarginBottom(?float $marginBottom): void |
166
|
|
|
{ |
167
|
|
|
$this->marginBottom = $marginBottom; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function setMarginLeft(?float $marginLeft): void |
171
|
|
|
{ |
172
|
|
|
$this->marginLeft = $marginLeft; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function setMarginRight(?float $marginRight): void |
176
|
|
|
{ |
177
|
|
|
$this->marginRight = $marginRight; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function setLandscape(bool $landscape): void |
181
|
|
|
{ |
182
|
|
|
$this->landscape = $landscape; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function setGoogleChromeRpccBufferSize(?int $googleChromeRpccBufferSize): void |
186
|
|
|
{ |
187
|
|
|
$this->googleChromeRpccBufferSize = $googleChromeRpccBufferSize; |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|