|
1
|
|
|
<?php namespace Arcanedev\GeoLocation\Google; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanedev\GeoLocation\Contracts\GoogleManager as GoogleManagerContract; |
|
4
|
|
|
use GuzzleHttp\ClientInterface; |
|
5
|
|
|
use Illuminate\Support\Manager; |
|
6
|
|
|
use InvalidArgumentException; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class GoogleManager |
|
10
|
|
|
* |
|
11
|
|
|
* @package Arcanedev\GeoLocation\Google |
|
12
|
|
|
* @author ARCANEDEV <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class GoogleManager extends Manager implements GoogleManagerContract |
|
15
|
|
|
{ |
|
16
|
|
|
/* ----------------------------------------------------------------- |
|
17
|
|
|
| Main Methods |
|
18
|
|
|
| ----------------------------------------------------------------- |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Get a google service. |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $driver |
|
25
|
|
|
* |
|
26
|
|
|
* @return \Arcanedev\GeoLocation\Google\AbstractService |
|
27
|
|
|
*/ |
|
28
|
|
|
public function driver($driver = null) |
|
29
|
|
|
{ |
|
30
|
|
|
return parent::driver($driver); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Create the google directions service. |
|
35
|
|
|
* |
|
36
|
|
|
* @return \Arcanedev\GeoLocation\Google\AbstractService |
|
37
|
|
|
*/ |
|
38
|
15 |
|
public function createDirectionsDriver() |
|
39
|
|
|
{ |
|
40
|
15 |
|
return $this->buildService('directions'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Create the google distance matrix service. |
|
45
|
|
|
* |
|
46
|
|
|
* @return \Arcanedev\GeoLocation\Google\AbstractService |
|
47
|
|
|
*/ |
|
48
|
21 |
|
public function createDistanceMatrixDriver() |
|
49
|
|
|
{ |
|
50
|
21 |
|
return $this->buildService('distance-matrix'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Create the google elevation service. |
|
55
|
|
|
* |
|
56
|
|
|
* @return \Arcanedev\GeoLocation\Google\AbstractService |
|
57
|
|
|
*/ |
|
58
|
12 |
|
public function createElevationDriver() |
|
59
|
|
|
{ |
|
60
|
12 |
|
return $this->buildService('elevation'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Create the google geocoding service. |
|
65
|
|
|
* |
|
66
|
|
|
* @return \Arcanedev\GeoLocation\Google\AbstractService |
|
67
|
|
|
*/ |
|
68
|
9 |
|
public function createGeocodingDriver() |
|
69
|
|
|
{ |
|
70
|
9 |
|
return $this->buildService('geocoding'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get the default driver name. |
|
75
|
|
|
* |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getDefaultDriver() |
|
79
|
|
|
{ |
|
80
|
|
|
throw new InvalidArgumentException('No google service was specified.'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/* ----------------------------------------------------------------- |
|
84
|
|
|
| Other Methods |
|
85
|
|
|
| ----------------------------------------------------------------- |
|
86
|
|
|
*/ |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Build a google service. |
|
90
|
|
|
* |
|
91
|
|
|
* @param string $name |
|
92
|
|
|
* |
|
93
|
|
|
* @return \Arcanedev\GeoLocation\Google\AbstractService |
|
94
|
|
|
*/ |
|
95
|
57 |
|
protected function buildService($name) |
|
96
|
|
|
{ |
|
97
|
57 |
|
$service = $this->config()->get("geo-location.services.google.{$name}.service"); |
|
98
|
|
|
|
|
99
|
57 |
|
return new $service( |
|
100
|
57 |
|
$this->getHttpClient(), |
|
101
|
57 |
|
$this->config()->get("geo-location.services.google.{$name}.options", []) |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Get the config repository. |
|
107
|
|
|
* |
|
108
|
|
|
* @return mixed |
|
109
|
|
|
*/ |
|
110
|
57 |
|
protected function config() |
|
111
|
|
|
{ |
|
112
|
57 |
|
return $this->app['config']; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Get the http client. |
|
117
|
|
|
* |
|
118
|
|
|
* @return \GuzzleHttp\ClientInterface |
|
119
|
|
|
*/ |
|
120
|
57 |
|
protected function getHttpClient() |
|
121
|
|
|
{ |
|
122
|
57 |
|
return $this->app->make(ClientInterface::class); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|