1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheCodingMachine\Gotenberg; |
4
|
|
|
|
5
|
|
|
final class OfficeRequest extends Request implements GotenbergRequestInterface |
6
|
|
|
{ |
7
|
|
|
/** @var Document[] */ |
8
|
|
|
private $files; |
9
|
|
|
|
10
|
|
|
/** @var float|null */ |
11
|
|
|
private $paperWidth; |
12
|
|
|
|
13
|
|
|
/** @var float|null */ |
14
|
|
|
private $paperHeight; |
15
|
|
|
|
16
|
|
|
/** @var bool */ |
17
|
|
|
private $landscape; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* OfficeRequest constructor. |
21
|
|
|
* @param Document[] $files |
22
|
|
|
*/ |
23
|
|
|
public function __construct(array $files) |
24
|
|
|
{ |
25
|
|
|
$this->files = $files; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
public function getPostURL(): string |
33
|
|
|
{ |
34
|
|
|
return '/convert/office'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return array<string,mixed> |
39
|
|
|
*/ |
40
|
|
|
public function getFormValues(): array |
41
|
|
|
{ |
42
|
|
|
$values = []; |
43
|
|
|
if (!empty($this->webhookURL)) { |
44
|
|
|
$values[self::WEBHOOK_URL] = $this->webhookURL; |
45
|
|
|
} |
46
|
|
|
if (!is_null($this->paperWidth)) { |
47
|
|
|
$values[self::PAPER_WIDTH] = $this->paperWidth; |
48
|
|
|
} |
49
|
|
|
if (!is_null($this->paperHeight)) { |
50
|
|
|
$values[self::PAPER_HEIGHT] = $this->paperHeight; |
51
|
|
|
} |
52
|
|
|
$values[self::LANDSCAPE] = $this->landscape; |
53
|
|
|
return $values; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return array<string,Document> |
58
|
|
|
*/ |
59
|
|
|
public function getFormFiles(): array |
60
|
|
|
{ |
61
|
|
|
$files = []; |
62
|
|
|
foreach ($this->files as $file) { |
63
|
|
|
$files[$file->getFileName()] = $file; |
64
|
|
|
} |
65
|
|
|
return $files; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param float[] $paperSize |
70
|
|
|
* @throws RequestException |
71
|
|
|
*/ |
72
|
|
|
public function setPaperSize(array $paperSize): void |
73
|
|
|
{ |
74
|
|
|
if (count($paperSize) !== 2) { |
75
|
|
|
throw new RequestException('Wrong paper size.'); |
76
|
|
|
} |
77
|
|
|
$this->paperWidth = $paperSize[0]; |
78
|
|
|
$this->paperHeight = $paperSize[1]; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param bool $landscape |
83
|
|
|
*/ |
84
|
|
|
public function setLandscape(bool $landscape): void |
85
|
|
|
{ |
86
|
|
|
$this->landscape = $landscape; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|