2017 © Pedro Peláez
 

library env

Library to load environments from a shell style file.

image

phossa2/env

Library to load environments from a shell style file.

  • Tuesday, September 27, 2016
  • by phossa2
  • Repository
  • 2 Watchers
  • 2 Stars
  • 113 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

phossa2/env [ABANDONED]

PLEASE USE phoole/env library instead, (*1)

Build Status Code Quality Code Climate PHP 7 ready HHVM Latest Stable Version License, (*2)

phossa2/env is a library to load environment variables from fully bash shell compatible files., (*3)

It requires PHP 5.4, supports PHP 7.0+ and HHVM. It is compliant with PSR-1, PSR-2, PSR-4., (*4)

Installation

Install via the composer utility., (*5)

composer require "phossa2/env=2.*"

or add the following lines to your composer.json, (*6)

{
    "require": {
       "phossa2/env": "2.*"
    }
}

Usage

  • Put your environments in file .env,, (*7)

    # this is comment line
    BASE_DIR='/home/web'
    
    # reference here
    APP_DIR=${BASE_DIR}/app   # another comment here
    
  • Load and use your env variables in PHP script, (*8)

    <?php
    // ...
    $env = new Phossa2\Env\Environment();
    
    # load env
    $env->load(__DIR__ . '/.env');
    
    // use your env
    echo getenv('APP_DIR');
    

Features

  • Compatible with bash if not using extended features like relaxed syntax, get current dir and file or PHP globals., (*9)

  • Support shell default values, ${param:-new} or ${param:=new}, (*10)

  • Able to source another_env_file in the env file, (*11)

  • By default, WILL overwrite any existing environment variables. This is the default behavior in bash., (*12)

    To disable overwrite and honor existing env variables,, (*13)

    env->load('./.env', $overload = false);
    
  • Relaxed syntax (not compatible with bash) in env file, (*14)

    # spaces before and after '=' is allowed. NOT recommended though
    ROOT_DIR = /var/tmp
    
  • Get current path, dir, filename with ${BASH_SOURCE}, ${BASH_SOURCE%/*}, ${BASH_SOURCE##*/}, (*15)

    # set current file
    MY_FILE=${BASH_SOURCE##*/}
    
    # set root dir to current dir
    ROOT_DIR=${BASH_SOURCE%/*}
    

    or with ${__PATH__}, ${__DIR__}, ${__FILE__}, which is not compatible with bash script., (*16)

  • Support PHP global variables like $_SERVER etc., (*17)

    This is not compatible with shell script, thus NOT recommended., (*18)

    HOST=${_SERVER.HTTP_HOST}
    
  • Support PHP 5.4+, PHP 7.0+, HHVM, (*19)

  • PHP7 ready for return type declarations and argument type declarations., (*20)

  • PSR-1, PSR-2, PSR-4 compliant., (*21)

Change log

Please see CHANGELOG from more information., (*22)

Testing

$ composer test

Contributing

Please see CONTRIBUTE for more information., (*23)

Dependencies

  • PHP >= 5.4.0, (*24)

  • phossa2/shared >= 2.0.21, (*25)

License

MIT License, (*26)

The Versions

27/09 2016

dev-master

9999999-dev https://github.com/phossa2/env

Library to load environments from a shell style file.

  Sources   Download

MIT

The Requires

 

The Development Requires

framework environment phossa phossa2

04/07 2016

2.0.5

2.0.5.0 https://github.com/phossa2/env

Library to load environments from a shell style file.

  Sources   Download

MIT

The Requires

 

library environment phossa phossa2

04/07 2016

2.0.6

2.0.6.0 https://github.com/phossa2/env

Library to load environments from a shell style file.

  Sources   Download

MIT

The Requires

 

library environment phossa phossa2

23/06 2016

2.0.4

2.0.4.0 https://github.com/phossa2/env

Library to load environments from a shell style file.

  Sources   Download

MIT

The Requires

 

library environment phossa phossa2

22/06 2016

2.0.3

2.0.3.0 https://github.com/phossa2/env

Library to load environments from a shell style file.

  Sources   Download

MIT

The Requires

 

library environment phossa phossa2

21/06 2016

2.0.2

2.0.2.0 https://github.com/phossa2/env

Library to load environments from a shell style file.

  Sources   Download

MIT

The Requires

 

library environment phossa phossa2

21/06 2016

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1 https://github.com/phossa2/env

Library to load environments from a shell style file.

  Sources   Download

MIT

The Requires

 

library environment phossa phossa2

21/06 2016

2.0.1

2.0.1.0 https://github.com/phossa2/env

Library to load environments from a shell style file.

  Sources   Download

MIT

The Requires

 

library environment phossa phossa2