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

Last change on this file since 552da81 was 552da81, checked in by Joachim Langenbach <joachim.langenbach@…>, 11 years ago

Fixed inconsistent slash handling in WEBSERVICE_BASE_URL cmake setting and further processing in the php files

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[8c356c1]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(){
[1e37648]26 require(__DIR__ ."/../../../config/config.php");
[8c356c1]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";
[1e37648]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 }
[8c356c1]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 }
[1e37648]59 if($key == "webserviceBaseUrl"){
60// error_log("Use dataDirectory() function to access this value");
61 return $this->webserviceBaseUrl();
62 }
[8c356c1]63
64 return $this->_config[$key];
65 }
66
67 public function dataDirectory(){
[1e37648]68 return __DIR__ ."/../../../". $this->_config["dataDirectory"];
69 }
70
71 public function webserviceBaseUrl(){
72 $baseUrl = $this->_config["webserviceBaseUrl"];
[552da81]73 if(substr($baseUrl, strlen($baseUrl), 1) != "/"){
[1e37648]74 $baseUrl .= "/";
75 }
76 return $baseUrl;
[8c356c1]77 }
78
79 private $_config;
80}
81
82?>
Note: See TracBrowser for help on using the repository browser.