Completed
Push — master ( 9b899c...eabbf2 )
by Mike
15s
created

src/Providers/GeocoderService.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace Geocoder\Laravel\Providers;
2
3
/**
4
 * This file is part of the Geocoder Laravel package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Mike Bronner <[email protected]>
9
 * @license    MIT License
10
 */
11
12
use Geocoder\Laravel\Facades\Geocoder;
13
use Geocoder\Laravel\ProviderAndDumperAggregator;
14
use Illuminate\Support\ServiceProvider;
15
16
class GeocoderService extends ServiceProvider
17
{
18
    protected $defer = false;
19
20
    public function boot()
21
    {
22 26
        $configPath = __DIR__ . "/../../config/geocoder.php";
23
        $this->publishes(
24 26
            [$configPath => $this->configPath("geocoder.php")],
25 26
            "config"
26 26
        );
27 26
        $this->mergeConfigFrom($configPath, "geocoder");
28 24
29 24
        $providerAndDumperAggregator = (new ProviderAndDumperAggregator)
30 26
            ->registerProvidersFromConfig(collect(config("geocoder.providers")));
31 26
32
        $this->app->singleton("geocoder", function ($app) use ($providerAndDumperAggregator) {
0 ignored issues
show
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33 26
            return $providerAndDumperAggregator;
34
        });
35 26
36 26
        // Resolve dependency via class name
37
        // i.e app(ProviderAndDumperAggregator::class) or _construct(ProviderAndDumperAggregator $geocoder)
38
        $this->app->instance(ProviderAndDumperAggregator::class, $providerAndDumperAggregator);
39
    }
40
41
    public function register()
42
    {
43
        $this->app->alias("Geocoder", Geocoder::class);
44
    }
45
46
    public function provides(): array
47
    {
48
        return ["geocoder"];
49
    }
50
51
    protected function configPath(string $path = ""): string
52
    {
53
        if (function_exists("config_path")) {
54
            return config_path($path);
55
        }
56
57
        $pathParts = [
58
            app()->basePath(),
59
            "config",
60
            trim($path, "/"),
61
        ];
62
63
        return implode("/", $pathParts);
64
    }
65
}
66