11
11
12
12
use Geocoder \Laravel \Facades \Geocoder ;
13
13
use Geocoder \Laravel \ProviderAndDumperAggregator ;
14
- use Illuminate \Support \Collection ;
15
14
use Illuminate \Support \ServiceProvider ;
16
- use ReflectionClass ;
17
15
18
16
class GeocoderService extends ServiceProvider
19
17
{
@@ -27,23 +25,30 @@ public function boot()
27
25
"config "
28
26
);
29
27
$ this ->mergeConfigFrom ($ configPath , "geocoder " );
30
- $ this ->app ->singleton ("geocoder " , function () {
31
- return (new ProviderAndDumperAggregator )
32
- ->registerProvidersFromConfig (collect (config ("geocoder.providers " )));
28
+
29
+ $ providerAndDumperAggregator = (new ProviderAndDumperAggregator )
30
+ ->registerProvidersFromConfig (collect (config ("geocoder.providers " )));
31
+
32
+ $ this ->app ->singleton ("geocoder " , function ($ app ) use ($ providerAndDumperAggregator ) {
33
+ return $ providerAndDumperAggregator ;
33
34
});
35
+
36
+ // Resolve dependency via class name
37
+ // i.e app(ProviderAndDumperAggregator::class) or _construct(ProviderAndDumperAggregator $geocoder)
38
+ $ this ->app ->instance (ProviderAndDumperAggregator::class, $ providerAndDumperAggregator );
34
39
}
35
40
36
41
public function register ()
37
42
{
38
43
$ this ->app ->alias ("Geocoder " , Geocoder::class);
39
44
}
40
45
41
- public function provides () : array
46
+ public function provides (): array
42
47
{
43
48
return ["geocoder " ];
44
49
}
45
50
46
- protected function configPath (string $ path = "" ) : string
51
+ protected function configPath (string $ path = "" ): string
47
52
{
48
53
if (function_exists ("config_path " )) {
49
54
return config_path ($ path );
0 commit comments