Download the PHP package abdeslam/envator without Composer
On this page you can find all versions of the php package abdeslam/envator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package envator
Envator package
Envator is a .env file loader that supports loading multiple files, caching (using psr-16 simple-cache interface) and using filters that enable type casting of booleans, numerics and variables inside values and more ...
Table of contents
- Requirements
- Installation
- 1. Using Composer
- 2. Manually
- Usage
- 1. using the class Envator directly
- 2. using the factory
- 3. adding filters
- 4. filters using the factory
- 5. custom filters
- 6. options
- 7. caching
- Customization
Requirements
- PHP 8.0 and above.
Installation
1. Using Composer
You can install the library via Composer.
or
2. Manually
If you're not using Composer, you can also clone Abdeslam/Envator
repository into your directory:
However, using Composer is recommended as you can easily keep the library up-to-date.
Usage
#
1. using the class Envator directly
let's assume that's your .env
file
in your php
code :
loading multiple .env files
2. using the factory
3. adding filters
filters allow operating on the the keys and values after the parsing of the .env
file. Envator package provide 5 filters and you can add custom ones.
TrimQuotesFilter::class
: trims the quotes of the string keys and values.BooleanValuesFilter::class
: casts 'true' and 'false' strings to booleans (case insensitive).NumericValueFilter::class
: casts numeric string values to integers and floats.EmptyStringToNullFilter::class
: casts empty strings '' to NULL.VariableFilter::class
: replaces variables inside values (variable must defined before using it inside values). see example below
let's assume that is your .env file :
in your php
code :
CAVEATS :
- using getenv() function : it does not support booleans (TRUE and FALSE) and NULL, they get type casted to string : TRUE => '1', FALSE => '', NULL => ''.
4. filters using the factory
the factory loads the default filters 5 automatically, to change this behavior :
or
or
5. custom filters
A filter must be a class that implements Abdeslam\Envator\Contracts\FilterInterface
:
if we take this .env variables for example :
6. options
when populating the variables to the environment, you can specify what way the variables are populated by passing an array as an argument to Envator::populate()
method :
7. caching
Envator support any implementation of psr-16 (simple-cache), and provides a default one :
or
Customization
- Creating a custom .env files Resolver and Parser classes, they must implement
Abdeslam\Envator\ResolverInterface
andAbdeslam\Envator\ParserInterface
.
Made with love :heart: