1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User: ms |
4
|
|
|
* Date: 29.08.15 |
5
|
|
|
* Time: 09:35 |
6
|
|
|
*/ |
7
|
|
|
namespace Mvg\RequestHandler\Html; |
8
|
|
|
|
9
|
|
|
use Zend\Http\Client; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Http |
13
|
|
|
* @package Mvg |
14
|
|
|
*/ |
15
|
|
|
class HttpGetDepartures { |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $schema; |
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $host; |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $path; |
28
|
|
|
/** |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $parameter; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param $schema |
35
|
|
|
* @param $host |
36
|
|
|
* @param $path |
37
|
|
|
*/ |
38
|
|
|
public function __construct($schema, $host, $path) { |
39
|
|
|
$this->setHost($host); |
40
|
|
|
$this->setSchema($schema); |
41
|
|
|
$this->setPath($path); |
42
|
|
|
|
43
|
|
|
$this->setParameter( |
44
|
|
|
[ |
45
|
|
|
'ubahn' => 'checked' |
46
|
|
|
, 'bus' => 'checked' |
47
|
|
|
, 'tram' => 'checked' |
48
|
|
|
, 'sbahn' => 'checked' |
49
|
|
|
] |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
* @throws \Exception |
57
|
|
|
*/ |
58
|
|
|
protected function doGetRequest() { |
59
|
|
|
|
60
|
|
|
$url = sprintf('%s://%s/%s?%s' |
|
|
|
|
61
|
|
|
, $this->getSchema() |
62
|
|
|
, $this->getHost() |
63
|
|
|
, $this->getPath() |
64
|
|
|
, http_build_query($this->getParameter(), PHP_QUERY_RFC3986) |
65
|
|
|
); |
66
|
|
|
$client = new Client(); |
67
|
|
|
$client->setUri($url) |
68
|
|
|
->setMethod(\Zend\Http\Request::METHOD_GET); |
69
|
|
|
$response = $client->send(); |
70
|
|
|
if ($response->getStatusCode() !== 200) { |
71
|
|
|
throw new \Exception(sprintf('Request Response: Status Code %d', $response->getStatusCode())); |
72
|
|
|
} |
73
|
|
|
return utf8_encode($response->getBody()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
|
|
|
|
78
|
|
|
*/ |
79
|
|
|
public function getStations() { |
80
|
|
|
//@todo implement me |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param $station |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getDeparturesForStation($station) { |
88
|
|
|
$this->addParameter('haltestelle', $station); |
89
|
|
|
$htmlResponse = $this->doGetRequest(); |
90
|
|
|
return $htmlResponse; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getNewsTicker() { |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
protected function getSchema() { |
101
|
|
|
return $this->schema; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string $schema |
106
|
|
|
*/ |
107
|
|
|
protected function setSchema($schema) { |
108
|
|
|
$this->schema = $schema; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
protected function getHost() { |
115
|
|
|
return $this->host; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string $host |
120
|
|
|
*/ |
121
|
|
|
protected function setHost($host) { |
122
|
|
|
$this->host = $host; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
protected function getPath() { |
129
|
|
|
return $this->path; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $path |
134
|
|
|
*/ |
135
|
|
|
protected function setPath($path) { |
136
|
|
|
$this->path = $path; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return string |
|
|
|
|
141
|
|
|
*/ |
142
|
|
|
public function getParameter() { |
143
|
|
|
return $this->parameter; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param string $key |
148
|
|
|
* @param string $value |
149
|
|
|
*/ |
150
|
|
|
protected function addParameter($key, $value) { |
151
|
|
|
$this->parameter[$key] = utf8_decode($value); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param array $parameter |
156
|
|
|
*/ |
157
|
|
|
protected function setParameter($parameter) { |
158
|
|
|
$this->parameter = $parameter; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
} |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.