imunhatep/checkenv

通用PHP库

v1.0.3 2020-12-23 15:49 UTC

This package is auto-updated.

Last update: 2024-09-04 14:25:14 UTC


README

比较应用程序环境变量与.env文件。在InitContainer阶段,它可能有助于验证PHP应用程序部署的集群设置。基于Symfony/Console组件,

安装
composer require imunhatep/checkenv
使用示例
cd ./bin
ln -s ../vendor/imunhatep/checkenv/bin/check-env 
cd ..

./bin/check-env c:c:e --dot-env=".env.dist"

注意:默认情况下,Symfony4在每次应用程序调用时都会加载.env,请检查您的项目config/bootstrap.php

针对config/bootstrap.php的修复,以跳过在APP_ENV变量定义的情况下加载.env

#...

// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) {
    foreach ($env as $k => $v) {
        $_ENV[$k] = $_ENV[$k] ?? (isset($_SERVER[$k]) && 0 !== strpos($k, 'HTTP_') ? $_SERVER[$k] : $v);
    }
} elseif (!class_exists(Dotenv::class)) {
    throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} elseif (getenv('APP_ENV') === false) {
    // load all the .env files
    (new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
}

#...

增加检查:} elseif (getenv('APP_ENV') === false) {