daedalus-web / dotenv
Configuration loader from .env files
Installs: 1 017
Dependents: 6
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^6.0
README
Settings loading module for the Daedalus web application framework.
Installation
This module is typically used as part of a Daedalus web application. If you'd like to use it on your own non-Daedalus project, you can add the following to your composer.json file:
{ "require": { "daedalus-web/dotenv": "^2.0" } }
Usage
This module automatically reads settings from .env
named files, and from environment variables passed into your instance by a cloud service provider.
// Setting your file up to use Dotenv use Daedalus\Dotenv\Dotenv as Dotenv; // Getting a setting Dotenv::get('DATABASE_PASSWORD'); Dotenv::get('PROJECT_ROOT');
Env File Locations
Dotenv can read a number of different file types, from a number of different locations. Your file must be named .env
for the parser to detect it.
We currently support these locations:
- In your project root, next to your composer.json file
- A
config
directory one level deeper inside your project root, at/project_root/config/.env
We currently support the following file syntax type:
- A traditional Key=Value syntax, eg
DATABASE_PASSWORD=pocahontas
. One value per line.
Order of Precedence
Your .env
file settings will always take precedence over your system environment settings.
For .env file locations, the order of precedence is:
/.env
/config/.env
/storage/config/.env
About
Requirements
Daedalus Dotenv is fully tested to work with:
- PHP 7.0
- PHP 7.1
Strictly speaking, this module can be modified to support PHP 5.5+, however we use strict variable typing that is not available in PHP versions before 7.0. Because PHP 5.6 is no longer receiving active support (and will only be receiving security updates for another year), we strongly recommend starting any new project with PHP 7 or later.
Submitting bugs and feature requests
Bugs and feature request are tracked on GitHub
Author
Josh Grancell - josh@joshgrancell.com - https://github.com/jgrancell
License
Daedalus Dotenv is licensed under the MIT License - see the LICENSE
file for details