Skip to content

Commit 530a185

Browse files
committed
Resolve depency via Class name
1 parent 9b899cf commit 530a185

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/Providers/GeocoderService.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
use Geocoder\Laravel\Facades\Geocoder;
1313
use Geocoder\Laravel\ProviderAndDumperAggregator;
14-
use Illuminate\Support\Collection;
1514
use Illuminate\Support\ServiceProvider;
16-
use ReflectionClass;
1715

1816
class GeocoderService extends ServiceProvider
1917
{
@@ -27,23 +25,30 @@ public function boot()
2725
"config"
2826
);
2927
$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;
3334
});
35+
36+
// Resolve dependency via class name
37+
// i.e app(ProviderAndDumperAggregator::class) or _construct(ProviderAndDumperAggregator $geocoder)
38+
$this->app->instance(ProviderAndDumperAggregator::class, $providerAndDumperAggregator);
3439
}
3540

3641
public function register()
3742
{
3843
$this->app->alias("Geocoder", Geocoder::class);
3944
}
4045

41-
public function provides() : array
46+
public function provides(): array
4247
{
4348
return ["geocoder"];
4449
}
4550

46-
protected function configPath(string $path = "") : string
51+
protected function configPath(string $path = ""): string
4752
{
4853
if (function_exists("config_path")) {
4954
return config_path($path);

0 commit comments

Comments
 (0)