Browse Source

added settings in LuticateApplication

develop
Robin Thoni 8 years ago
parent
commit
b9fca23b67

+ 18
- 0
src/Utils/Controller/LuticateApplication.php View File

@@ -66,12 +66,30 @@ class LuticateApplication implements MessageComponentInterface
66 66
 
67 67
         $this->_config["databases"] = static::resolveDatabases($this->_config["databases"]);
68 68
 
69
+        if (!isset($this->_config['settings'])) {
70
+            $this->_config['settings'] = [];
71
+        }
72
+
69 73
         $this->_clients = new \SplObjectStorage;
70 74
         $this->_router = new LuRoute();
71 75
         LuLog::setLogFilePath(__DIR__ . "/../../../../../../". $this->_config["logs"]);
72 76
         self::$_app = $this;
73 77
     }
74 78
 
79
+    public function getSetting($name)
80
+    {
81
+        $value = getenv("lu_setting_" . $name);
82
+        if ($value === false) {
83
+            if (isset($this->_config['settings'][$name])) {
84
+                $value = $this->_config['settings'][$name];
85
+            }
86
+            else {
87
+                $value = null;
88
+            }
89
+        }
90
+        return $value;
91
+    }
92
+
75 93
     /**
76 94
      * @return LuRoute
77 95
      */

+ 16
- 0
tests/LuApplicationTest.php View File

@@ -69,4 +69,20 @@ class LuApplicationTest extends \PHPUnit_Framework_TestCase
69 69
         $dbs = ["mydb", $db1];
70 70
         $this->assertSame([$db1, $db1], LuticateApplication::resolveDatabases($dbs));
71 71
     }
72
+
73
+    public function testSettings1()
74
+    {
75
+        $this->assertSame(42, LuticateApplication::getInstance()->getSetting("test"));
76
+    }
77
+
78
+    public function testSettings2()
79
+    {
80
+        $this->assertNull(LuticateApplication::getInstance()->getSetting("not-a-setting"));
81
+    }
82
+
83
+    public function testSettings3()
84
+    {
85
+        putenv("lu_setting_test=24");
86
+        $this->assertSame("24", LuticateApplication::getInstance()->getSetting("test"));
87
+    }
72 88
 }

+ 4
- 1
tests/config.example.json View File

@@ -10,5 +10,8 @@
10 10
       "host": "127.0.0.1", "database": "project",
11 11
       "username": "project", "password": "password"
12 12
     }
13
-  ]
13
+  ],
14
+  "settings": {
15
+
16
+  }
14 17
 }

Loading…
Cancel
Save