|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Ivory Google Map package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ivory\GoogleMap\Service\TimeZone; |
|
13
|
|
|
|
|
14
|
|
|
use Http\Client\HttpClient; |
|
15
|
|
|
use Http\Message\MessageFactory; |
|
16
|
|
|
use Ivory\GoogleMap\Service\AbstractService; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author GeLo <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class TimeZone extends AbstractService |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @param HttpClient $client |
|
25
|
|
|
* @param MessageFactory $messageFactory |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(HttpClient $client, MessageFactory $messageFactory) |
|
28
|
|
|
{ |
|
29
|
|
|
parent::__construct($client, $messageFactory, 'http://maps.googleapis.com/maps/api/timezone'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function setHttps($https) |
|
36
|
|
|
{ |
|
37
|
|
|
if (!$https) { |
|
38
|
|
|
throw new \InvalidArgumentException('The http scheme is not supported.'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
parent::setHttps($https); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param TimeZoneRequest $request |
|
46
|
|
|
* |
|
47
|
|
|
* @return TimeZoneResponse |
|
48
|
|
|
*/ |
|
49
|
|
|
public function process(TimeZoneRequest $request) |
|
50
|
|
|
{ |
|
51
|
|
|
$response = $this->getClient()->sendRequest($this->createRequest($request->buildQuery())); |
|
52
|
|
|
$data = $this->parse((string) $response->getBody()); |
|
53
|
|
|
|
|
54
|
|
|
return $this->buildResponse($data); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param string $data |
|
59
|
|
|
* |
|
60
|
|
|
* @return mixed[] |
|
61
|
|
|
*/ |
|
62
|
|
|
private function parse($data) |
|
63
|
|
|
{ |
|
64
|
|
|
if ($this->getFormat() === self::FORMAT_JSON) { |
|
65
|
|
|
return json_decode($data, true); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $this->getXmlParser()->parse($data, [], true); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param mixed[] $data |
|
73
|
|
|
* |
|
74
|
|
|
* @return TimeZoneResponse |
|
75
|
|
|
*/ |
|
76
|
|
|
private function buildResponse(array $data) |
|
77
|
|
|
{ |
|
78
|
|
|
$response = new TimeZoneResponse(); |
|
79
|
|
|
$response->setStatus($data['status']); |
|
80
|
|
|
$response->setDstOffset((int) $data['dstOffset']); |
|
81
|
|
|
$response->setRawOffset((int) $data['rawOffset']); |
|
82
|
|
|
$response->setTimeZoneId($data['timeZoneId']); |
|
83
|
|
|
$response->setTimeZoneName($data['timeZoneName']); |
|
84
|
|
|
|
|
85
|
|
|
return $response; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|