Environment manager
, (*1)
, (*2)
The Environment manager
parses, populates dot environment variables from env files to super global $_ENV variable, apache and getenv function.
It supports for checking variables and fetching system only variables., (*3)
It provides for editing environment file and manipulate them., (*4)
, (*5)
Donations
Due I am working 100% alone without any helps, organizations and any others team I can be satisfy for receiving any amount of payment to improve, develop and continue building on origin idea of framework., (*6)
You can pay any amount to PayPal: https://www.paypal.me/codervio?locale.x=en_US, (*7)
Installation
- Installation via Composer on Packagist
- Installation using Git GIT clone component
Prerequisities
PHP version requirements: PHP >7.0, (*8)
PHP extension: mbstring, (*9)
Use use Codervio\Environment\EnvParser
declaration for parsing dot env files., (*10)
Use use Codervio\Environment\EnvEditor
declaration for edit and manage dot env file., (*11)
A [requirements
] - Requirements and auto detect encodings script automatically can check mbstring extension and automatically detects encoding types., (*12)
Usage
Example of fetching env variables and loading into global super variables like $_ENV
, using function getenv()
or directly using instance:, (*13)
If on a file example.env contains a data:, (*14)
FOO=bar
After loading instance it can be fetching a variable:, (*15)
use Codervio\Envmanager\Envparser;
$envparser = new Envparser('.env');
$envparser->load();
$envparser->run();
$result = $parser->getValue('FOO');
var_dump($result);
Returns a result will automatically detect type of getting env variables:, (*16)
(string) 'bar'
Or get a result using env variables globally:, (*17)
echo apache_getenv('FOO')
echo getenv('FOO')
echo $_ENV('FOO')
Returning a result
A result returns in following orders:
- using apache_getenv() if apache service is configured internally to use only Apache environment
- using getenv() that most Unix systems supports
- using PHP native super globals $_ENV function, (*18)
It will automatically parse to PHP env functions and super globals so you can access via:
- superglobals functions $_ENV
- superglobals $_SERVER variable
- using getenv() if is enabled by system
- using apache_getenv() if is enabled by Apache service, (*19)
Changelog
Status of core:, (*20)
Version |
State |
1.0 |
Release version |
PHP version above 7.0
.
Quality assurance: Unit tests provided, (*21)
Table of Contents
Envparser
Common env variables
- For loading simple ENV variables use [
example
]
FOO=bar
VAREMPTY=
FOO1=foo1
WITHSPACES="with spaces"
Lists examples env variables
- Lists of examples env variables: [
lists
]
- Writing comments: [
comments
]
# comment
# a comment #comment
## A main comment ##
FOO=bar # a comment
It is possible to parse comments variables such using:, (*22)
new Envparser('main.env', true);
A variable inside comment can be visible, (*23)
#COM1=BAR1
using command:, (*24)
$envparser->getAllValues(); # to get all values
$envparser->getValue('#COM1'); # to get commented key
which returns as array and keeps # mark:, (*25)
["#COM1"]=>
string(4) "BAR1"
or directly:, (*26)
$envparser->getValue('#COM1');
will parsing a variable, (*27)
string(4) "BAR1"
Parsing apache env variables or unix exports env variables
- Parsing export or setenv variables: [
envexports
]
setenv FOO1=value # general csh case
export FOO2=value
SetEnv FOO3=value # Apache camel case
Get a system only variables
It is possible to fetch all system variables:, (*28)
use Codervio\Envmanager\Envparser;
$envparser = new Envparser();
$envparser->load();
$envparser->run();
var_dump($envparser->getSystemVars());
- For fetching single variable or just check a variable exists see [
getSystemVars
] and [checkSystemVar()
].
- See validation types for values in environment variables: [
required()
]
- To fetch a comment from a file of specific variable use: [
getComment()
]
References
- [
requirements
] - Requirements and auto detect encodings
- [
setEncoding()
] - Manually specify encoding
- [
getEncoding()
] - Detect encoding type from file
- [
checkSuperGlobalsSet()
] - Check if set or get env directive for $_ENV active
- [
Envparser()
] - A construct parser constructor
- [
load()
] - Load an environment .env file or folder with .env files
- [
getComment()
] - Get a comment from a variable of .env file
- [
getValue()
] - Get a value from system environment variables and parsing variables
- [
getAllValues()
] - Returns parsed environment variables internally as array
- [
getSystemVars()
] - Fetch all or one system variables
- [
checkSystemVar()
]- Returns boolean if system variables exists
- [
setStrictBool()
] - Parse value to boolen on non-standard values such as 'y/n' or '1/0'
- [
required()
] - Instance of variable validator and variable validators
EnvEditor
- [
Enveditor
] - Instance environment for creating environment file
- [
Help
] - Common helps and issues in a code