From: fomichev Date: Tue, 21 Jan 2025 20:07:16 +0000 (+0300) Subject: добавляю переменную окружения X-Git-Tag: 1.7~53^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=9cab53d540706afab33e3aa29f38d8843fe1180d;p=erp24_rep%2Fyii-erp24%2F.git добавляю переменную окружения --- diff --git a/erp24/.env.example b/erp24/.env.example new file mode 100644 index 00000000..9ec7e9d4 --- /dev/null +++ b/erp24/.env.example @@ -0,0 +1 @@ +APP_ENV=development \ No newline at end of file diff --git a/erp24/composer.json b/erp24/composer.json index aede880e..eb09e325 100644 --- a/erp24/composer.json +++ b/erp24/composer.json @@ -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": { diff --git a/erp24/services/TelegramService.php b/erp24/services/TelegramService.php index 53d3ac76..eaf28c5c 100644 --- a/erp24/services/TelegramService.php +++ b/erp24/services/TelegramService.php @@ -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"; diff --git a/erp24/web/index.php b/erp24/web/index.php index a32daaef..1c20992e 100644 --- a/erp24/web/index.php +++ b/erp24/web/index.php @@ -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';