Torch
Torch copied to clipboard
Use env() helper by invoking Dotenv\Dotenv directly
Hey
I've provided an example of how to use the env() helper in conjunction with direct leverage of the Dotenv\Dotenv library. Unfortunately, the values aren't accessible with Illuminate\Support\Env; not sure what the missing bit is.
That said, maybe it's not important. IIRC, laravel folks say to only rely on app environment variables in the config files.
Thoughts?
It appears that in the full installation of Laravel DotEnv/DotEnv is implemented here: https://github.com/laravel/framework/blob/9ed095dc2d0c254e6558b514ea285b767407034b/src/Illuminate/Foundation/Bootstrap/LoadEnvironmentVariables.php#L20
Unfortunately, Illuminate/Foundation standalone package is deprecated and already not compatible with latest version of at least one other standalone package (can't recall which atm).
"... although it would be worth a later PR that also showed how to hook that into the application like happens in Laravel"
So, I could definitely try this, but where should it go?
One thing that perplexes me, and this is probably related to laravel's boot code and not using Illuminate\Foundation\Application (sadly not available), is that I can access the .env variables with the Illuminate\Support\Env class, but they do not appear in return value of Config::getEnvironment().
Any ideas on how to address this?
code:

output:

EDIT:
With regard to line 4 of my code snippet (Config::setFacadeApplication($capsule->getContainer());), this was necessary to set facade root. I guess it worked because Application extends Container (?).
I'm gonna check if your Slim Application can be used to do likewise...brb
EDIT2:
Ok, this doesn't work.

Fatal error: Uncaught RuntimeException: A facade root has not been set. in /Users/ramos/repos/Torch/components/support/vendor/illuminate/support/Facades/Facade.php:258 Stack trace: #0 /Users/ramos/repos/Torch/components/support/index.php(31): Illuminate\Support\Facades\Facade::__callStatic('getEnvironment', Array) #1 {main} thrown in /Users/ramos/repos/Torch/components/support/vendor/illuminate/support/Facades/Facade.php on line 258
EDIT3: @mattstauffer , lemme know if you think it would be better to create a new issue based on the above text.
EDIT4: hold off on merging. got something figured out.
EDIT5: see issue #192