|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace TelegramBot\Api\Types; |
|
4
|
|
|
|
|
5
|
|
|
use TelegramBot\Api\BaseType; |
|
6
|
|
|
use TelegramBot\Api\InvalidArgumentException; |
|
7
|
|
|
use TelegramBot\Api\TypeInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Document |
|
11
|
|
|
* This object represents a general file (as opposed to photos and audio files). |
|
12
|
|
|
* Telegram users can send files of any type of up to 1.5 GB in size. |
|
13
|
|
|
* |
|
14
|
|
|
* @package TelegramBot\Api\Types |
|
15
|
|
|
*/ |
|
16
|
|
|
class Document extends BaseType implements TypeInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
* |
|
21
|
|
|
* @var array |
|
22
|
|
|
*/ |
|
23
|
|
|
protected static $map = [ |
|
24
|
|
|
'file_id' => true, |
|
25
|
|
|
'file_unique_id' => true, |
|
26
|
|
|
'thumbnail' => PhotoSize::class, |
|
27
|
|
|
'file_name' => true, |
|
28
|
|
|
'mime_type' => true, |
|
29
|
|
|
'file_size' => true |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
* |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected static $requiredParams = ['file_id', 'file_unique_id']; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Unique identifier for this file |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $fileId; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Document thumbnail as defined by sender |
|
48
|
|
|
* |
|
49
|
|
|
* @var PhotoSize |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $thumbnail; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Optional. Original filename as defined by sender |
|
55
|
|
|
* |
|
56
|
|
|
* @var string|null |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $fileName; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Optional. MIME type of the file as defined by sender |
|
62
|
|
|
* |
|
63
|
|
|
* @var string|null |
|
64
|
|
|
*/ |
|
65
|
|
|
protected $mimeType; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Optional. File size |
|
69
|
|
|
* |
|
70
|
|
|
* @var int|null |
|
71
|
|
|
*/ |
|
72
|
|
|
protected $fileSize; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. |
|
76
|
|
|
* |
|
77
|
|
|
* @var string |
|
78
|
|
|
*/ |
|
79
|
|
|
protected $fileUniqueId; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
1 |
|
public function getFileId() |
|
85
|
|
|
{ |
|
86
|
1 |
|
return $this->fileId; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param string $fileId |
|
91
|
|
|
* @return void |
|
92
|
5 |
|
*/ |
|
93
|
|
|
public function setFileId($fileId) |
|
94
|
5 |
|
{ |
|
95
|
5 |
|
$this->fileId = $fileId; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return null|string |
|
100
|
1 |
|
*/ |
|
101
|
|
|
public function getFileName() |
|
102
|
1 |
|
{ |
|
103
|
|
|
return $this->fileName; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param string $fileName |
|
108
|
5 |
|
* @return void |
|
109
|
|
|
*/ |
|
110
|
5 |
|
public function setFileName($fileName) |
|
111
|
5 |
|
{ |
|
112
|
|
|
$this->fileName = $fileName; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
1 |
|
* @return int|null |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function getFileSize() |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->fileSize; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param mixed $fileSize |
|
125
|
|
|
* @return void |
|
126
|
6 |
|
* @throws InvalidArgumentException |
|
127
|
|
|
*/ |
|
128
|
6 |
|
public function setFileSize($fileSize) |
|
129
|
5 |
|
{ |
|
130
|
5 |
|
if (is_integer($fileSize)) { |
|
131
|
1 |
|
$this->fileSize = $fileSize; |
|
132
|
|
|
} else { |
|
133
|
5 |
|
throw new InvalidArgumentException(); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
1 |
|
* @return null|string |
|
139
|
|
|
*/ |
|
140
|
1 |
|
public function getMimeType() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->mimeType; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
5 |
|
* @param string $mimeType |
|
147
|
|
|
* @return void |
|
148
|
5 |
|
*/ |
|
149
|
5 |
|
public function setMimeType($mimeType) |
|
150
|
|
|
{ |
|
151
|
|
|
$this->mimeType = $mimeType; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
2 |
|
/** |
|
155
|
|
|
* @return PhotoSize |
|
156
|
2 |
|
*/ |
|
157
|
|
|
public function getThumbnail() |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->thumbnail; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
5 |
|
/** |
|
163
|
|
|
* @param PhotoSize $thumbnail |
|
164
|
5 |
|
* @return void |
|
165
|
5 |
|
*/ |
|
166
|
|
|
public function setThumbnail(PhotoSize $thumbnail) |
|
167
|
|
|
{ |
|
168
|
|
|
$this->thumbnail = $thumbnail; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @deprecated use getThumbnail method |
|
173
|
|
|
* |
|
174
|
|
|
* @return PhotoSize|null |
|
175
|
|
|
*/ |
|
176
|
|
|
public function getThumb() |
|
177
|
|
|
{ |
|
178
|
3 |
|
return $this->getThumbnail(); |
|
179
|
|
|
} |
|
180
|
3 |
|
|
|
181
|
3 |
|
/** |
|
182
|
|
|
* @deprecated use setThumbnail method |
|
183
|
|
|
* |
|
184
|
|
|
* @param PhotoSize $thumb |
|
185
|
|
|
* |
|
186
|
|
|
* @return void |
|
187
|
|
|
*/ |
|
188
|
|
|
public function setThumb($thumb) |
|
189
|
|
|
{ |
|
190
|
|
|
$this->setThumbnail($thumb); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @return string |
|
195
|
|
|
*/ |
|
196
|
|
|
public function getFileUniqueId() |
|
197
|
|
|
{ |
|
198
|
|
|
return $this->fileUniqueId; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @param string $fileUniqueId |
|
203
|
|
|
* @return void |
|
204
|
|
|
*/ |
|
205
|
|
|
public function setFileUniqueId($fileUniqueId) |
|
206
|
|
|
{ |
|
207
|
|
|
$this->fileUniqueId = $fileUniqueId; |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|