2023-08-23 10:17:38 +02:00
2023-08-23 10:10:40 +02:00
2023-08-23 10:17:38 +02:00
2023-08-23 10:16:04 +02:00
2023-08-22 17:23:46 +02:00
2023-08-22 17:23:46 +02:00

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

Description
No description provided
Readme MIT 53 KiB
Languages
PHP 100%