Skip to content

🐘 PHP environment variables 🔃 loader in $_ENV ONLY 🚤 with the power of INI syntax and ARRAY support

License

Notifications You must be signed in to change notification settings

melbahja/environ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Environ

Load PHP environment variables from .env (INI syntax) file only on $_ENV and runtime.

Build Status Twitter

Installation :

composer require melbahja/environ

Why?

Some env libraries load variables into $_SERVER and $_REQUEST, which is a stupid idea that can lead to expose credentials and insert sensitive information into log files. environ only load variables to superglobal $_ENV and runtime via putenv.

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

Note:

Arrays will not be available in getenv(), you can only access them via $_ENV or Environ::get().

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-present Mohamed Elbahja

About

🐘 PHP environment variables 🔃 loader in $_ENV ONLY 🚤 with the power of INI syntax and ARRAY support

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published