|  | 
| 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 | { | 
| 20 | 18 |  protected $defer = false; | 
| 21 | 19 | 
 | 
| 22 | 20 |  public function boot() | 
| 23 | 21 |  { | 
| 24 |  | - $configPath = __DIR__ . '/../../config/geocoder.php'; | 
| 25 |  | - $this->publishes([$configPath => config_path('geocoder.php')], 'config'); | 
| 26 |  | - $this->mergeConfigFrom($configPath, 'geocoder'); | 
| 27 |  | - $this->app->singleton('geocoder', function () { | 
| 28 |  | - return (new ProviderAndDumperAggregator) | 
| 29 |  | - ->registerProvidersFromConfig(collect(config('geocoder.providers'))); | 
| 30 |  | - }); | 
|  | 22 | + $configPath = __DIR__ . "/../../config/geocoder.php"; | 
|  | 23 | + $this->publishes( | 
|  | 24 | + [$configPath => $this->configPath("geocoder.php")], | 
|  | 25 | + "config" | 
|  | 26 | + ); | 
|  | 27 | + $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); | 
| 31 | 36 |  } | 
| 32 | 37 | 
 | 
| 33 | 38 |  public function register() | 
| 34 | 39 |  { | 
| 35 |  | - $this->app->alias('Geocoder', Geocoder::class); | 
|  | 40 | + $this->app->alias("Geocoder", Geocoder::class); | 
| 36 | 41 |  } | 
| 37 | 42 | 
 | 
| 38 | 43 |  public function provides() : array | 
| 39 | 44 |  { | 
| 40 |  | - return ['geocoder']; | 
|  | 45 | + return ["geocoder", ProviderAndDumperAggregator::class]; | 
|  | 46 | + } | 
|  | 47 | + | 
|  | 48 | + protected function configPath(string $path = "") : string | 
|  | 49 | + { | 
|  | 50 | + if (function_exists("config_path")) { | 
|  | 51 | + return config_path($path); | 
|  | 52 | + } | 
|  | 53 | + | 
|  | 54 | + $pathParts = [ | 
|  | 55 | + app()->basePath(), | 
|  | 56 | + "config", | 
|  | 57 | + trim($path, "/"), | 
|  | 58 | + ]; | 
|  | 59 | + | 
|  | 60 | + return implode("/", $pathParts); | 
| 41 | 61 |  } | 
| 42 | 62 | } | 
0 commit comments