| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This library is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 7 | License as published by the Free Software Foundation; either
|
|---|
| 8 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This library is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | Lesser General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | License along with this library; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|---|
| 18 | MA 02110-1301 USA.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | namespace SiWeather\Webservice;
|
|---|
| 22 |
|
|---|
| 23 | class WebserviceConfig {
|
|---|
| 24 |
|
|---|
| 25 | function __construct(){
|
|---|
| 26 | require(__DIR__ ."/../../../config/config.php");
|
|---|
| 27 | $this->_config = $config;
|
|---|
| 28 | $this->loadAdditionalConfiguration();
|
|---|
| 29 |
|
|---|
| 30 | if($this->getConfig("mode") == "development"){
|
|---|
| 31 | error_reporting(E_ALL);
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | static public function value($key){
|
|---|
| 36 | $webserviceConfig = new WebserviceConfig();
|
|---|
| 37 | return $webserviceConfig->getConfig($key);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | private function loadAdditionalConfiguration(){
|
|---|
| 41 | $this->_config["dataDirectory"] = "data";
|
|---|
| 42 |
|
|---|
| 43 | require(__DIR__ ."/../../inc/internalconfig.php");
|
|---|
| 44 | foreach(array_keys($internalconfig) as $key){
|
|---|
| 45 | if(array_key_exists($key, $this->_config)){
|
|---|
| 46 | error_log("Internal config entry ". $key ." already exists --> Keeping existing value and discard internal config value");
|
|---|
| 47 | }
|
|---|
| 48 | else{
|
|---|
| 49 | $this->_config[$key] = $internalconfig[$key];
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | public function getConfig($key){
|
|---|
| 55 | if(!array_key_exists($key, $this->_config)){
|
|---|
| 56 | error_log("Expected config value ". $key ." does not exists");
|
|---|
| 57 | return FALSE;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | if($key == "dataDirectory"){
|
|---|
| 61 | // error_log("Use dataDirectory() function to access this value");
|
|---|
| 62 | return $this->dataDirectory();
|
|---|
| 63 | }
|
|---|
| 64 | if($key == "webserviceBaseUrl"){
|
|---|
| 65 | // error_log("Use dataDirectory() function to access this value");
|
|---|
| 66 | return $this->webserviceBaseUrl();
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | return $this->_config[$key];
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | public function dataDirectory(){
|
|---|
| 73 | $directory = __DIR__ ."/../../../". $this->_config["dataDirectory"];
|
|---|
| 74 | if(substr($directory, strlen($directory) - 1, 1) != "/"){
|
|---|
| 75 | $directory .= "/";
|
|---|
| 76 | }
|
|---|
| 77 | return $directory;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | public function webserviceBaseUrl(){
|
|---|
| 81 | $baseUrl = $this->_config["webserviceBaseUrl"];
|
|---|
| 82 | if(substr($baseUrl, strlen($baseUrl) - 1, 1) != "/"){
|
|---|
| 83 | $baseUrl .= "/";
|
|---|
| 84 | }
|
|---|
| 85 | return $baseUrl;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | private $_config;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | ?>
|
|---|