AppServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 7
Bugs 0 Features 1
Metric Value
eloc 15
c 7
b 0
f 1
dl 0
loc 40
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 11 1
A register() 0 16 1
1
<?php
2
3
namespace App\Providers;
4
5
use App\Models\Compilation;
6
use App\Models\Location;
7
use App\Models\Ward;
8
use App\Observers\EloquentModelObserver;
9
use App\Services\CompilationService;
10
use App\Services\DataTablesPluginService;
11
use App\User;
12
use Illuminate\Support\Facades\Blade;
13
use Illuminate\Support\ServiceProvider;
14
15
class AppServiceProvider extends ServiceProvider
16
{
17
18
    /**
19
     * Bootstrap any application services.
20
     */
21
    public function boot()
22
    {
23
24
        // https://laravel.com/docs/5.5/eloquent#events
25
        User::observe(EloquentModelObserver::class);
26
        Compilation::observe(EloquentModelObserver::class);
27
        Ward::observe(EloquentModelObserver::class);
28
        Location::observe(EloquentModelObserver::class);
29
30
        Blade::directive("jsonize", function ($data) {
31
            return "<?php echo json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ?>";
32
        });
33
34
    }
35
36
    /**
37
     * Register any application services.
38
     */
39
    public function register()
40
    {
41
42
        // @todo ensure $countries population can stay here or must be moved to boot() method
43
        $countries = require(base_path("vendor/umpirsky/country-list/data/" . config("app.locale") . "/country.php"));
44
45
        $this->app->when("App\Services\CountryService")
46
            ->needs('$countries')
47
            ->give($countries);
48
49
        $this->app->bind("App\Services\DataTablesPluginService", function () {
50
            return new DataTablesPluginService(base_path("node_modules/datatables.net-plugins"));
51
        });
52
53
        $this->app->singleton("App\Services\CompilationService", function ($app) {
54
            return new CompilationService($app->make("App\Services\CountryService"));
55
        });
56
57
    }
58
59
}
60