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,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 View File

@@ -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
 }

Loading…
Cancel
Save