Download the PHP package rancoud/environment without Composer
On this page you can find all versions of the php package rancoud/environment. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package environment
Environment Package
Read Environment file (.env).
Can complete or override data from getenv()
/ $_ENV
/ $_SERVER
Installation
.env File example
How to use it?
Warning, call constructor will not load values, you can:
- use
load()
function - use any functions that automatically call
load()
inside
Simple example
Check keys and values
Complete and Override values
Only type conversion will be done on those variables (no replacement with $
).
You have 3 differents flags:
- Environment::GETENV
- Environment::ENV
- Environment::SERVER
Complete is for filling values belong to keys having empty string or no values.
Override is for erasing values belong to keys.
The treatment given by the flags is always in the same order:
getenv()
$_ENV
$_SERVER
You can also use 3 others flags.
Those will inject all keys and values found, your env file is not used for checkings keys.
- Environment::GETENV_ALL
- Environment::ENV_ALL
- Environment::SERVER_ALL
Enable cache
The file cached will not contains informations from getenv()
/ $_ENV
/ $_SERVER
When load() is called?
For simplicity load()
is automatically called when using thoses functions:
- get
- getAll
- exists
- complete
Multiline
You can check what kind of endline it using, by default it's PHP_EOL
You can change it with for using <br>
Include another .env
Inside .env file you can include another .env file with the @
operator at the begining of the line
Constructor variations
Environment Constructor
Settings
Mandatory
Parameter | Type | Description |
---|---|---|
folder | string OR array | folder to seek .env file |
Optionnals
Parameter | Type | Default value | Description |
---|---|---|---|
filename | string | .env | custom name of .env file (don't forget to add file extension) |
Environment Methods
General Commands
- load():void
- get(name: string, [default: mixed = null]): mixed|null
- getAll(): arrray
- exists(name: string|array): bool
- allowedValues(name: string, values: array): bool
Cache File
- enableCache(): void
- disableCache(): void
- flushCache(): void
Env variables
- complete(flags: Environment::GETENV | Environment::ENV | Environment::SERVER): void
- override(flags: Environment::GETENV | Environment::ENV | Environment::SERVER): void
Multilines endline interpretation
- setEndline(endline: string): void
- getEndline(): string
How to Dev
composer ci
for php-cs-fixer and phpunit and coverage
composer lint
for php-cs-fixer
composer test
for phpunit and coverage
All versions of environment with dependencies
ext-mbstring Version >=7.4.0