/
Request.php
65 lines (55 loc) · 1.57 KB
/
Request.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/* Copyright (C) 2011 by iRail vzw/asbl
*
* This is an interface to a Request
*
* @author pieterc
*/
class Request {
public static $SUPPORTED_LANGUAGES = array("EN", "NL", "FR", "DE");
public static $SUPPORTED_SYSTEMS = array("NMBS", "MIVB", "NS", "DL");
private $format = "xml";
private $lang = "EN";
private $system = "NMBS";
protected function processRequiredVars($array){
foreach($array as $var){
if(!isset($this->$var) || $this->$var == "" || is_null($this->$var)){
throw new Exception("$var not set. Please review your request and add the right parameters",401);
}
}
}
/**
* will take a get a variable from the GET array and set it as a member variable
*/
protected function setGetVar($varName, $default){
if(isset($_GET[$varName])){
$this->$varName = $_GET[$varName];
}else{
$this->$varName = $default;
}
}
function __construct() {
$this->setGetVar("format", "xml");
$this->setGetVar("lang", "EN");
$this->setGetVar("system", "NMBS");
}
public function getFormat() {
return strtolower($this->format);
}
public function getLang() {
$this->lang = strtoupper($this->lang);
if(in_array($this->lang, Request::$SUPPORTED_LANGUAGES)){
return $this->lang;
}
return "EN";
}
public function getSystem(){
$this->system = strtoupper($this->system);
if(in_array($this->system, Request::$SUPPORTED_SYSTEMS)){
return $this->system;
}else{
return "NMBS";
}
}
}
?>