1 | <?php |
||
11 | class PostOptionsConstructor |
||
12 | { |
||
13 | /** |
||
14 | * With this flag we'll know what type of request to send to Telegram |
||
15 | * |
||
16 | * 'application/x-www-form-urlencoded' is the "normal" one, which is simpler and quicker. |
||
17 | * 'multipart/form-data' should be used only when you upload documents, photos, etc. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | public $formType = 'application/x-www-form-urlencoded'; |
||
22 | |||
23 | /** |
||
24 | * @var LoggerInterface |
||
25 | */ |
||
26 | protected $logger; |
||
27 | |||
28 | public function __construct(LoggerInterface $logger = null) |
||
35 | |||
36 | /** |
||
37 | * Builds up the form elements to be sent to Telegram |
||
38 | * |
||
39 | * @TODO Move this to apart function |
||
40 | * |
||
41 | * @param TelegramMethods $method |
||
42 | * @return array |
||
43 | * @throws \unreal4u\TelegramAPI\Exceptions\MissingMandatoryField |
||
44 | */ |
||
45 | public function constructOptions(TelegramMethods $method): array |
||
60 | |||
61 | /** |
||
62 | * Check if the given TelegramMethod should be handled as a multipart. |
||
63 | * |
||
64 | * @param TelegramMethods $method |
||
65 | * @return array |
||
66 | */ |
||
67 | private function checkIsMultipart(TelegramMethods $method): array |
||
88 | |||
89 | /** |
||
90 | * Builds up a multipart form-like array for Guzzle |
||
91 | * |
||
92 | * @param array $data The original object in array form |
||
93 | * @param string $fileKeyName A file handler will be sent instead of a string, state here which field it is |
||
94 | * @param resource $stream The actual file handler |
||
95 | * @return array Returns the actual formdata to be sent |
||
96 | */ |
||
97 | public function constructMultipartOptions(array $data, string $fileKeyName, $stream): array |
||
125 | } |
||
126 |