PwaServiceProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 105
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 4

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A loadHelpers() 0 6 2
A registerPublish() 0 30 2
A registerCommands() 0 4 1
A register() 0 14 1
A registerBladeDirectives() 0 8 1
1
<?php
2
3
namespace CodexShaper\PWA;
4
5
use CodexShaper\PWA\Commands\InstallPwa;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\View\Compilers\BladeCompiler;
8
9
class PwaServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Boot the service provider.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
19
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'pwa');
20
    }
21
22
    /**
23
     * Register the service provider.
24
     *
25
     * @return void
26
     */
27
    public function register()
28
    {
29
        $this->app->singleton('pwa', function () {
30
            return new PWA();
31
        });
32
        $this->mergeConfigFrom(
33
            __DIR__.'/../config/pwa.php',
34
            'config'
35
        );
36
        $this->loadHelpers();
37
        $this->registerBladeDirectives();
38
        $this->registerPublish();
39
        $this->registerCommands();
40
    }
41
42
    /**
43
     * Register blade directories.
44
     *
45
     * @return void
46
     */
47
    protected function registerBladeDirectives()
48
    {
49
        $this->app->afterResolving('blade.compiler', function (BladeCompiler $blade) {
50
            $blade->directive('PWA', function () {
51
                return "<?php echo view('pwa::meta')->render();?>";
52
            });
53
        });
54
    }
55
56
    /**
57
     * Load all helpers.
58
     *
59
     * @return void
60
     */
61
    protected function loadHelpers()
62
    {
63
        foreach (glob(__DIR__.'/Helpers/*.php') as $filename) {
64
            require_once $filename;
65
        }
66
    }
67
68
    /**
69
     * Register publishable assets.
70
     *
71
     * @return void
72
     */
73
    protected function registerPublish()
74
    {
75
        $publishable = [
76
            'pwa.config'    => [
77
                __DIR__.'/../config/pwa.php' => config_path('pwa.php'),
78
            ],
79
            'pwa.migrations'    => [
80
                __DIR__.'/../database/migrations/' => database_path('migrations'),
81
            ],
82
            'pwa.tenant.migrations'    => [
83
                __DIR__.'/../database/migrations/' => database_path('migrations/tenant'),
84
            ],
85
            'pwa.seeds'     => [
86
                __DIR__.'/../database/seeds/' => database_path('seeds'),
87
            ],
88
            'pwa.views'     => [
89
                __DIR__.'/../resources/views' => resource_path('views/vendor/pwa'),
90
            ],
91
            'pwa.resources' => [
92
                __DIR__.'/../resources' => resource_path('views/vendor/pwa'),
93
            ],
94
            'pwa.lang' => [
95
                __DIR__.'/../resources/lang' => resource_path('lang'),
96
            ],
97
        ];
98
99
        foreach ($publishable as $group => $paths) {
100
            $this->publishes($paths, $group);
101
        }
102
    }
103
104
    /**
105
     * Register commands.
106
     *
107
     * @return void
108
     */
109
    private function registerCommands()
110
    {
111
        $this->commands(InstallPwa::class);
112
    }
113
}
114