Set and use environment from JSON file.
Inspired vlucas/phpdotenv.
Support PHP >= 5.3
Using Composer
composer.phar require kijtra/env
<?php
// Autoload only
require_once '/path/to/vendor/autoload.php';
JSON example
{
"FOO": "Foo value",
"BAR": {
"BAR-one": "Bar One value",
"BAR-two": "Bar Two value"
}
}
Usage
<?php
// Load JSON file
env(array('/path/to/example.json'));
// Or multiple files
// env(array('/path/to/example.json', '../../other.json'));
// Basic use
echo env('FOO'); // "Foo value"
// You can use dot separated name
// (better than vlucas/phpdotenv)
echo env('BAR.BAR-one'); // "Bar One value"
// Get all environments
$all = env();
// If you need clear all environment, set PHP_EOL
env(PHP_EOL);
Simple
{
"FOO": "Foo value",
"BAR": "Bar value"
}
Nested
{
"FOO": {
"FOO-one": "Foo One value",
"FOO-two": "Foo Two value"
},
"BAR": [
"Bar One value",
"Bar Two value"
]
}
Placeholder
{
"FOO": "Foo value",
"BAR": "{FOO} after Bar value"
}
And reverse replacing placeholder
(better than vlucas/phpdotenv)
{
"FOO": "{BAR} before Foo value",
"BAR": "Bar value"
}
Nested placeholder
(better than vlucas/phpdotenv)
{
"FOO": {
"FOO-one": "Foo One value",
"FOO-two": "Foo Two value"
},
"BAR": "{FOO.FOO-two} and Bar value"
}
Function env()
is alias of this class.
<?php
use \kijtra\Env;
// Load JSON file
Env::file('/path/to/env.json');
// Or multiple files
Env::file(array('/path/to/env.json', '../other.json'));
Env::file('/path/to/env.json', '../other.json');
// Basic use
echo Env::get('FOO');
// You can use dot separated name
echo Env::get('BAR.BAR-one');
// Get all environments
$all = Env::all();
// Clear all environment
Env::clear();
JavaScript(node.js) version