Use prefixed properties in .env files

As mentioned in discussion regarding database config files, BaseConfig
should prefer env vars prefixed with the classname (and a dot (.)
separator) over env vars using the property name alone.
This commit is contained in:
mwhitneysdsu 2016-01-29 10:00:54 -08:00
parent 56cfbaf406
commit 87d3c1ce24

View File

@ -20,10 +20,15 @@ class BaseConfig
public function __construct()
{
$properties = array_keys(get_object_vars($this));
$prefix = get_class($this);
foreach ($properties as $property)
{
if ($value = getenv($property))
if ($value = getenv("{$prefix}.{$property}"))
{
$this->{$property} = $value;
}
elseif ($value = getenv($property))
{
$this->{$property} = $value;
}