public function testDotenvDoesNotOverwriteEnvWhenImmutable() { Dotenv::makeMutable(); // only need this because we've previously set the variable Dotenv::setEnvironmentVariable('QFOO=external'); Dotenv::makeImmutable(); Dotenv::load(dirname(__DIR__) . '/fixtures', 'quoted.env'); $this->assertEquals('external', getenv('QFOO')); }
/** * Reloads env settings and also updates the configurations * in Laravel for anything that might change during the install * process. Things like app.key, app.debug, database stuff, mail * stuff, cache and session settings... this is a hack for people * who use php artisan serve ... no one else really needs this * hackery... * * @return void */ public function refreshEnvironment(array $settings = array()) { $this->EnvironmentFileManager->createIfNotExists(); \Dotenv::makeMutable(); \Dotenv::load(base_path(), '.env'); \Dotenv::makeImmutable(); $configToEnvMapping = ['app.debug' => 'APP_DEBUG', 'app.key' => 'APP_KEY', 'cache.default' => 'CACHE_DRIVER', 'database.default' => 'DB_DEFAULT', 'database.connections.mysql.host' => 'DB_HOST', 'database.connections.pgsql.host' => 'DB_HOST', 'database.connections.sqlsrv.host' => 'DB_HOST', 'database.connections.mysql.database' => 'DB_DATABASE', 'database.connections.pgsql.database' => 'DB_DATABASE', 'database.connections.sqlsrv.database' => 'DB_DATABASE', 'database.connections.mysql.username' => 'DB_USERNAME', 'database.connections.pgsql.username' => 'DB_USERNAME', 'database.connections.sqlsrv.username' => 'DB_USERNAME', 'database.connections.mysql.password' => 'DB_PASSWORD', 'database.connections.pgsql.password' => 'DB_PASSWORD', 'database.connections.sqlsrv.password' => 'DB_PASSWORD', 'session.driver' => 'SESSION_DRIVER']; $merged = array_merge(['APP_NAME' => env('APP_NAME', 'App'), 'APP_ENV' => env('APP_ENV', 'local'), 'APP_DEBUG' => env('APP_DEBUG'), 'APP_KEY' => env('APP_KEY', 'SomeRandomString'), 'CACHE_DRIVER' => env('CACHE_DRIVER', 'file'), 'DB_DEFAULT' => env('DB_DEFAULT', 'mysql'), 'DB_HOST' => env('DB_HOST', 'localhost'), 'DB_DATABASE' => env('DB_DATABASE', 'forge'), 'DB_USERNAME' => env('DB_USERNAME', 'forge'), 'DB_PASSWORD' => env('DB_PASSWORD', ''), 'CONFIGS_OVERRIDE' => env('CONFIGS_OVERRIDE', ''), 'APP_MIGRATIONS' => env('APP_MIGRATIONS', ''), 'APP_SEEDS' => env('APP_SEEDS', ''), 'SESSION_DRIVER' => env('SESSION_DRIVER', 'file')], $settings); foreach ($configToEnvMapping as $config => $env) { $this->Config->set($config, $merged[$env]); } app()['env'] = $merged['APP_ENV']; }
<?php require_once __DIR__ . '/../vendor/autoload.php'; Dotenv::makeMutable(); Dotenv::load(__DIR__ . '/../'); Dotenv::makeImmutable(); /* |-------------------------------------------------------------------------- | Create The Application |-------------------------------------------------------------------------- | | Here we will load the environment and create the application instance | that serves as the central piece of this framework. We'll use this | application as an "IoC" container and router for this framework. | */ $app = new Laravel\Lumen\Application(realpath(__DIR__ . '/../')); $app->withFacades(); // $app->withEloquent(); /* |-------------------------------------------------------------------------- | Register Container Bindings |-------------------------------------------------------------------------- | | Now we will register a few bindings in the service container. We will | register the exception handler and the console kernel. You may add | your own bindings here if you like or you can make another file. | */ $app->singleton(Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class); $app->singleton(Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class);