1 | <?php |
||
11 | class FormConstructor |
||
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 | 41 | 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 | 31 | public function constructFormData(TelegramMethods $method): array |
|
86 | |||
87 | /** |
||
88 | * Can perform any special checks needed to be performed before sending the actual request to Telegram |
||
89 | * |
||
90 | * This will return an array with data that will be different in each case (for now). This can be changed in the |
||
91 | * future. |
||
92 | * |
||
93 | * @param TelegramMethods $method |
||
94 | * @return array |
||
95 | */ |
||
96 | 31 | private function checkSpecialConditions(TelegramMethods $method): array |
|
117 | |||
118 | /** |
||
119 | * Builds up a multipart form-like array for Guzzle |
||
120 | * |
||
121 | * @param array $data The original object in array form |
||
122 | * @param string $fileKeyName A file handler will be sent instead of a string, state here which field it is |
||
123 | * @param resource $stream The actual file handler |
||
124 | * @return array Returns the actual formdata to be sent |
||
125 | */ |
||
126 | 5 | public function buildMultipartFormData(array $data, string $fileKeyName, $stream): array |
|
148 | } |
||
149 |