|
1 | 1 | <?php
|
2 | 2 |
|
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); |
5 | 6 |
|
6 | 7 | class phpGPS_Settings {
|
| 8 | + |
7 | 9 | //Map Info
|
8 | 10 | public static $_defaultZoom = 3;
|
9 | 11 | public static $_defaultCenterLat = "41.988308";
|
@@ -32,5 +34,28 @@ class phpGPS_Settings {
|
32 | 34 |
|
33 | 35 | //Secret key for adding an entry using addGpsEntry.php
|
34 | 36 | 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 | + } |
35 | 58 | }
|
| 59 | + |
| 60 | + phpGPS_Settings::init(); |
36 | 61 | ?>
|
0 commit comments