Skip to content

Commit d31c7c8

Browse files
committed
override defaults using envvars when present
1 parent 17e1593 commit d31c7c8

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/phpGPS_Settings.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22

3-
ini_set('display_errors',1);
4-
error_reporting(E_ALL);
3+
// enable for development only
4+
// ini_set('display_errors',1);
5+
// error_reporting(E_ALL);
56

67
class phpGPS_Settings {
8+
79
//Map Info
810
public static $_defaultZoom = 3;
911
public static $_defaultCenterLat = "41.988308";
@@ -32,5 +34,28 @@ class phpGPS_Settings {
3234

3335
//Secret key for adding an entry using addGpsEntry.php
3436
public static $_secretKey = "1234";
37+
38+
39+
// override defaults from environment variables if defined
40+
static function init() {
41+
phpGPS_Settings::$_host = phpGPS_Settings::loadFromEnv("db_hostname", phpGPS_Settings::$_host);
42+
phpGPS_Settings::$_username = phpGPS_Settings::loadFromEnv("db_username", phpGPS_Settings::$_username);
43+
phpGPS_Settings::$_password = phpGPS_Settings::loadFromEnv("db_password", phpGPS_Settings::$_password);
44+
phpGPS_Settings::$_dbname = phpGPS_Settings::loadFromEnv("db_name", phpGPS_Settings::$_dbname);
45+
46+
phpGPS_Settings::$_devKey = phpGPS_Settings::loadFromEnv("dev_key", phpGPS_Settings::$_devKey);
47+
48+
phpGPS_Settings::$_secretKey = phpGPS_Settings::loadFromEnv("secret_key", phpGPS_Settings::$_secretKey);
49+
}
50+
51+
private static function loadFromEnv($name, $default) {
52+
if (isset($_ENV[$name])) {
53+
return $_ENV[$name];
54+
} else {
55+
return $default;
56+
}
57+
}
3558
}
59+
60+
phpGPS_Settings::init();
3661
?>

0 commit comments

Comments
 (0)