Procházet zdrojové kódy

default value for settings

develop
Robin Thoni před 8 roky
rodič
revize
32b147f0eb

+ 2
- 2
src/Utils/Controller/LuticateApplication.php Zobrazit soubor

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

+ 5
- 0
tests/LuApplicationTest.php Zobrazit soubor

@@ -85,4 +85,9 @@ class LuApplicationTest extends \PHPUnit_Framework_TestCase
85 85
         putenv("lu_setting_test=24");
86 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
 }

Načítá se…
Zrušit
Uložit