Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change .env UF_MODE not working #1177

Closed
josemachado94 opened this issue Sep 25, 2021 · 4 comments
Closed

Change .env UF_MODE not working #1177

josemachado94 opened this issue Sep 25, 2021 · 4 comments
Milestone

Comments

@josemachado94
Copy link

When i change UF_MODE to production, erros are still displayed and assets-raw used.

however looking for some troubleshooting, i found that:

changing $mode = getenv('UF_MODE') ?: "" to $mode = env('UF_MODE', '') on CORE Sprinkle ServiceProvider, line 244, resolves the problem.

is that save to use in production? uncomment and use env() instead of getenv() ?

@josemachado94
Copy link
Author

Possible fix (getenv() was deprecated and changed to $_ENV[] ):

Change: $mode = getenv('UF_MODE') ?: ""
To: $mode = array_key_exists("UF_MODE", $_ENV) ? $_ENV['UF_MODE'] : "default";

@lcharette
Copy link
Member

Which version of UserFrosting are you using?

There was an issue with using env there, not sure if it can be fixed yet :

// TODO : Change to env. It doesn't looks likes it work with dotenv load above.

@josemachado94
Copy link
Author

I'm using the latest version 4.6.

If i change that line to $mode = array_key_exists("UF_MODE", $_ENV) ? $_ENV['UF_MODE'] : "default"; it works properly.

That's what is in the phptdotenv documentation:

"Putenv and Getenv
Using getenv() and putenv() is strongly discouraged due to the fact that these functions are not thread safe, however it is still possible to instruct PHP dotenv to use these functions. Instead of calling Dotenv::createImmutable, one can call Dotenv::createUnsafeImmutable, which will add the PutenvAdapter behind the scenes. Your environment variables will now be available using the getenv method, as well as the super-globals:

$s3_bucket = getenv('S3_BUCKET');
$s3_bucket = $_ENV['S3_BUCKET'];
$s3_bucket = $_SERVER['S3_BUCKET'];"


$dotenv = Dotenv\Dotenv::createImmutable(DIR);
$dotenv->load();

The above example will write loaded values to $_ENV and putenv, but when interpolating environment variables, we'll only read from $_ENV. Moreover, it will never replace any variables already set before loading the file.

By means of another example, one can also specify a set of variables to be allow listed. That is, only the variables in the allow list will be loaded:

$repository = Dotenv\Repository\RepositoryBuilder::createWithDefaultAdapters()
->allowList(['FOO', 'BAR'])
->make();

$dotenv = Dotenv\Dotenv::create($repository, DIR);
$dotenv->load();

@lcharette lcharette added this to the 4.6.x milestone Sep 26, 2021
@lcharette
Copy link
Member

This has been fixed in eed5f9b and v4.6.2

@lcharette lcharette modified the milestones: 4.6.x, 4.6.2 Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants