You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Guillermo Pages f0fca18d10 docs: add license 2 years ago
src feat: add support for .env with comments 2 years ago
vendor feat: rename package 2 years ago
.gitignore Initial commit 4 years ago
LICENSE docs: add license 2 years ago
README.md docs: add license 2 years ago
composer.json feat: rename package 2 years ago
composer.lock feat: rename package 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 $_ENV superglobal.
  • load(string $rootDir): Loads environment variables from a .env file in the given root directory.

Contributing

Feel free to submit issues or pull requests if you find any problems or have suggestions for improvements.

License

MIT License