|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Laravel WuBook. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Filippo Galante <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace IlGala\LaravelWubook; |
|
13
|
|
|
|
|
14
|
|
|
use fXmlRpc\Client; |
|
15
|
|
|
use fXmlRpc\Parser\NativeParser; |
|
16
|
|
|
use fXmlRpc\Serializer\NativeSerializer; |
|
17
|
|
|
use Illuminate\Contracts\Config\Repository; |
|
18
|
|
|
use IlGala\LaravelWubook\Exceptions\WuBookException; |
|
19
|
|
|
use IlGala\LaravelWubook\Api\WuBookAuth; |
|
20
|
|
|
use IlGala\LaravelWubook\Api\WuBookAvailability; |
|
21
|
|
|
use IlGala\LaravelWubook\Api\WuBookCancellationPolicies; |
|
22
|
|
|
use IlGala\LaravelWubook\Api\WuBookChannelManager; |
|
23
|
|
|
use IlGala\LaravelWubook\Api\WuBookCorporate; |
|
24
|
|
|
use IlGala\LaravelWubook\Api\WuBookExtras; |
|
25
|
|
|
use IlGala\LaravelWubook\Api\WuBookPrices; |
|
26
|
|
|
use IlGala\LaravelWubook\Api\WuBookReservations; |
|
27
|
|
|
use IlGala\LaravelWubook\Api\WuBookRestrictions; |
|
28
|
|
|
use IlGala\LaravelWubook\Api\WuBookRooms; |
|
29
|
|
|
use IlGala\LaravelWubook\Api\WuBookTransactions; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* This is the WuBook manager class. |
|
33
|
|
|
* |
|
34
|
|
|
* @author Filippo Galante <[email protected]> |
|
35
|
|
|
*/ |
|
36
|
|
|
class WuBookManager |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
const ENDPOINT = 'https://wubook.net/xrws/'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var array |
|
46
|
|
|
*/ |
|
47
|
|
|
private $config; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var Illuminate\Cache\Repository |
|
51
|
|
|
*/ |
|
52
|
|
|
private $cache; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Create a new WuBook Instance. |
|
56
|
|
|
* |
|
57
|
|
|
* @param Repository $config |
|
58
|
|
|
* @throws WuBookException |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __construct(Repository $config) |
|
61
|
|
|
{ |
|
62
|
|
|
// Setup credentials |
|
63
|
|
|
$this->config = array_only($config->get('wubook'), ['username', 'password', 'provider_key', 'lcode']); |
|
64
|
|
|
|
|
65
|
|
|
// Credentials check |
|
66
|
|
|
if (!array_key_exists('username', $this->config) || !array_key_exists('password', $this->config) || !array_key_exists('provider_key', $this->config) || !array_key_exists('lcode', $this->lcode)) { |
|
|
|
|
|
|
67
|
|
|
throw new WuBookException('Credentials are required!'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (!array_key_exists('cache_token', $this->config)) { |
|
71
|
|
|
$this->config['cache_token'] = false; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// Utilities |
|
75
|
|
|
$this->cache = app()['cache']; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Auth API |
|
80
|
|
|
* |
|
81
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookAuth |
|
82
|
|
|
*/ |
|
83
|
|
View Code Duplication |
public function auth() |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
// Setup client |
|
86
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
87
|
|
|
|
|
88
|
|
|
return new WuBookAuth($this->config, $this->cache, $client); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Availability API |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $token |
|
95
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookAvailability |
|
96
|
|
|
*/ |
|
97
|
|
View Code Duplication |
public function availability($token = null) |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
// Setup client |
|
100
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
101
|
|
|
|
|
102
|
|
|
return new WuBookAvailability($this->config, $this->cache, $client, $token); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Cancellation polices API |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $token |
|
109
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookCancellationPolicies |
|
110
|
|
|
*/ |
|
111
|
|
|
public function cancellation_policies($token = null) |
|
112
|
|
|
{ |
|
113
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
114
|
|
|
|
|
115
|
|
|
return new WuBookCancellationPolicies($this->config, $this->cache, $client, $token); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Channel manager API |
|
120
|
|
|
* |
|
121
|
|
|
* @param string $token |
|
122
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookChannelManager |
|
123
|
|
|
*/ |
|
124
|
|
View Code Duplication |
public function channel_manager($token = null) |
|
|
|
|
|
|
125
|
|
|
{ |
|
126
|
|
|
// Setup client |
|
127
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
128
|
|
|
|
|
129
|
|
|
return new WuBookChannelManager($this->config, $this->cache, $client, $token); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Corporate function API |
|
134
|
|
|
* |
|
135
|
|
|
* @param string $token |
|
136
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookCorporate |
|
137
|
|
|
*/ |
|
138
|
|
View Code Duplication |
public function corporate_functions($token = null) |
|
|
|
|
|
|
139
|
|
|
{ |
|
140
|
|
|
// Setup client |
|
141
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
142
|
|
|
|
|
143
|
|
|
return new WuBookCorporate($this->config, $this->cache, $client, $token); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Extra functions API |
|
148
|
|
|
* |
|
149
|
|
|
* @param string $token |
|
150
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookExtras |
|
151
|
|
|
*/ |
|
152
|
|
View Code Duplication |
public function extras($token = null) |
|
|
|
|
|
|
153
|
|
|
{ |
|
154
|
|
|
// Setup client |
|
155
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
156
|
|
|
|
|
157
|
|
|
return new WuBookExtras($this->config, $this->cache, $client, $token); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Prices API |
|
162
|
|
|
* |
|
163
|
|
|
* @param string $token |
|
164
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookPrices |
|
165
|
|
|
*/ |
|
166
|
|
View Code Duplication |
public function prices($token = null) |
|
|
|
|
|
|
167
|
|
|
{ |
|
168
|
|
|
// Setup client |
|
169
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
170
|
|
|
|
|
171
|
|
|
return new WuBookPrices($this->config, $this->cache, $client, $token); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Reservations API |
|
176
|
|
|
* |
|
177
|
|
|
* @param string $token |
|
178
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookPrices |
|
179
|
|
|
*/ |
|
180
|
|
View Code Duplication |
public function reservations($token = null) |
|
|
|
|
|
|
181
|
|
|
{ |
|
182
|
|
|
// Setup client |
|
183
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
184
|
|
|
|
|
185
|
|
|
return new WuBookReservations($this->config, $this->cache, $client, $token); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Restrictions API |
|
190
|
|
|
* |
|
191
|
|
|
* @param string $token |
|
192
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookRestrictions |
|
193
|
|
|
*/ |
|
194
|
|
View Code Duplication |
public function restrictions($token = null) |
|
|
|
|
|
|
195
|
|
|
{ |
|
196
|
|
|
// Setup client |
|
197
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
198
|
|
|
|
|
199
|
|
|
return new WuBookRestrictions($this->config, $this->cache, $client, $token); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Rooms API |
|
204
|
|
|
* |
|
205
|
|
|
* @param string $token |
|
206
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookRooms |
|
207
|
|
|
*/ |
|
208
|
|
View Code Duplication |
public function rooms($token = null) |
|
|
|
|
|
|
209
|
|
|
{ |
|
210
|
|
|
// Setup client |
|
211
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
212
|
|
|
|
|
213
|
|
|
return new WuBookRooms($this->config, $this->cache, $client, $token); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Transactions API |
|
218
|
|
|
* |
|
219
|
|
|
* @param string $token |
|
220
|
|
|
* @return IlGala\LaravelWubook\Api\WuBookTransactions |
|
221
|
|
|
*/ |
|
222
|
|
View Code Duplication |
public function transactions($token = null) |
|
|
|
|
|
|
223
|
|
|
{ |
|
224
|
|
|
// Setup client |
|
225
|
|
|
$client = new Client(self::ENDPOINT, null, new NativeParser(), new NativeSerializer()); |
|
226
|
|
|
|
|
227
|
|
|
return new WuBookTransactions($this->config, $this->cache, $client, $token); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Username getter. |
|
232
|
|
|
* |
|
233
|
|
|
* @return string |
|
234
|
|
|
*/ |
|
235
|
|
|
public function get_username() |
|
236
|
|
|
{ |
|
237
|
|
|
return $this->username; |
|
|
|
|
|
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Password getter. |
|
242
|
|
|
* |
|
243
|
|
|
* @return string |
|
244
|
|
|
*/ |
|
245
|
|
|
public function get_password() |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->password; |
|
|
|
|
|
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* Provider key getter. |
|
252
|
|
|
* |
|
253
|
|
|
* @return string |
|
254
|
|
|
*/ |
|
255
|
|
|
public function get_provider_key() |
|
256
|
|
|
{ |
|
257
|
|
|
return $this->provider_key; |
|
|
|
|
|
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* Client getter. |
|
262
|
|
|
* |
|
263
|
|
|
* @return PhpXmlRpc\Client |
|
264
|
|
|
*/ |
|
265
|
|
|
public function get_client() |
|
266
|
|
|
{ |
|
267
|
|
|
return $this->client; |
|
|
|
|
|
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: