aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: be2fc90801444013dc4279fbf46bc07c8e258394 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Dotenv

[![Build Status](https://travis-ci.org/NeonXP/Dotenv.svg?branch=master)](https://travis-ci.org/NeonXP/Dotenv)
[![Coveralls github](https://img.shields.io/coveralls/github/NeonXP/Dotenv.svg)]()
[![GitHub issues](https://img.shields.io/github/issues/neonxp/dotenv.svg)](https://github.com/neonxp/dotenv/issues)
[![GitHub forks](https://img.shields.io/github/forks/neonxp/dotenv.svg)](https://github.com/neonxp/dotenv/network)
[![GitHub stars](https://img.shields.io/github/stars/neonxp/dotenv.svg)](https://github.com/neonxp/dotenv/stargazers)
[![GitHub license](https://img.shields.io/github/license/neonxp/dotenv.svg)](https://github.com/neonxp/dotenv)

## 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:

```php
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:

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