mykemeynell / dotenv by mykemeynell

Load .env file into project environment, using same functions as Laravel
9,593
2
2
Package Data
Maintainer Username: mykemeynell
Maintainer Contact: iam@mykemeynell.com (Myke Howells)
Package Create Date: 2016-03-09
Package Last Update: 2018-06-18
Language: PHP
License: GPL
Last Refreshed: 2024-04-15 15:08:09
Package Statistics
Total Downloads: 9,593
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 2
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

dotenv Environment Manager

Stable version Unstable version

If you have used Laravel and gotten used to being able to set and switch between environments as easily as swapping out a .env file.

Using mykehowells/dotenv, you can now add that functionality to your own projects with composer.

Install via Composer

Add mykehowells/dotenv to your project via composer with the following line:

composer require mykehowells/dotenv

Add the below code to check for a .env file, and import if it exists. Preferably, you should store this file outside of any publicly accessible directories, as it will contain potentially sensitive data - such as database credentials.

Check out the vlucas/phpdotenv readme for more info on that package.

/*----------------------------------------------------------------------------
| ENV CONFIGURATION
|-----------------------------------------------------------------------------
|
| Check to see if an env file exists at project root, if it does, import
| keys and values into putenv( $setting ), otherwise env( $key, $default=null )
| will return default value.
|
|---------------------------------------------------------------------------*/
load_env( __DIR__ );

You can then start using the env( $key, $default = null ) function to retrieve data from your .env file.