source: src/webservice/htdocs/SiWeather/Webservice/WebserviceConfig.php@ a2330fc

Last change on this file since a2330fc was 8a5cdba, checked in by Joachim Langenbach <joachim.langenbach@…>, 11 years ago
  • WebserviceApi::stationsRegister() now creates rrd file for station
    • WebserviceConfig::dataDirectory now adds a slash at the end, if needed
  • Property mode set to 100644
File size: 2.5 KB
Line 
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
21namespace SiWeather\Webservice;
22
23class 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 private function loadAdditionalConfiguration(){
36 $this->_config["dataDirectory"] = "data";
37
38 require(__DIR__ ."/../../inc/internalconfig.php");
39 foreach(array_keys($internalconfig) as $key){
40 if(array_key_exists($key, $this->_config)){
41 error_log("Internal config entry ". $key ." already exists --> Keeping existing value and discard internal config value");
42 }
43 else{
44 $this->_config[$key] = $internalconfig[$key];
45 }
46 }
47 }
48
49 public function getConfig($key){
50 if(!array_key_exists($key, $this->_config)){
51 error_log("Expected config value ". $key ." does not exists");
52 return FALSE;
53 }
54
55 if($key == "dataDirectory"){
56// error_log("Use dataDirectory() function to access this value");
57 return $this->dataDirectory();
58 }
59 if($key == "webserviceBaseUrl"){
60// error_log("Use dataDirectory() function to access this value");
61 return $this->webserviceBaseUrl();
62 }
63
64 return $this->_config[$key];
65 }
66
67 public function dataDirectory(){
68 $directory = __DIR__ ."/../../../". $this->_config["dataDirectory"];
69 if(substr($directory, strlen($directory) - 1, 1) != "/"){
70 $directory .= "/";
71 }
72 return $directory;
73 }
74
75 public function webserviceBaseUrl(){
76 $baseUrl = $this->_config["webserviceBaseUrl"];
77 if(substr($baseUrl, strlen($baseUrl) - 1, 1) != "/"){
78 $baseUrl .= "/";
79 }
80 return $baseUrl;
81 }
82
83 private $_config;
84}
85
86?>
Note: See TracBrowser for help on using the repository browser.