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