1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace TheCodingMachine\Gotenberg; |
6
|
|
|
|
7
|
|
|
abstract class Request |
8
|
|
|
{ |
9
|
|
|
public const A3 = [11.7, 16.5]; |
10
|
|
|
public const A4 = [8.27, 11.7]; |
11
|
|
|
public const A5 = [5.8, 8.2]; |
12
|
|
|
public const A6 = [4.1, 5.8]; |
13
|
|
|
public const LETTER = [8.5, 11]; |
14
|
|
|
public const LEGAL = [8.5, 14]; |
15
|
|
|
public const TABLOID = [11, 17]; |
16
|
|
|
|
17
|
|
|
public const NO_MARGINS = [0, 0, 0, 0]; |
18
|
|
|
public const NORMAL_MARGINS = [1, 1, 1, 1]; |
19
|
|
|
public const LARGE_MARGINS = [2, 2, 2, 2]; |
20
|
|
|
|
21
|
|
|
private const RESULT_FILENAME = 'resultFilename'; |
22
|
|
|
private const WAIT_TIMEOUT = 'waitTimeout'; |
23
|
|
|
private const WEBHOOK_URL = 'webhookURL'; |
24
|
|
|
private const WEBHOOK_URL_TIMEOUT = 'webhookURLTimeout'; |
25
|
|
|
|
26
|
|
|
private const WEBHOOK_URL_BASE_HTTP_HEADER_KEY = 'Gotenberg-Webhookurl-'; |
27
|
|
|
|
28
|
|
|
/** @var string|null */ |
29
|
|
|
private $resultFilename; |
30
|
|
|
|
31
|
|
|
/** @var float|null */ |
32
|
|
|
private $waitTimeout; |
33
|
|
|
|
34
|
|
|
/** @var string|null */ |
35
|
|
|
private $webhookURL; |
36
|
|
|
|
37
|
|
|
/** @var float|null */ |
38
|
|
|
private $webhookURLTimeout; |
39
|
|
|
|
40
|
|
|
/** @var array<string,string> */ |
41
|
|
|
protected $customHTTPHeaders; |
42
|
|
|
|
43
|
|
|
public function __construct() |
44
|
|
|
{ |
45
|
|
|
$this->customHTTPHeaders = []; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return array<string,mixed> |
50
|
|
|
*/ |
51
|
|
|
public function getFormValues(): array |
52
|
|
|
{ |
53
|
|
|
$values = []; |
54
|
|
|
if (! empty($this->resultFilename)) { |
55
|
|
|
$values[self::RESULT_FILENAME] = $this->resultFilename; |
56
|
|
|
} |
57
|
|
|
if ($this->waitTimeout !== null) { |
58
|
|
|
$values[self::WAIT_TIMEOUT] = $this->waitTimeout; |
59
|
|
|
} |
60
|
|
|
if (! empty($this->webhookURL)) { |
61
|
|
|
$values[self::WEBHOOK_URL] = $this->webhookURL; |
62
|
|
|
} |
63
|
|
|
if (! empty($this->webhookURLTimeout)) { |
64
|
|
|
$values[self::WEBHOOK_URL_TIMEOUT] = $this->webhookURLTimeout; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $values; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return array<string,string> |
72
|
|
|
*/ |
73
|
|
|
public function getCustomHTTPHeaders(): array |
74
|
|
|
{ |
75
|
|
|
return $this->customHTTPHeaders; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setResultFilename(?string $resultFilename): void |
79
|
|
|
{ |
80
|
|
|
$this->resultFilename = $resultFilename; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setWaitTimeout(?float $waitTimeout): void |
84
|
|
|
{ |
85
|
|
|
$this->waitTimeout = $waitTimeout; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function setWebhookURL(?string $webhookURL): void |
89
|
|
|
{ |
90
|
|
|
$this->webhookURL = $webhookURL; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function setWebhookURLTimeout(?float $webhookURLTimeout): void |
94
|
|
|
{ |
95
|
|
|
$this->webhookURLTimeout = $webhookURLTimeout; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function addWebhookURLHTTPHeader(string $key, string $value): void |
99
|
|
|
{ |
100
|
|
|
$key = self::WEBHOOK_URL_BASE_HTTP_HEADER_KEY . $key; |
101
|
|
|
$this->customHTTPHeaders[$key] = $value; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|