1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Afonso\Emt; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use GuzzleHttp\Client as Guzzle; |
7
|
|
|
use RuntimeException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* The SDK client for the EMT OpenData API. |
11
|
|
|
* |
12
|
|
|
* @author Carlos Afonso Pérez <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class Client |
15
|
|
|
{ |
16
|
|
|
const ENDPOINT = 'https://openbus.emtmadrid.es:9443'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The request launcher instance. |
20
|
|
|
* |
21
|
|
|
* @var \Afonso\Emt\RequestLauncher |
22
|
|
|
*/ |
23
|
|
|
protected $launcher; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Create a new Client instance with the given client ID and passkey. |
27
|
|
|
* |
28
|
|
|
* @param string $clientId |
29
|
|
|
* @param string $passkey |
30
|
|
|
*/ |
31
|
|
|
public function __construct($clientId, $passkey) |
32
|
|
|
{ |
33
|
|
|
// $client = new Guzzle(['base_uri' => self::ENDPOINT]); |
|
|
|
|
34
|
|
|
$this->launcher = new RequestLauncher($clientId, $passkey/*, $client*/); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Return the itinerary of one or more lines. |
39
|
|
|
* |
40
|
|
|
* @var int[] $lines |
41
|
|
|
* @var \DateTime $date |
42
|
|
|
* @return \stdClass |
43
|
|
|
* @throws \RuntimeException |
44
|
|
|
*/ |
45
|
|
|
public function getRouteLines(array $lines, DateTime $date) |
46
|
|
|
{ |
47
|
|
|
$params = [ |
48
|
|
|
'Lines' => join('|', $lines), |
49
|
|
|
'SelectDate' => $date->format('d/m/Y'), |
50
|
|
|
]; |
51
|
|
|
return $this->launcher |
52
|
|
|
->launchRequest(self::ENDPOINT . '/emt-proxy-server/last/bus/GetRouteLines.php', $params) |
53
|
|
|
->resultValues; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Return calendar details for the given date interval. |
58
|
|
|
* |
59
|
|
|
* @var \DateTime $startDate |
60
|
|
|
* @var \DateTime $endDate |
61
|
|
|
* @return \stdClass |
62
|
|
|
* @throws \RuntimeException |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
public function getCalendar(DateTime $startDate, DateTime $endDate) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$params = [ |
67
|
|
|
'SelectDateBegin' => $startDate->format('d/m/Y'), |
68
|
|
|
'SelectDateEnd' => $endDate->format('d/m/Y'), |
69
|
|
|
]; |
70
|
|
|
return $this->launcher |
71
|
|
|
->launchRequest(self::ENDPOINT . '/emt-proxy-server/last/bus/GetCalendar.php', $params) |
72
|
|
|
->resultValues; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Return a list with line details. |
77
|
|
|
* |
78
|
|
|
* @var int[] $lines |
79
|
|
|
* @var \DateTime $date |
80
|
|
|
* @return \stdClass |
81
|
|
|
* @throws \RuntimeException |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function getListLines(array $lines, DateTime $date) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$params = [ |
86
|
|
|
'Lines' => join('|', $lines), |
87
|
|
|
'SelectDate' => $date->format('d/m/Y'), |
88
|
|
|
]; |
89
|
|
|
return $this->launcher |
90
|
|
|
->launchRequest(self::ENDPOINT . '/emt-proxy-server/last/bus/GetListLines.php', $params) |
91
|
|
|
->resultValues; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Return details about all line groups. |
96
|
|
|
* |
97
|
|
|
* @return \stdClass |
98
|
|
|
* @throws \RuntimeException |
99
|
|
|
*/ |
100
|
|
|
public function getGroups() |
101
|
|
|
{ |
102
|
|
|
return $this->launcher |
103
|
|
|
->launchRequest(self::ENDPOINT . '/emt-proxy-server/last/bus/GetGroups.php') |
104
|
|
|
->resultValues; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Return start and end operation times of one or more lines. |
109
|
|
|
* |
110
|
|
|
* @var int[] $lines |
111
|
|
|
* @var \DateTime $date |
112
|
|
|
* @return \stdClass |
113
|
|
|
* @throws \RuntimeException |
114
|
|
|
*/ |
115
|
|
View Code Duplication |
public function getTimesLines(array $lines, DateTime $date) |
|
|
|
|
116
|
|
|
{ |
117
|
|
|
$params = [ |
118
|
|
|
'Lines' => join('|', $lines), |
119
|
|
|
'SelectDate' => $date->format('d/m/Y'), |
120
|
|
|
]; |
121
|
|
|
return $this->launcher |
122
|
|
|
->launchRequest(self::ENDPOINT . '/emt-proxy-server/last/bus/GetTimesLines.php', $params) |
123
|
|
|
->resultValues; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Return timetable details of one or more lines. |
128
|
|
|
* |
129
|
|
|
* @var int[] $lines |
130
|
|
|
* @var \DateTime $date |
131
|
|
|
* @return \stdClass |
132
|
|
|
* @throws \RuntimeException |
133
|
|
|
*/ |
134
|
|
View Code Duplication |
public function getTimeTableLines(array $lines, DateTime $date) |
|
|
|
|
135
|
|
|
{ |
136
|
|
|
$params = [ |
137
|
|
|
'Lines' => join('|', $lines), |
138
|
|
|
'SelectDate' => $date->format('d/m/Y'), |
139
|
|
|
]; |
140
|
|
|
return $this->launcher |
141
|
|
|
->launchRequest(self::ENDPOINT . '/emt-proxy-server/last/bus/GetTimeTableLines.php', $params) |
142
|
|
|
->resultValues; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Return details of one or more bus stops including name, served lines |
147
|
|
|
* and geographic coordinates. |
148
|
|
|
* |
149
|
|
|
* @var int[] $stopIds |
150
|
|
|
* @return \stdClass |
151
|
|
|
* @throws \RuntimeException |
152
|
|
|
*/ |
153
|
|
|
public function getNodesLines(array $stopIds) |
154
|
|
|
{ |
155
|
|
|
$params = [ |
156
|
|
|
'Nodes' => join('|', $stopIds), |
157
|
|
|
]; |
158
|
|
|
return $this->launcher |
159
|
|
|
->launchRequest(self::ENDPOINT . '/emt-proxy-server/last/bus/GetNodesLines.php', $params) |
160
|
|
|
->resultValues; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.