1 | <?php |
||
23 | class File |
||
24 | { |
||
25 | private $file; |
||
26 | |||
27 | private $format_name; |
||
28 | |||
29 | /** |
||
30 | * \brief Fill this object with another file. |
||
31 | * @param string $file File_id or local/remote path to the file. |
||
32 | * @param string $format_name Format name of the file (audio, document, ...) |
||
33 | */ |
||
34 | 7 | public function init(string $file, string $format_name) |
|
39 | |||
40 | /** |
||
41 | * \brief (<i>Internal</i>) Check if the path to the file given is local or a file_id/url. |
||
42 | * @return bool True if the file is a local path. |
||
43 | */ |
||
44 | 7 | public function isLocal() : bool |
|
45 | { |
||
46 | 7 | $host = parse_url($this->file, PHP_URL_HOST); |
|
47 | |||
48 | // If it has not an url host |
||
49 | 7 | if ($host === null) { |
|
50 | // Is the string a file_id? |
||
51 | 3 | if (preg_match('/^([\w\d]*[-_]*[\w\d]*)*$/', $this->file)) { |
|
52 | // It is a file_id |
||
53 | return false; |
||
54 | } |
||
55 | // It is local |
||
56 | 3 | return true; |
|
57 | } |
||
58 | // It is an url |
||
59 | 4 | return false; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * \brief (<i>Internal</i>) Get string component of this file. |
||
64 | * @return string File as string (file_id/path to the file). |
||
65 | */ |
||
66 | 4 | public function getString() |
|
70 | |||
71 | 3 | public function getResource() |
|
81 | |||
82 | 7 | public function getFormatName() : string |
|
86 | } |
||
87 |