|
|
2 years ago | |
|---|---|---|
| src | 2 years ago | |
| .gitignore | 2 years ago | |
| LICENSE | 2 years ago | |
| README.md | 2 years ago | |
| composer.json | 2 years ago | |
| composer.lock | 2 years ago | |
README.md
Gbili DotEnv
A simple PHP package to load environment variables from a .env file. Comments within the .env file, starting with a #, are supported.
Installation
You can include this class in your project by copying the file, or use Composer if it's part of a package.
Usage
Loading Environment Variables
To load environment variables from a .env file located in the root directory of your project, use the load method:
use Gbili\DotEnv;
DotEnv::load(__DIR__);
The .env file should contain one environment variable per line, in the format VAR_NAME=value. Comments can be included, starting with a #.
Accessing Environment Variables
Once loaded, environment variables can be accessed using the $_ENV global variable:
echo $_ENV['VAR_NAME']; // Outputs the value
Handling Quotes
The removeOuterQuotes method in the class handles both single and double quotes around the values, allowing for flexibility in how you define your variables.
Methods
loadFromFile($filepath): Loads environment variables from a given file path.removeOuterQuotes(string $string, $quote = "'"): Removes outer quotes from a given string.MUTATE_ENV_addEnvVars(array $variables): Merges the given variables into the$_ENVsuperglobal.load(string $rootDir): Loads environment variables from a.envfile in the given root directory.
Contributing
Feel free to submit issues or pull requests if you find any problems or have suggestions for improvements.