dotenv-org / phpdotenv-vault

Load environment variables from encrypted .env.vault files
https://www.dotenv.org/docs/languages/php
BSD 3-Clause "New" or "Revised" License
8 stars 3 forks source link

NOT_FOUND_DOTENV_ENVIRONMENT in version 0.1.2 #2

Closed SchoppAx closed 10 months ago

SchoppAx commented 1 year ago

Hi,

after updating to package version 0.1.2, phpdotenv-vault throws: NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment DOTENV_VAULT_DEVELOPMENT in your .env.vault file. Run 'npx dotenv-vault build' to include it.

PHP: 8.2 phpdotenv-vault: 0.1.2

In my opinion the problem is, the last change Use getenv instead of

Why? We load our .env with the following code:

$dotenv = DotenvVault::createImmutable(__DIR__, '.env.vault');
$dotenv->load();

The function createImmutable calls RepositoryBuilder::createWithDefaultAdapters(). The used default adapters are ServerConstAdapter and EnvConstAdapter (ref vlucas/phpdotenv/src/Repository/RepositoryBuilder.php). These adapters write our environment variables to $_SERVER and $_ENV. So with these adapers we can't access our variables via getenv. The needed PutenvAdapter is only added inside createUnsafeImmutable.

How to deal with it?

motdotla commented 10 months ago

This is fixed in the latest. Sorry for the delay on this. This library was largely broken. :(

It is all fixed up now. 🎉

https://github.com/dotenv-org/phpdotenv-vault/tree/v0.2.4