Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
CRAP | |
76.47% |
13 / 17 |
GeolocationProvider | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
5.33 | |
76.47% |
13 / 17 |
boot | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
register | |
0.00% |
0 / 1 |
4.30 | |
73.33% |
11 / 15 |
1 | <?php |
2 | namespace Qmp\Laravel\Geolocation\Providers; |
3 | |
4 | use Illuminate\Support\ServiceProvider; |
5 | use Qmp\Laravel\Geolocation\Services\GeolocApiServices\GeolocFakerService; |
6 | use Qmp\Laravel\Geolocation\Services\Validations\GeolocValidator; |
7 | use Qmp\Laravel\Geolocation\Services\GeolocApiServices\ServiceInterface; |
8 | use Qmp\Laravel\MicroService\DbConnection\DbConnection; |
9 | |
10 | class GeolocationProvider extends ServiceProvider |
11 | { |
12 | /** |
13 | * Boot the service provider. |
14 | * |
15 | * @return void |
16 | */ |
17 | public function boot() |
18 | { |
19 | $this->loadMigrationsFrom(__DIR__.'/../database/migrations/'); |
20 | } |
21 | |
22 | public function register() |
23 | { |
24 | DbConnection::mergeFromFile(realpath(__DIR__.'/../../config/connection.php')); |
25 | |
26 | $this->mergeConfigFrom( __DIR__.'/../../config/geolocation.php', 'geolocation'); |
27 | |
28 | $this->app->singleton(ServiceInterface::class, function ($app) { |
29 | |
30 | $request = $app->request; |
31 | |
32 | if(env('APP_ENV') === 'production') { |
33 | |
34 | if($request->has('input') && ($serviceName = config('geolocation.inputs.' . $request->input)) !== null) { |
35 | |
36 | $serviceConfig = collect(config('geolocation.services.' . $serviceName)); |
37 | $class = $serviceConfig->get('class'); |
38 | |
39 | return new $class($request->input, $request->value, $serviceConfig); |
40 | } |
41 | } |
42 | |
43 | return new GeolocFakerService($request->input, $request->value, collect([])); |
44 | |
45 | }); |
46 | |
47 | $this->app->singleton(GeolocValidator::class, function ($app) { |
48 | return new GeolocValidator($app->request->input, $app->request->value); |
49 | }); |
50 | } |
51 | } |