Download the PHP package hashbang/envfile without Composer

On this page you can find all versions of the php package hashbang/envfile. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package envfile

PHP-EnvFile

PHP implementation of the NodeJS envfile system.

This system works by the dev placing a .env file in the root of a project. That file is read for various config information which is imported into scope. Its expected that that file is excluded from commits (via .gitignore or whatever) with every dev having their own .env file unique to them.

As an additional sanity measure its recommended that a .env.example file is placed in the same directory containing example settings. If present that file will be scanned and the variables imported into .env compared to make sure no settings are missing.

Installation

Grab the envfile.php file and drop it into your project.

Alternatively install via Composer:

composer require hashbang/envfile

Usage

The .env file

The .env file is a simple key/value file in the same form as a INI file.

a=1
b:2
c = 3
d : 4

Use within PHP

Importing this into a PHP project is straight-forward:

include('envfile.php'); // <- Not needed if you use Composer

$settings = envfile(); // If the defaults of .env (and .env.example for sanity checks) is ok

$settings = encfile('.somewhere-else', '.somewhere-else.example'); // For specific file names

$settings = encfile('.somewhere-else', '.somewhere-else.example', FALSE); // Dont fatally exit if there is a problem

Use within Bash

There is a helper script called getval which can extract a single value from a given .env file (or search directory). This can be used to extract variables into any external script:

# Extract the DBUSER variable from .env
DBUSER=`getval .env DBUSER`

# Extract the DBUSER variable from an .env file located in the parent directory
DBUSER=`getval .. DBUSER`

Use within Makefiles

As with Bash use getval to extract settings one at a time:

# Extract the DBUSER variable from .env
DBUSER=$(shell getval .env DBUSER)

# Extract the DBUSER variable from an .env file located in the parent directory
DBUSER=$(shell getval .. DBUSER)

Use within Makefiles inside CI application folders

This example assumes that:

A very specific example, but its what we use at MFDC.

The following is an example Makefile:

# Config details
DBHOST=$(shell ../vendor/hashbang/envfile/getval .. DBHOST)
DBUSER=$(shell ../vendor/hashbang/envfile/getval .. DBUSER)
DBPASS=$(shell ../vendor/hashbang/envfile/getval .. DBPASS)
DBDATABASE=$(shell ../vendor/hashbang/envfile/getval .. DBDATABASE)

# MySQL config {{{
    ifdef DBPASS
        MYSQL=mysql ${DBDATABASE} -h"${DBHOST}" -u"${DBUSER}" -p"${DBPASS}"
    else
        MYSQL=mysql ${DBDATABASE} -h"${DBHOST}"-u"${DBUSER}"
    endif
# }}}

debug:
    echo "Connection Command: ${MYSQL}"

database: database-clean
    @echo "Installing database schema..."
    ${MYSQL} <../database/Schema.sql

database-clean:
    @echo "Cleaning database [${DBDATABASE}]..."
    ${MYSQL} -e 'DROP DATABASE IF EXISTS ${DBDATABASE}; CREATE DATABASE ${DBDATABASE}'

All versions of envfile with dependencies

PHP Build Version
Package Version
Requires php Version >=5.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hashbang/envfile contains the following files

Loading the files please wait ....