DownloadEnviron
PHP environment loader with the power of the ini syntax and array support
![](environ.jpg?raw=true)
Installation :
composer require melbahja/environ
NOTE:
Environ has no effect to the php runtime ini configuration, environ only takes env variables from ini file and load them
Usage :
path/to/your/project/.env
; set a var
APP_MODE = "dev"
; array
[DATABASE]
HOST = '127.0.0.1'
USERNAME = 'root'
PASSWORD = null
YourScript.php
require 'vendor/autoload.php';
use Melbahja\Environ\Environ;
// environ looking for .env or env.ini file in your directory
Environ::load('path/to/your/project');
var_dump(Environ::get('APP_MODE')); // string
var_dump(Environ::get('DATABASE')); // array
var_dump($_ENV['DATABASE']); // array
Helper
# if you want a helper
function env(string $var, $default = null)
{
return \Melbahja\Environ\Environ::get($var, $default);
}
Environ methods :
Environ::load(string $directory): bool
Environ::get(string $var, $default = null): mixed
Environ::set(string $var, $value): bool
# Example: Environ::is('apache'), Environ::is('cli')
Environ::is(string $sapi): bool
License :
MIT Copyright (c) 2018 Mohamed Elbahja
|