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
 
66
 
67
         $this->_config["databases"] = static::resolveDatabases($this->_config["databases"]);
67
         $this->_config["databases"] = static::resolveDatabases($this->_config["databases"]);
68
 
68
 
69
+        if (!isset($this->_config['settings'])) {
70
+            $this->_config['settings'] = [];
71
+        }
72
+
69
         $this->_clients = new \SplObjectStorage;
73
         $this->_clients = new \SplObjectStorage;
70
         $this->_router = new LuRoute();
74
         $this->_router = new LuRoute();
71
         LuLog::setLogFilePath(__DIR__ . "/../../../../../../". $this->_config["logs"]);
75
         LuLog::setLogFilePath(__DIR__ . "/../../../../../../". $this->_config["logs"]);
72
         self::$_app = $this;
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
      * @return LuRoute
94
      * @return LuRoute
77
      */
95
      */

+ 16
- 0
tests/LuApplicationTest.php View File

69
         $dbs = ["mydb", $db1];
69
         $dbs = ["mydb", $db1];
70
         $this->assertSame([$db1, $db1], LuticateApplication::resolveDatabases($dbs));
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
       "host": "127.0.0.1", "database": "project",
10
       "host": "127.0.0.1", "database": "project",
11
       "username": "project", "password": "password"
11
       "username": "project", "password": "password"
12
     }
12
     }
13
-  ]
13
+  ],
14
+  "settings": {
15
+
16
+  }
14
 }
17
 }

Loading…
Cancel
Save