|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TheCodingMachine\Gotenberg; |
|
4
|
|
|
|
|
5
|
|
|
class HTMLRequest extends ChromeRequest |
|
6
|
|
|
{ |
|
7
|
|
|
/** @var Document */ |
|
8
|
|
|
protected $index; |
|
9
|
|
|
|
|
10
|
|
|
/** @var Document[] */ |
|
11
|
|
|
protected $assets; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* HTMLRequest constructor. |
|
15
|
|
|
* @param Document $index |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct(Document $index) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->index = $index; |
|
20
|
|
|
$this->assets = []; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return string |
|
25
|
|
|
*/ |
|
26
|
|
|
public function getPostURL(): string |
|
27
|
|
|
{ |
|
28
|
|
|
return '/convert/html'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return array<string,Document> |
|
33
|
|
|
*/ |
|
34
|
|
|
public function getFormFiles(): array |
|
35
|
|
|
{ |
|
36
|
|
|
$files = parent::getFormFiles(); |
|
37
|
|
|
$files['index.html'] = $this->index; |
|
38
|
|
|
foreach ($this->assets as $asset) { |
|
39
|
|
|
$files[$asset->getFileName()] = $asset; |
|
40
|
|
|
} |
|
41
|
|
|
return $files; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param float[] $paperSize |
|
46
|
|
|
* @throws RequestException |
|
47
|
|
|
*/ |
|
48
|
|
|
public function setPaperSize(array $paperSize): void |
|
49
|
|
|
{ |
|
50
|
|
|
if (count($paperSize) !== 2) { |
|
51
|
|
|
throw new RequestException('Wrong paper size.'); |
|
52
|
|
|
} |
|
53
|
|
|
$this->paperWidth = $paperSize[0]; |
|
54
|
|
|
$this->paperHeight = $paperSize[1]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param float[] $margins |
|
59
|
|
|
* @throws RequestException |
|
60
|
|
|
*/ |
|
61
|
|
|
public function setMargins(array $margins): void |
|
62
|
|
|
{ |
|
63
|
|
|
if (count($margins) !== 4) { |
|
64
|
|
|
throw new RequestException('Wrong margins.'); |
|
65
|
|
|
} |
|
66
|
|
|
$this->marginTop = $margins[0]; |
|
67
|
|
|
$this->marginBottom = $margins[1]; |
|
68
|
|
|
$this->marginLeft = $margins[2]; |
|
69
|
|
|
$this->marginRight = $margins[3]; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param Document[] $assets |
|
74
|
|
|
*/ |
|
75
|
|
|
public function setAssets(array $assets): void |
|
76
|
|
|
{ |
|
77
|
|
|
$this->assets = $assets; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|