Total Complexity | 7 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | trait TelegramTrait |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * Admin chat id |
||
18 | * |
||
19 | * @var int |
||
20 | */ |
||
21 | private static int $adminId = -1; |
||
22 | |||
23 | /** |
||
24 | * Get env file path and return it |
||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | private function getEnvFilePath(): string |
||
29 | { |
||
30 | $defaultEnvPaths = [ |
||
31 | $_SERVER['DOCUMENT_ROOT'] . '/.env', |
||
32 | getcwd() . '/../.env', |
||
33 | getcwd() . '/.env', |
||
34 | ]; |
||
35 | |||
36 | foreach ($defaultEnvPaths as $path) { |
||
37 | if (file_exists($path)) { |
||
38 | return $path; |
||
39 | } |
||
40 | } |
||
41 | |||
42 | return ''; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Get token from env file. |
||
47 | * |
||
48 | * @param string $file |
||
49 | * @return string|null |
||
50 | */ |
||
51 | protected function getEnvToken(string $file): string|null |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Set the admin chat id |
||
59 | * |
||
60 | * @return int |
||
61 | */ |
||
62 | public static function getAdminId(): int |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Set the admin chat id |
||
69 | * |
||
70 | * @param int $adminId |
||
71 | */ |
||
72 | public static function setAdminId(int $adminId): void |
||
77 | } |