| 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 |  |  |     public function hasWebhook(): bool | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |         return ! empty($this->webhookURL); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |      * @return array<string,string> | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     public function getCustomHTTPHeaders(): array | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         return $this->customHTTPHeaders; | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |     public function setResultFilename(?string $resultFilename): void | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |         $this->resultFilename = $resultFilename; | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |     public function setWaitTimeout(?float $waitTimeout): void | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |         $this->waitTimeout = $waitTimeout; | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |     public function setWebhookURL(?string $webhookURL): void | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |         $this->webhookURL = $webhookURL; | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     public function setWebhookURLTimeout(?float $webhookURLTimeout): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  |         $this->webhookURLTimeout = $webhookURLTimeout; | 
            
                                                                        
                                                                
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                        
                                                                
            
                                    
            
            
                | 103 |  |  |     public function addWebhookURLHTTPHeader(string $key, string $value): void | 
            
                                                                        
                                                                
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                        
                                                                
            
                                    
            
            
                | 105 |  |  |         $key = self::WEBHOOK_URL_BASE_HTTP_HEADER_KEY . $key; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  |         $this->customHTTPHeaders[$key] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 108 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |  |