|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Arthem\GoogleApi\Infrastructure\Place; |
|
4
|
|
|
|
|
5
|
|
|
use Arthem\GoogleApi\Domain\Place\Client\PlaceClientInterface; |
|
6
|
|
|
use Arthem\GoogleApi\Infrastructure\Client\Client; |
|
7
|
|
|
use Arthem\GoogleApi\Infrastructure\Client\Decoder\DecoderInterface; |
|
8
|
|
|
use Arthem\GoogleApi\Infrastructure\Place\Hydrator\PlaceHydrator; |
|
9
|
|
|
use Arthem\GooglePlaces\Domain\Place\Exception\PlaceNotFoundException; |
|
10
|
|
|
use GuzzleHttp\ClientInterface; |
|
11
|
|
|
|
|
12
|
|
|
class PlaceClient extends Client implements PlaceClientInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* {@inheritdoc} |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $apiUrl = 'https://maps.googleapis.com/maps/api/place'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var PlaceHydrator |
|
21
|
|
|
*/ |
|
22
|
|
|
private $placeHydrator; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct( |
|
25
|
|
|
ClientInterface $httpClient, |
|
26
|
|
|
DecoderInterface $decoder, |
|
27
|
|
|
$apiKey, |
|
28
|
|
|
PlaceHydrator $placeHydrator |
|
29
|
|
|
) { |
|
30
|
|
|
parent::__construct($httpClient, $decoder, $apiKey); |
|
31
|
|
|
$this->placeHydrator = $placeHydrator; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
public function nearbysearch(array $params) |
|
38
|
|
|
{ |
|
39
|
|
|
$response = $this->request('GET', '/nearbysearch', $params); |
|
40
|
|
|
|
|
41
|
|
|
return $this->placeHydrator->hydratePlaces($response['results']); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
public function textsearch(array $params) |
|
48
|
|
|
{ |
|
49
|
|
|
$response = $this->request('GET', '/textsearch', $params); |
|
50
|
|
|
|
|
51
|
|
|
return $this->placeHydrator->hydratePlaces($response['results']); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function details(array $params) |
|
58
|
|
|
{ |
|
59
|
|
|
$response = $this->request('GET', '/details', $params); |
|
60
|
|
|
$place = $this->placeHydrator->hydratePlace($response['result']); |
|
61
|
|
|
|
|
62
|
|
|
if (null === $place) { |
|
63
|
|
|
throw new PlaceNotFoundException(sprintf('The place was not found')); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $place; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|