Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

BrosSquad/dotenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotenv

Simple PHP Dot env parser

Latest Stable Version Total Downloads License

Installation

You can install the package through Composer.

composer require dusan/dotenv

Features

  1. Type Casting
ENV type with examples PHP type
string => "" string
numbers => 1,0,1.0 int, floats
empty values => KEY= null
boolean => true, false, yes, ok, no bool
  • Disclaimer:
    • Everything else is treated as a string. ** To convert booleans to string, put the quotes ("") around them.
      • eg. "true", "false", "ok"... *** 1,0 are never treated as boolean value, ALWAYS as an int.
  1. Interpolation

    • Example:

    APP_NAME="TestApp" OTHER="123 ${APP_NAME}" // prints out "123 TestApp"

    • Disclaimer:
      • Interpolation works previously defined variables. ** Interpolations works only in quoted strings.

Setup

First you need to instantiate EnvParser class with path to driver to .env:

  use BrosSquad\DotEnv\EnvParser;
  
 // Instantiation of EnvParser
 $dotenv = new EnvParser('.env');

 // Parsing .env file
 $dotenv->parse();

 // Loading
 $dotenv->loadIntoENV(); // Loads into $_ENV
 $dotenv->loadUsingPutEnv(); // Loading environment variables using putenv()

Advanced Usage

 use BrosSquad\DotEnv\EnvParser;
  
 // Instantiation of EnvParser
 $dotenv = new EnvParser('.env');
 
 // Gets all env keys as an array.
 $getAllEnvsIntoArray = $dotenv->getEnvs();

License

The dotenv package is open source software licensed under the Apache License 2.0