Simple PHP Class to get environment depending on server name
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist proximity/detectenv "1.0.*"
or add
"proximity/detectenv": "1.0.*"
to the require section of your composer.json
file.
Once the extension is installed, simply use it in your code by :
$hosts = [
'mydevhost.dev'=>'dev',
'mytesthost.com'=>'test',
'myprodhost.com'=>'prod',
];
$env = \proximity\detectenv\DetectEnv::get($hosts);
By default if no host is found it will return null, you can change the default host by adding the second parameter:
$env = \proximity\detectenv\DetectEnv::get($hosts, 'prod');