Browse Source

default value for settings

develop
Robin Thoni 8 years ago
parent
commit
32b147f0eb
2 changed files with 7 additions and 2 deletions
  1. 2
    2
      src/Utils/Controller/LuticateApplication.php
  2. 5
    0
      tests/LuApplicationTest.php

+ 2
- 2
src/Utils/Controller/LuticateApplication.php View File

76
         self::$_app = $this;
76
         self::$_app = $this;
77
     }
77
     }
78
 
78
 
79
-    public function getSetting($name)
79
+    public function getSetting($name, $default = null)
80
     {
80
     {
81
         $value = getenv("lu_setting_" . $name);
81
         $value = getenv("lu_setting_" . $name);
82
         if ($value === false) {
82
         if ($value === false) {
84
                 $value = $this->_config['settings'][$name];
84
                 $value = $this->_config['settings'][$name];
85
             }
85
             }
86
             else {
86
             else {
87
-                $value = null;
87
+                $value = $default;
88
             }
88
             }
89
         }
89
         }
90
         return $value;
90
         return $value;

+ 5
- 0
tests/LuApplicationTest.php View File

85
         putenv("lu_setting_test=24");
85
         putenv("lu_setting_test=24");
86
         $this->assertSame("24", LuticateApplication::getInstance()->getSetting("test"));
86
         $this->assertSame("24", LuticateApplication::getInstance()->getSetting("test"));
87
     }
87
     }
88
+
89
+    public function testSettings4()
90
+    {
91
+        $this->assertSame("defaultValue", LuticateApplication::getInstance()->getSetting("not-a-setting", "defaultValue"));
92
+    }
88
 }
93
 }

Loading…
Cancel
Save