]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
добавляю переменную окружения
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 21 Jan 2025 20:07:16 +0000 (23:07 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 21 Jan 2025 20:07:16 +0000 (23:07 +0300)
erp24/.env.example [new file with mode: 0644]
erp24/composer.json
erp24/services/TelegramService.php
erp24/web/index.php

diff --git a/erp24/.env.example b/erp24/.env.example
new file mode 100644 (file)
index 0000000..9ec7e9d
--- /dev/null
@@ -0,0 +1 @@
+APP_ENV=development
\ No newline at end of file
index aede880ef81d30fb83fcf5c3cada717e9a390e57..eb09e3253c5553a9115cd05cd45eac57bf07ace7 100644 (file)
@@ -35,7 +35,8 @@
         "kartik-v/yii2-widget-datepicker": "dev-master",
         "phpoffice/phpspreadsheet": "^2.2",
         "ext-xmlreader": "*",
-        "enqueue/amqp-lib": "^0.10.19"
+        "enqueue/amqp-lib": "^0.10.19",
+        "vlucas/phpdotenv": "^5.6"
 
     },
     "require-dev": {
index 53d3ac76931eca7be3a3d6fa411ef46209e76caf..eaf28c5caebde1efbc3a2a9233f8234f26ab1ae6 100644 (file)
@@ -40,13 +40,9 @@ class TelegramService
 
     public static function isDevEnv(): bool
     {
-        return getenv('DB_HOST') === 'db-yii_erp24';
+        return getenv('APP_ENV') === 'development';
     }
 
-    public static function isDevEnvironment(): bool
-    {
-        return getenv('XDEBUG_MODE') === 'debug';
-    }
 
     public static function sendErrorToTelegramMessage($message, $disableNotification, $isDev)
     {
@@ -79,13 +75,13 @@ class TelegramService
 
     public static function sendMessageToTelegramClient($chatId, $message)
     {
-        if (self::isDevelopmentEnvironment()) {
+        if (self::isDevEnv()) {
             $botToken = self::TELEGRAM_BOT_DEV;
         } else {
             $botToken = self::TELEGRAM_BOT_PROD;
         }
 
-        $botToken = self::TELEGRAM_BOT_PROD;
+        //$botToken = self::TELEGRAM_BOT_PROD;
 
         $apiURL = "https://api.telegram.org/bot{$botToken}/sendMessage";
 
index a32daaef47489799715c4eae8c577538b1cde589..1c20992e9d9f6540702d21a2598f5dfdade2c574 100644 (file)
@@ -10,6 +10,19 @@ defined('YII_ENV') or define('YII_ENV', 'dev');
 
 require __DIR__ . '/../vendor/autoload.php';
 require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
+try {
+    $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
+    $dotenv->load();
+    $dotenv->required(['APP_ENV']);
+
+    foreach ($_ENV as $key => $value) {
+        putenv("$key=$value");
+    }
+} catch (\Dotenv\Exception\InvalidPathException $e) {
+    // Логгируйте ошибку или игнорируйте, если файл не обязателен
+    error_log('Файл .env не найден: ' . $e->getMessage());
+}
+
 
 $config = require __DIR__ . '/../config/web.php';