-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
# Dotenv | ||
A simple and tiny PHP `.env` loader. | ||
A simple and tiny PHP `.env` loader, which does not inject values into `$_ENV` or OS. | ||
## Installation | ||
``` | ||
composer require env/dotenv | ||
``` | ||
## Usage | ||
The .env file should have a valid [.ini](https://wikipedia.org/wiki/INI_file) syntaxis, supported by [parse_ini_file](https://www.php.net/manual/en/function.parse-ini-file.php). | ||
|
||
This package does not inject values into global `$_ENV` or OS wia [putenv()](https://www.php.net/manual/en/function.putenv.php) so it's up to you how you wan't proceed with parsed data. | ||
|
||
### Load | ||
Parse .env and inject it into `$_ENV` variable: | ||
Parse `.env` and get values as array: | ||
```php | ||
$env = new \Env\Dotenv( | ||
$env = \Env\Dotenv::toArray( | ||
path: '.env', | ||
overwrite: false, // by default: true | ||
strict: false, // by default: true | ||
); | ||
``` | ||
The second argument determine if existing `$_ENV` keys should be overwritten. | ||
### Parse | ||
Additionaly, if you dont wan't to inject data into `$_ENV`, you can retrieve parsed data by: | ||
```php | ||
$env = \Env\Dotenv::load('.env'); | ||
``` | ||
If you need variables and fallback values, set strict to `false` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters