Skip to content

Commit 1a484b2

Browse files
committed
Prevent GeocoderService from instantiating providers on boot
This could cause performance issues as is instantiates the each provider that was setup in the configuration as the time of boot, event if they don't get use.
1 parent fd0c837 commit 1a484b2

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/Providers/GeocoderService.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,24 @@ public function boot()
2525
"config"
2626
);
2727
$this->mergeConfigFrom($configPath, "geocoder");
28-
$geocoder = (new ProviderAndDumperAggregator)
29-
->registerProvidersFromConfig(collect(config("geocoder.providers")));
30-
$this->app
31-
->singleton("geocoder", function () use ($geocoder) {
32-
return $geocoder;
33-
});
34-
$this->app
35-
->instance(ProviderAndDumperAggregator::class, $geocoder);
3628
}
3729

3830
public function register()
3931
{
4032
$this->app->alias("Geocoder", Geocoder::class);
33+
$this->app->singleton(ProviderAndDumperAggregator::class, function () {
34+
return (new ProviderAndDumperAggregator)
35+
->registerProvidersFromConfig(collect(config("geocoder.providers")));
36+
});
37+
$this->app->bind('geocoder', ProviderAndDumperAggregator::class);
4138
}
4239

43-
public function provides() : array
40+
public function provides(): array
4441
{
4542
return ["geocoder", ProviderAndDumperAggregator::class];
4643
}
4744

48-
protected function configPath(string $path = "") : string
45+
protected function configPath(string $path = ""): string
4946
{
5047
if (function_exists("config_path")) {
5148
return config_path($path);

0 commit comments

Comments
 (0)