comparison Options.inc @ 48:c6d0892f81ff

Documentation.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Tue, 09 Oct 2012 20:05:12 +0200
parents 66382989353f
children b7efe2ecbc11
comparison
equal deleted inserted replaced
47:66382989353f 48:c6d0892f81ff
1 <?php 1 <?php
2 /**
3 * Contains alle configurable parameters, and "globals"
4 *
5 * @author Tom Fredrik Blenning Klaussen
6 */
2 class Options 7 class Options
3 { 8 {
4 private $defaultLang; 9 private $defaultLang;
5 private $lang; 10 private $lang;
6 private $name; 11 private $name;
10 private $urlParams = array(); 15 private $urlParams = array();
11 private $basePath; 16 private $basePath;
12 private $flagUrl; 17 private $flagUrl;
13 private $baseUrl; 18 private $baseUrl;
14 19
20 /**
21 * Gets the default language
22 *
23 * @return two letter code for the language
24 */
15 function getDefaultLang() 25 function getDefaultLang()
16 { 26 {
17 return $this->defaultLang; 27 return $this->defaultLang;
18 } 28 }
19 29
30 /**
31 * Gets the selected language
32 *
33 * @return two letter code for the language
34 */
20 function getLang() 35 function getLang()
21 { 36 {
22 return $this->lang; 37 return $this->lang;
23 } 38 }
24 39
40 /**
41 * Get the base url, or if non set, extracts it from _SERVER
42 *
43 * @return the baseurl for the scripts
44 */
25 function getBaseUrl() 45 function getBaseUrl()
26 { 46 {
27 if ($this->baseUrl) 47 if ($this->baseUrl)
28 return $this->baseUrl; 48 return $this->baseUrl;
29 49
32 $base = ($l) ? substr($request, 0 , $l) : $request; 52 $base = ($l) ? substr($request, 0 , $l) : $request;
33 53
34 return "http://" . $_SERVER['HTTP_HOST'] . $base; 54 return "http://" . $_SERVER['HTTP_HOST'] . $base;
35 } 55 }
36 56
57 /**
58 * Replaces placeholder variables, with actual values.
59 *
60 * Currently supported values:
61 * @li \%HOST\%
62 *
63 * @param $value string to replace values in
64 * @return the processed string
65 */
37 function replacePlaceholders($value) 66 function replacePlaceholders($value)
38 { 67 {
39 $value = preg_replace('/%HOST%/', $_SERVER['HTTP_HOST'], $value); 68 $value = preg_replace('/%HOST%/', $_SERVER['HTTP_HOST'], $value);
40 return $value; 69 return $value;
41 } 70 }
42 71
72 /**
73 * Sets the base url where scripts are located
74 *
75 * @param $baseUrl the url where scripts are located
76 */
43 function setBaseUrl($baseUrl) 77 function setBaseUrl($baseUrl)
44 { 78 {
45 $baseUrl = self::replacePlaceholders($baseUrl); 79 $baseUrl = self::replacePlaceholders($baseUrl);
46 $this->baseUrl = $baseUrl; 80 $this->baseUrl = $baseUrl;
47 } 81 }
48 82
83 /**
84 * Sets the url for the flag script
85 *
86 * @param $flagUrl for flag script
87 */
49 function setFlagUrl($flagUrl) 88 function setFlagUrl($flagUrl)
50 { 89 {
51 $flagUrl = self::replacePlaceholders($flagUrl); 90 $flagUrl = self::replacePlaceholders($flagUrl);
52 $this->flagUrl = $flagUrl; 91 $this->flagUrl = $flagUrl;
53 } 92 }
54 93
94 /**
95 * Gets the url for the flag script, or autogenerate if not set
96 *
97 * @return url for flag script
98 */
55 function getFlagUrl() 99 function getFlagUrl()
56 { 100 {
57 if ($this->flagUrl) 101 if ($this->flagUrl)
58 return $this->flagUrl; 102 return $this->flagUrl;
59 103
60 return $this->getBaseUrl() . "/flag.php"; 104 return $this->getBaseUrl() . "/flag.php";
61 } 105 }
62 106
107 /**
108 * Sets the selected language
109 *
110 * @param $lang two letter code for the language
111 */
63 function setLang($lang) 112 function setLang($lang)
64 { 113 {
65 $this->lang = $lang; 114 $this->lang = $lang;
66 } 115 }
67 116
117 /**
118 * Gets the path where the scripts are located
119 *
120 * @return path where scripts are located
121 */
68 function getBasePath() 122 function getBasePath()
69 { 123 {
70 return $this->basePath; 124 return $this->basePath;
71 } 125 }
72 126
127 /**
128 * Sets the path where the scripts are located
129 *
130 * @param $basePath path where scripts are located
131 */
73 function setBasePath($basePath) 132 function setBasePath($basePath)
74 { 133 {
75 $this->basePath = $basePath; 134 $this->basePath = $basePath;
76 } 135 }
77 136
137 /**
138 * Sets a set of urlparameters
139 *
140 * @param $urlParams list of parameters to get from the URL
141 */
78 function setUrlParams($urlParams) 142 function setUrlParams($urlParams)
79 { 143 {
80 foreach($urlParams as $key) { 144 foreach($urlParams as $key) {
81 $value = array_key_exists($key, $_GET) ? $_GET[$key] : ''; 145 $value = array_key_exists($key, $_GET) ? $_GET[$key] : '';
82 $this->urlParams[$key] = $value; 146 $this->urlParams[$key] = $value;
83 } 147 }
84 } 148 }
85 149
150 /**
151 * Gets the default language
152 *
153 * @return associative array of key and value for the url parameters
154 */
86 function getUrlParams() 155 function getUrlParams()
87 { 156 {
88 return $this->urlParams; 157 return $this->urlParams;
89 } 158 }
90 159
160 /**
161 * Sets the name(identity) for this page
162 *
163 * @param $name name(identity)
164 */
91 function setName($name) 165 function setName($name)
92 { 166 {
93 $this->name = $name; 167 $this->name = $name;
94 } 168 }
95 169
170 /**
171 * Gets the name(identity) for this page
172 *
173 * @return name(identity)
174 */
96 function getName() 175 function getName()
97 { 176 {
98 return $this->name; 177 return $this->name;
99 } 178 }
100 179
180 /**
181 * Sets a cache object
182 *
183 * @param $cache CacheTimeCheck object
184 */
101 function setCache($cache) 185 function setCache($cache)
102 { 186 {
103 $this->cache = $cache; 187 $this->cache = $cache;
104 } 188 }
105 189
190 /**
191 * Gets the cache object
192 *
193 * @return cache object
194 */
106 function getCache() 195 function getCache()
107 { 196 {
108 return $this->cache; 197 return $this->cache;
109 } 198 }
110 199
200 /**
201 * A list of languages which this configuration supports.
202 *
203 * @return array of two letter language codes
204 */
111 function getAcceptedLanguages() 205 function getAcceptedLanguages()
112 { 206 {
113 return $this->acceptedLanguages; 207 return $this->acceptedLanguages;
114 } 208 }
115 209
210 /**
211 * Gets the default value associated whith the key
212 *
213 * @param $key as specified in master xml file.
214 * @return associated default
215 */
116 function getInputDefault($key) 216 function getInputDefault($key)
117 { 217 {
118 return $this->inputDefaults[$key]; 218 return $this->inputDefaults[$key];
119 } 219 }
120 220
221 /**
222 * Constructs an options object
223 *
224 * This contstructor will consume any tag with the type option, and
225 * extract values from any tag with type input
226 *
227 * @include master.xml
228 *
229 * @param $baseDocument An open xml file
230 */
121 function __construct($baseDocument) 231 function __construct($baseDocument)
122 { 232 {
123 $params = $baseDocument->getElementsByTagName("param"); 233 $params = $baseDocument->getElementsByTagName("param");
124 $toRemove = array(); 234 $toRemove = array();
125 foreach ($params as $param) { 235 foreach ($params as $param) {