2017 © Pedro PelĂĄez
 

library dotenv-php

Simple .env file parser and ENV loader (.env to getenv() and $_ENV) based on standard PHP INI parser (parse_ini_file).

image

balint-horvath/dotenv-php

Simple .env file parser and ENV loader (.env to getenv() and $_ENV) based on standard PHP INI parser (parse_ini_file).

  • Monday, October 23, 2017
  • by hbalint
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 17 % Grown

The README.md

dotenv

Simple .env file parser and ENV loader (.env to getenv() and $_ENV) based on standard PHP INI parser (parse_ini_file)., (*1)

Version 1.0 Build Passing PHP 7.0, (*2)

balint-horvath/dotenv-php balint-horvath/dotenv-php, (*3)

Supported methods: - getenv(variable) - getenv(section_variable) - $_ENV[variable] - $_ENV[section_variable] - $dotenv->variable - $dotenv->section->variable - $dotenv[variable] - $dotenv[section][variable], (*4)

Examples

Installation

To install this library, you need to use Composer in your project. If you are not using Composer yet, here's how to install:, (*5)

curl -sS https://getcomposer.org/installer | php

via Composer

composer require balint-horvath/dotenv-php

Phar

php composer.phar require balint-horvath/dotenv-php

Example Environment File (INI) (.env)

#.env
[API]
apiUser = User
apiKey = Key

Usage (Instance)

Class

Namespace: \BalintHorvath\DotEnv\, (*6)

Class: DotEnv, (*7)

new \BalintHorvath\DotEnv\DotEnv($path)

Properties

  • (string) path: Directory of .env file or full path to your ini file. (default: ../../../)
  • (bool) setEnvironmentVariables: If it's true, variables will be available via environment ($_ENV, getenv()), otherwise (if false) they'll be available only via the DotEnv as object or array ($dotenv-> $dotenv[]). (default: true)
  • (bool) processSections: If it's true, variables will be organized under sections ($dotenv->section $dotenv[section]), otherwise sections will have no matter. (default: true)
  • (bool) scannerMode: If it's INI_SCANNER_TYPED, values 0/off/"false"/false will become bool false, values 1/on/"true"/true will become bool true. Can either be INI_SCANNER_NORMAL or INI_SCANNER_RAW. If INI_SCANNER_RAW is supplied, then option values will not be parsed. (See PHP Manual: parse_ini_file and PHP Manual: Predefined Constants for more.) (default: INI_SCANNER_TYPED)

Example


define('APP_DIR', dirname(__FILE__) . '/'); require 'vendor/autoload.php'; $dotenv = new \BalintHorvath\DotEnv\DotEnv(APP_DIR);

Getting environment variables

Object Access

Usage:, (*8)

    $dotenv->{variable}
    $dotenv->{section}->{variable}

Example:, (*9)

    $dotenv->API->apiUser
    API User: <?=$dotenv->API->apiUser?>
    API Key: <?=$dotenv->API->apiKey?>

ENV Access ($_ENV)

Usage:, (*10)

    $_ENV['{variable}']
    $_ENV['{section}']['{variable}']

Example:, (*11)

    $_ENV['API_apiUser']
    API User: <?=$_ENV['API_apiUser']?>
    API Key: <?=$_ENV['API_apiKey']?>



## ENV Access (getenv) **Usage:** ```php getenv('variable') getenv('section_variable')
**Example:**
    getenv('API_apiUser')
```php API User: <?=getenv('API_apiUser')?> API Key: <?=getenv('API_apiKey')?>

## Array Access **Usage:** ```php $dotenv[{variable}] $dotenv[{section}][{variable}]
**Example:**
    $dotenv['API']['apiUser']
```php API User: <?=$dotenv['API']['apiUser']?> API Key: <?=$dotenv['API']['apiKey']?>

Dependencies

Developer Dependencies

Unit & BDD Test

This package has included test cases for Kahlan., (*12)

PSR

PSR-4 Autoload

  • \BalintHorvath\DotEnv\

The Versions

23/10 2017

dev-master

9999999-dev

Simple .env file parser and ENV loader (.env to getenv() and $_ENV) based on standard PHP INI parser (parse_ini_file).

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0

 

The Development Requires

by BĂĄlint HorvĂĄth

23/10 2017

1.0.0

1.0.0.0

Simple .env file parser and ENV loader (.env to getenv() and $_ENV) based on standard PHP INI parser (parse_ini_file).

  Sources   Download

Apache-2.0

The Requires

  • php >=7.0

 

The Development Requires

by BĂĄlint HorvĂĄth