leafsphp / leaf

🍁 The easiest way to create clean, simple but powerful web apps and APIs quickly
https://leafphp.dev
MIT License
1.1k stars 68 forks source link

_env not working on CLI #133

Closed agarzon-orangerine closed 2 years ago

agarzon-orangerine commented 2 years ago

Describe the bug

The helper function _env() relies on $_ENV validation, preventing the correct use on CLI

To Reproduce Steps to reproduce the behavior:

  1. Run the application using injected environments variables (like in docker and docker-compose and kubernetes) and skip the use of .env file (using .env files in clusters and containers is bad practice)
  2. debug the content of the container (docker) executing the command printenv to verify the variable you want has been injected in the container.
  3. Dump the content using the PHP function getenv() from inside leaf PHP (cli), The variable injected should be there, cool!
  4. Do the same but with _env()... Hmm, the variable is not there!

Expected behavior _env() should read the environment variables just like getenv does.

Additional context I love the simplicity and flexibility of this framework.

What I'm doing is basically running the leaf framework inside a docker container to execute a command (not web), and because is docker, the .env files won't be used to handle environment variables, instead all the variables are injected to the container just like it works with any other framework.

Unfortunately the presence of $_ENV in the validation inside _env function prevent the use of the variable even though the variable was captured by the official PHP function getenv().

mychidarko commented 2 years ago

Hey @agarzon-orangerine, thanks for opening such a detailed issue. I'll confirm the issue and provide a fix for it ASAP.

mychidarko commented 2 years ago

@agarzon-orangerine An update has been pushed for this.