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: 118 All time: 9,529 This week: 560Up
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  
Name: Mohamed Elbahja is available for providing paid consulting. Contact Mohamed Elbahja .
Classes: 12 packages by
Country: Morocco Morocco
Age: 29
All time rank: 9011 in Morocco Morocco
Week rank: 170 Up2 in Morocco Morocco Down
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

  Files folder image Files (11)  /  src  
File Role Description
Files folder imageInterfaces (1 file)
  Plain text file Environ.php Class Class source

  Files folder image Files (11)  /  src  /  Interfaces  
File Role Description
  Plain text file EnvironInterface.php Class Class source

  Files folder image Files (11)  /  tests  
File Role Description
Files folder imagedirectory (1 file)
  Accessible without login Plain text file .env Data Auxiliary data
  Plain text file EnvironTest.php Class Class source

  Files folder image Files (11)  /  tests  /  directory  
File Role Description
  Accessible without login Plain text file env.ini Data Auxiliary data

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:118
This week:0
All time:9,529
This week:560Up