Download the PHP package jpolvora/dotenvy without Composer
On this page you can find all versions of the php package jpolvora/dotenvy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jpolvora/dotenvy
More information about jpolvora/dotenvy
Files in jpolvora/dotenvy
Package dotenvy
Short Description PHP Environment Variables Manager with dotenv (.env) files and validation by example
License MIT
Informations about the package dotenvy
Atualizado em 2022
dotenvy
PHP Environment Variables Manager with dotenv (.env) files and validation by example
The goal is to provide a simple way to work with environment variables
Installation
WorkFlow
Create a file named .env.example
which will be shared through your dev team. This file must be commited to your repo.
Place you keys and values of your application variables.
The format is KEY=__validation-string__
For example:
There are some validators are built-in into library
Current available validators are:
-
required
: value cannot be empty, can be set to any string -
number
: value cannot be empty and must be convertible to an integer (is_numeric) -
boolean
: value cannot be empty and must be convertible to boolean (filter_var) -
enum
: value cannot be empty and should be co -
fallback
:Value can be empty, but will be fallback to desired value trim
:Just trims the string before set to env vars
important:
Order of validators are mandatory. They will run sequentially, passing the resulting value to the next validator, in a middleware mode. In case validator evaluates to invalid, the pipeline will be interrupted
Custom validators
You can create custom validators and feed Dotenvy with an array with key:value function name, function ref. Rules:
-
Validators must be functions with the following signature:
- You must always return a string that will be passed to next validator in validator chain/pipeline. If you pass null or empty string, the value will be ignored.
- If you want to invalidate the value, you must throw an exception and tell the user what happened.
Reference your validator in .env.example
Usage
Environment Results
After running Dotenvy, environment variables will be available through:
$_SERVER
$_ENV
getenv()
apache_getenv()
Important
Order of values precedence:
$_SERVER
$_ENV
getenv()
apache_getenv()
.env
file- fallback validator
- throw exception
Performance Optimization
Dotenvy can use a compiled cache file for maximum performance. The following code can be used to boost performance in production mode:
Options usage
Run tests
contributing
// todo: Fork and make pull requests.