1 | <?php |
||
13 | class PostOptionsConstructor |
||
14 | { |
||
15 | /** |
||
16 | * With this flag we'll know what type of request to send to Telegram |
||
17 | * |
||
18 | * 'application/x-www-form-urlencoded' is the "normal" one, which is simpler and quicker. |
||
19 | * 'multipart/form-data' should be used only when you upload documents, photos, etc. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | public $formType = 'application/x-www-form-urlencoded'; |
||
24 | |||
25 | /** |
||
26 | * @var LoggerInterface |
||
27 | */ |
||
28 | protected $logger; |
||
29 | |||
30 | 40 | public function __construct(LoggerInterface $logger = null) |
|
37 | |||
38 | /** |
||
39 | * Builds up the form elements to be sent to Telegram |
||
40 | * |
||
41 | * @TODO Move this to apart function |
||
42 | * |
||
43 | * @param TelegramMethods $method |
||
44 | * @return array |
||
45 | * @throws \unreal4u\TelegramAPI\Exceptions\MissingMandatoryField |
||
46 | */ |
||
47 | 31 | public function constructOptions(TelegramMethods $method): array |
|
71 | |||
72 | /** |
||
73 | * Check if the given TelegramMethod should be handled as a multipart. |
||
74 | * |
||
75 | * @param TelegramMethods $method |
||
76 | * @return array |
||
77 | */ |
||
78 | 31 | private function checkIsMultipart(TelegramMethods $method): array |
|
100 | |||
101 | /** |
||
102 | * Builds up a multipart form-like array for Guzzle |
||
103 | * |
||
104 | * @param array $data The original object in array form |
||
105 | * @param string $fileKeyName A file handler will be sent instead of a string, state here which field it is |
||
106 | * @param resource $stream The actual file handler |
||
107 | * @param string $filename |
||
108 | * @return array Returns the actual formdata to be sent |
||
109 | */ |
||
110 | 4 | public function constructMultipartOptions(array $data, string $fileKeyName, $stream, string $filename): array |
|
139 | } |
||
140 |