1 | <?php |
||
20 | class PostOptionsConstructor |
||
21 | { |
||
22 | /** |
||
23 | * With this flag we'll know what type of request to send to Telegram |
||
24 | * |
||
25 | * 'application/x-www-form-urlencoded' is the "normal" one, which is simpler and quicker. |
||
26 | * 'multipart/form-data' should be used only when you upload documents, photos, etc. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | public $formType = 'application/x-www-form-urlencoded'; |
||
31 | |||
32 | /** |
||
33 | * This is a flag intended to temporarily store the number of local files |
||
34 | * |
||
35 | * @var int |
||
36 | */ |
||
37 | private $numberOfLocalFiles = 0; |
||
38 | |||
39 | /** |
||
40 | * @var LoggerInterface |
||
41 | */ |
||
42 | protected $logger; |
||
43 | |||
44 | 41 | public function __construct(LoggerInterface $logger = null) |
|
51 | |||
52 | /** |
||
53 | * Builds up the form elements to be sent to Telegram |
||
54 | * |
||
55 | * @param TelegramMethods $method |
||
56 | * @return array |
||
57 | * @throws MissingMandatoryField |
||
58 | */ |
||
59 | 32 | public function constructOptions(TelegramMethods $method): array |
|
81 | |||
82 | /** |
||
83 | * Check if the given TelegramMethod should be handled as a multipart. |
||
84 | * |
||
85 | * @param TelegramMethods $method |
||
86 | * @return array |
||
87 | */ |
||
88 | 32 | private function checkIsMultipart(TelegramMethods $method): array |
|
113 | |||
114 | /** |
||
115 | * Builds up a multipart form-like array for the HTTP client |
||
116 | * |
||
117 | * @param array $data The original object in array form |
||
118 | * @param array $multipartData |
||
119 | * @return array Returns the actual formdata to be sent |
||
120 | */ |
||
121 | 4 | public function constructMultipartOptions(array $data, array $multipartData): array |
|
135 | |||
136 | /** |
||
137 | * Is able to construct the entire body for a multipart form data |
||
138 | * |
||
139 | * @param array $data |
||
140 | * @param array $multipartData |
||
141 | * @return Builder |
||
142 | */ |
||
143 | 4 | private function constructBodyForMultipart(array $data, array $multipartData): Builder |
|
157 | |||
158 | /** |
||
159 | * Scans the actual media and adds it to the multipart form data |
||
160 | * |
||
161 | * @param Builder $builder |
||
162 | * @param array $multipartData |
||
163 | * @return Builder |
||
164 | */ |
||
165 | 4 | private function appendMediaStream(Builder $builder, array $multipartData): Builder |
|
179 | } |
||
180 |