Advanced loading and parsing .env file in PHP-7
Find a file
Александр Кирюхин 47c9d580c6 Fix compiler
2018-01-19 10:27:54 +03:00
src Fix compiler 2018-01-19 10:27:54 +03:00
tests Completed reference implementation, added tests 2018-01-19 03:13:16 +03:00
.gitignore Initial 2018-01-19 01:01:01 +03:00
.travis.yml Added travis with coverall 2018-01-19 03:17:57 +03:00
composer.json Fix composer.json 2018-01-19 01:06:43 +03:00
LICENSE Readme and license 2018-01-19 03:41:53 +03:00
phpunit.xml.dist Completed reference implementation, added tests 2018-01-19 03:13:16 +03:00
README.md Fix badge 2018-01-19 03:47:43 +03:00

Dotenv

Build Status Codecov GitHub issues GitHub forks GitHub stars GitHub license

What is it?

Small library, that automaticaly loads .env (or any other) file to applications environment.

Why not XXX?

Because this library is pretty simple, without external dependencies and highly customizable.

Installation

composer require neonxp/dotenv

Usage

Basic usage:

use NeonXP\Dotenv\Dotenv;

$dotenv = new Dotenv();
$dotenv->load(); // You can specify file to load at first argument

print $dotenv->get('KEY', 'default') . PHP_EOL;
print $dotenv['KEY'] . PHP_EOL;
foreach ($dotenv as $key => $value) {
    print "$key = $value" . PHP_EOL;
}

.env file syntax

Here examples of syntax:

# This is a comment

# Empty lines also ignored
export KEY1=VALUE1
KEY2 = VALUE2 # Inline comment
KEY3 = 'VALUE3 # This is not comment'
KEY4 = "VALUE4 # And this value too"
KEY5 = ${KEY1} -> ${KEY2} # Compilled from another variables

and we will get:

[
    'KEY1' => 'VALUE1',
    'KEY2' => 'VALUE2',
    'KEY3' => 'VALUE3 # This is not comment',
    'KEY4' => 'VALUE4 # And this value too',
    'KEY5' => 'VALUE1 -> VALUE2',
]