|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace kalanis\google_maps\Services; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use kalanis\google_maps\ServiceException; |
|
7
|
|
|
use Psr\Http\Message\RequestInterface; |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Place Details service |
|
12
|
|
|
* |
|
13
|
|
|
* @see https://developers.google.com/maps/documentation/places/web-service/details |
|
14
|
|
|
*/ |
|
15
|
|
|
class PlaceDetails extends AbstractService |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string[] |
|
19
|
|
|
*/ |
|
20
|
|
|
protected array $allowedFields = [ |
|
21
|
|
|
// basic |
|
22
|
|
|
'address_components', 'adr_address', 'business_status', 'formatted_address', 'geometry', 'icon', |
|
23
|
|
|
'icon_mask_base_uri', 'icon_background_color', 'name', 'photo', 'place_id', 'plus_code', 'type', |
|
24
|
|
|
'url', 'utc_offset', 'vicinity', 'wheelchair_accessible_entrance', |
|
25
|
|
|
// contact |
|
26
|
|
|
'current_opening_hours', 'formatted_phone_number', 'international_phone_number', 'opening_hours', |
|
27
|
|
|
'secondary_opening_hours', 'website', |
|
28
|
|
|
// atmosphere |
|
29
|
|
|
'curbside_pickup', 'delivery', 'dine_in', 'editorial_summary', 'price_level', 'rating', 'reservable', |
|
30
|
|
|
'reviews', 'serves_beer', 'serves_breakfast', 'serves_brunch', 'serves_dinner', 'serves_lunch', |
|
31
|
|
|
'serves_vegetarian_food', 'serves_wine', 'takeout', 'user_ratings_total', |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string[] |
|
36
|
|
|
*/ |
|
37
|
|
|
protected array $allowedSort = [ |
|
38
|
|
|
'most_relevant', 'newest', |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Place lookup |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $placeId |
|
45
|
|
|
* @param string[] $fields which fields you want to get |
|
46
|
|
|
* @param string|null $region |
|
47
|
|
|
* @param bool $translateReviews |
|
48
|
|
|
* @param string|null $sortReviews |
|
49
|
|
|
* @param array<string, string|int|float> $params Query parameters |
|
50
|
|
|
* @throws ServiceException |
|
51
|
|
|
* @return RequestInterface |
|
52
|
|
|
*/ |
|
53
|
3 |
|
public function placeDetails( |
|
54
|
|
|
string $placeId, |
|
55
|
|
|
array $fields = [], |
|
56
|
|
|
?string $region = null, |
|
57
|
|
|
bool $translateReviews = true, |
|
58
|
|
|
?string $sortReviews = null, |
|
59
|
|
|
array $params = [] |
|
60
|
|
|
): RequestInterface |
|
61
|
|
|
{ |
|
62
|
3 |
|
if (empty($placeId)) { |
|
63
|
1 |
|
throw new ServiceException('You must set where to look!'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
// Main wanted id |
|
67
|
2 |
|
$params['place_id'] = $placeId; |
|
68
|
|
|
|
|
69
|
2 |
|
if (!empty($fields)) { |
|
70
|
1 |
|
$params['fields'] = implode(',', array_intersect($this->allowedFields, $fields)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
2 |
|
if (!empty($region)) { |
|
74
|
1 |
|
$params['region'] = strtolower(substr($region, 0, 2)); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
2 |
|
if (!$translateReviews) { |
|
78
|
1 |
|
$params['reviews_no_translations'] = 'true'; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
2 |
|
if (!empty($sortReviews) && in_array(strtolower($sortReviews), $this->allowedSort)) { |
|
82
|
1 |
|
$params['reviews_sort'] = strtolower($sortReviews); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
2 |
|
return $this->getWithDefaults( |
|
86
|
2 |
|
static::API_HOST . '/maps/api/place/details/json', |
|
87
|
2 |
|
$this->queryParamsLang($params), |
|
88
|
2 |
|
); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|