-
Notifications
You must be signed in to change notification settings - Fork 172
/
TelegramDocument.php
55 lines (47 loc) · 1.22 KB
/
TelegramDocument.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types = 1);
namespace unreal4u\InternalFunctionality;
use GuzzleHttp\Psr7\Response;
/**
* Used when we download a file from Telegram, contains some important headers information that else would be lost
*/
class TelegramDocument
{
/**
* The mime type of this file
* @var string
*/
public $mime_type = '';
/**
* The actual contents of this file
* @var string
*/
public $contents = '';
/**
* The file size
* @var int
*/
public $file_size = 0;
/**
* Constructs a representable document
*
* @param Response $response
*/
public function __construct(Response $response)
{
$headers = $response->getHeaders();
// What better to get the mime type than what the Telegram servers already send us?
$this->mime_type = $headers['Content-Type'][0];
// Same with file length
$this->file_size = $headers['Content-Length'][0];
$this->contents = (string)$response->getBody();
}
/**
* When called with string-ish functions, assume we want the actual contents of the file
* @return string
*/
public function __toString()
{
return $this->contents;
}
}