PHP Classes
elePHPant
Icontem

PHP Environment Variables Setup: Load and initialized PHP environment variables

Recommend this page to a friend!
  Info   View files Documentation   View files View files (11)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-03-02 (13 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 2 This week: 2All time: 9,533 This week: 258Up
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.

  Performance   Level  
Name: Mohamed Elbahja <contact>
Classes: 12 packages by
Country: Morocco Morocco
Innovation award
Innovation award
Nominee: 4x

Details

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  
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  /  src  
File Role Description
Files folder imageInterfaces (1 file)
  Plain text file Environ.php Class Class source

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

  Files folder image Files  /  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  /  tests  /  directory  
File Role Description
  Accessible without login Plain text file env.ini Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:2
This week:2
All time:9,533
This week:258Up