1 | <?php |
||
2 | |||
3 | namespace kalanis\google_maps; |
||
4 | |||
5 | |||
6 | use Psr\Http\Client\ClientExceptionInterface; |
||
7 | use Psr\Http\Client\ClientInterface; |
||
8 | use Psr\Http\Message\RequestInterface; |
||
9 | use ReflectionException; |
||
10 | |||
11 | |||
12 | /** |
||
13 | * Google Maps PHP Client - facade for processing |
||
14 | * |
||
15 | * @method array|string directions(string $origin, string $destination, array $params = []) |
||
16 | * @method array|string distanceMatrix(string $origin, string $destination, array $params = []) |
||
17 | * @method array|string elevation(string $locations, array $params = []) |
||
18 | * @method array|string geocode(string $address, array $params = []) |
||
19 | * @method array|string reverseGeocode(string $lat, string $lng, array $params = []) |
||
20 | * @method array|string computeRoutes(array $origin, array $destination, array $body = [], array $headers = [], array $params = []) |
||
21 | * @method array|string geolocate(array $bodyParams = []) |
||
22 | * @method array|string timezone(string $location, string|null $timestamp = null, array $params = []) |
||
23 | * @method array|string nearby(string $keyword, float[] $latlng, float|null $radius = null, string|null $type = null, array $params = []) |
||
24 | * @method array|string findPlace(string $input, string $inputType, string[] $fields = [], float[]|null $bias = null, array $params = []) |
||
25 | * @method array|string findText(string $query, float $radius, float[] $location = [], int|null $maxPrice = null, int|null $minPrice = null, bool $openNow = false, string|null $region = null, string|null $type = null, array $params = []) |
||
26 | * @method array|string placeDetails(string $placeId, string[] $fields = [], string $region = null, bool $translateReviews = true, string $sortReviews = null, array $params = []) |
||
27 | * @method array|string snapToRoads(array|string|null $path, array $params = []) |
||
28 | */ |
||
29 | class Client |
||
30 | { |
||
31 | protected readonly Services $services; |
||
32 | |||
33 | /** |
||
34 | * @param RequestInterface $request |
||
35 | * @param ClientInterface $client |
||
36 | * @param ClientConfig $config |
||
37 | * Each of these three must be available via Dependency Injection |
||
38 | */ |
||
39 | 1 | public function __construct( |
|
40 | RequestInterface $request, |
||
41 | ClientInterface $client, |
||
42 | protected ClientConfig $config, |
||
43 | ) |
||
44 | { |
||
45 | 1 | $this->services = new Services( |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
46 | 1 | new Services\ServiceFactory( |
|
47 | 1 | $request, |
|
48 | 1 | new Remote\Headers\ApiAuth($config), |
|
49 | 1 | new Remote\Headers\Language($config) |
|
50 | 1 | ), |
|
51 | 1 | $client, |
|
52 | 1 | new Remote\Response(), |
|
53 | 1 | ); |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * Set default language for Google Maps API |
||
58 | * |
||
59 | * @param string|null $language ex. 'zh-TW' |
||
60 | * @return $this |
||
61 | */ |
||
62 | 1 | public function setLanguage(?string $language = null): self |
|
63 | { |
||
64 | 1 | $this->config->setLanguage($language); |
|
65 | 1 | return $this; |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Client methods refer to each service |
||
70 | * |
||
71 | * All service methods from Client calling would leave out the first argument (Client itself). |
||
72 | * |
||
73 | * @param string $method Client's method name |
||
74 | * @param array<int, string|int|float> $arguments Method arguments |
||
75 | * @throws ServiceException |
||
76 | * @throws ReflectionException |
||
77 | * @throws ClientExceptionInterface |
||
78 | * @return mixed Current service method return |
||
79 | */ |
||
80 | 1 | public function __call(string $method, array $arguments) |
|
81 | { |
||
82 | 1 | return $this->services->__call($method, $arguments); |
|
83 | } |
||
84 | } |
||
85 |