PHP Classes

PHP Environment Variables Setup: Load and initialized PHP environment variables

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 119 All time: 9,525 This week: 35Up
Version License PHP version Categories
environ 1.0Custom (specified...5PHP 5, Configuration, Parsers
Description 

Author

This class can load and initialized PHP environment variables.

It can take the path of a given directory and checks if a .env or .ini it exists in that directory.

The class load and parses the file that was found and sets the PHP environment variables defined in the file.

Picture of Mohamed Elbahja
  Performance   Level  
Innovation award
Innovation award
Nominee: 4x

 

Documentation

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


  Files folder image Files (11)  
File Role Description
Files folder imagesrc (1 file, 1 directory)
Files folder imagetests (2 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Image file environ.jpg Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:119
This week:0
All time:9,525
This week:35Up