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
|
|
|
|