https://github.com/hind-sagar-biswas/phpdotenv
https://github.com/hind-sagar-biswas/phpdotenv
Last synced: 7 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hind-sagar-biswas/phpdotenv
- Owner: hind-sagar-biswas
- License: mit
- Created: 2023-10-03T17:35:05.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-03T17:56:17.000Z (about 2 years ago)
- Last Synced: 2025-02-03T04:29:01.308Z (9 months ago)
- Language: PHP
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Dot Env
Small `.env` file loader to load and manage Env variables for PHP project. It also has the functionality to load variables from `.env.example` iteractively
## Installation
To install via composer, run:
```
composer install hindbiswas/phpdotenv
```## Load Env Variable
```php
load();// To access variables
// getenv()
$variable_value = getenv('TEST_NAME');
// $_ENV[]
$variable_value = $_ENV['TEST_NAME'];
```## Generate from Example file
```php
from(__DIR__ . '/path/to/example/');
$env->to(__DIR__); // This line is not required if destination an source is same
$env->put();
```This will create a `.env` following the template of `.env.example` and if there are `{{...}}`, it will treat it as variable and ask for value.
So,if `.env.example`:
```
HOLA=amigos
OGENKI={{desuka}}
```Now if the generator file is run: `php generator.php` It'll prompt for the value in place of `{{desuka}}` and use it's value in generated `.env`:
```
Enter the value for `desuka`
>>
```So, putting value `Hai` will generate file:
```.env
HOLA=amigos
OGENKI=Hai
```