Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/commandstring/env

A singleton class used for storing environment variables
https://github.com/commandstring/env

env environment environment-variables php php8

Last synced: about 1 month ago
JSON representation

A singleton class used for storing environment variables

Awesome Lists containing this project

README

        

# commandstring/env #
A singleton class used for storing environment variables

# Requirements

* PHP 8.1
* Composer

# Creating with JSON file

## /env.json
```json
{
"mysql": {
"username": "root",
"password": "password",
"host": "127.0.0.1",
"port": 3306
}
}
```

## /index.php
```php
Env::createWithJsonFile(__DIR__."/env.json");
```

# Creating with an array

```php
Env::createFromArray(["hello" => "world"]);
```
### Note that nested arrays will be converted into an stdClass

# Getting / Setting variables

```php
Env::get("property");
Env::get()->property;

Env::get()->property = "value";
```