PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Mohamed Elbahja   PHP Environment Variables Setup   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Environment Variables Setup
Load and initialized PHP environment variables
Author: By
Last change:
Date: 5 years ago
Size: 1,740 bytes
 

Contents

Class file image Download

Environ Build Status PHP from Travis config Twitter

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