lcloss/env

Simple PHP environment package

dev-main 2020-10-22 19:26 UTC

This package is auto-updated.

Last update: 2024-11-29 06:22:18 UTC


README

Simple Environment package

Requirements

On root folder, create a .env file with information you need:

[database]
driver = mysql
server = localhost
port   = 3306
dbname = testdb
user   = root
password = 

[some_section]
key1    = value1
key2 = "value3"

[other_section]
key1    = value2
key2 = "value6"

Usage

Retrieving a section

use LCloss\Env\Environment;

$path_from = '.' . DIRECTORY_SEPARATOR;

$env = Environment::getInstance('.env', $path_from);
$database = $env->database;
echo $database['dbname'];

// Or...
$datbase = $env->getSection('database');
echo $database['dbname'];

Retrieving a property

use LCloss\Env\Environment;

$env = Environment::getInstance();  // Will retrieve .env file from current path
$key1 = $env->key1; // Will retrive first property with this 'key1': value1
echo $key1;

// Or...
$key1 = $env->getKey('other_section', 'key1');  // Retrieve: value2
echo $key1;