Skip to content

Commit

Permalink
Prevent GeocoderService from instantiating providers on boot
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Korri committed Jun 22, 2018
1 parent fd0c837 commit 1a484b2
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Providers/GeocoderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,24 @@ public function boot()
"config"
);
$this->mergeConfigFrom($configPath, "geocoder");
$geocoder = (new ProviderAndDumperAggregator)
->registerProvidersFromConfig(collect(config("geocoder.providers")));
$this->app
->singleton("geocoder", function () use ($geocoder) {
return $geocoder;
});
$this->app
->instance(ProviderAndDumperAggregator::class, $geocoder);
}

public function register()
{
$this->app->alias("Geocoder", Geocoder::class);
$this->app->singleton(ProviderAndDumperAggregator::class, function () {
return (new ProviderAndDumperAggregator)
->registerProvidersFromConfig(collect(config("geocoder.providers")));
});
$this->app->bind('geocoder', ProviderAndDumperAggregator::class);
}

public function provides() : array
public function provides(): array
{
return ["geocoder", ProviderAndDumperAggregator::class];
}

protected function configPath(string $path = "") : string
protected function configPath(string $path = ""): string
{
if (function_exists("config_path")) {
return config_path($path);
Expand Down

0 comments on commit 1a484b2

Please sign in to comment.