1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace jeremykenedy\LaravelBlocker; |
4
|
|
|
|
5
|
|
|
use Illuminate\Routing\Router; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use jeremykenedy\LaravelBlocker\App\Http\Middleware\LaravelBlocker; |
8
|
|
|
use jeremykenedy\LaravelBlocker\Database\Seeds\DefaultBlockedItemsTableSeeder; |
9
|
|
|
use jeremykenedy\LaravelBlocker\Database\Seeds\DefaultBlockedTypeTableSeeder; |
10
|
|
|
|
11
|
|
|
class LaravelBlockerServiceProvider extends ServiceProvider |
12
|
|
|
{ |
13
|
|
|
private $_packageTag = 'laravelblocker'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Indicates if loading of the provider is deferred. |
17
|
|
|
* |
18
|
|
|
* @var bool |
19
|
|
|
*/ |
20
|
|
|
protected $defer = false; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Bootstrap the application services. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function boot(Router $router) |
28
|
|
|
{ |
29
|
|
|
$router->middlewareGroup('checkblocked', [LaravelBlocker::class]); |
30
|
|
|
$this->loadRoutesFrom(__DIR__.'/routes/web.php'); |
31
|
|
|
$this->loadTranslationsFrom(__DIR__.'/resources/lang/', $this->_packageTag); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Register the application services. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function register() |
40
|
|
|
{ |
41
|
|
|
$this->packageRegistration(); |
42
|
|
|
$this->loadRoutesFrom(__DIR__.'/routes/web.php'); |
43
|
|
|
$this->loadViewsFrom(__DIR__.'/resources/views/', $this->_packageTag); |
44
|
|
|
$this->mergeConfigFrom(__DIR__.'/config/'.$this->_packageTag.'.php', $this->_packageTag); |
45
|
|
|
$this->loadMigrationsFrom(__DIR__.'/database/migrations'); |
46
|
|
|
$this->loadSeedsFrom(); |
47
|
|
|
$this->publishFiles(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Package Registration. |
52
|
|
|
* |
53
|
|
|
* @return void |
54
|
|
|
*/ |
55
|
|
|
private function packageRegistration() |
56
|
|
|
{ |
57
|
|
|
$this->app->make('jeremykenedy\LaravelBlocker\App\Http\Controllers\LaravelBlockerController'); |
58
|
|
|
$this->app->singleton(jeremykenedy\LaravelBlocker\App\Http\Controllers\LaravelBlockerController::class, function () { |
|
|
|
|
59
|
|
|
return new App\Http\Controllers\LaravelBlockerController(); |
60
|
|
|
}); |
61
|
|
|
$this->app->alias(LaravelBlockerController::class, $this->_packageTag); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Loads a seeds. |
66
|
|
|
* |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
|
private function loadSeedsFrom() |
70
|
|
|
{ |
71
|
|
|
if (config('laravelblocker.seedDefaultBlockedTypes')) { |
|
|
|
|
72
|
|
|
$this->app['seed.handler']->register( |
73
|
|
|
DefaultBlockedTypeTableSeeder::class |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
if (config('laravelblocker.seedDefaultBlockedItems')) { |
77
|
|
|
$this->app['seed.handler']->register( |
78
|
|
|
DefaultBlockedItemsTableSeeder::class |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (config('laravelblocker.useSeededBlockedTypes')) { |
83
|
|
|
$this->app['seed.handler']->register( |
84
|
|
|
\Database\Seeds\BlockedTypeTableSeeder::class |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (config('laravelblocker.useSeededBlockedItems')) { |
89
|
|
|
$this->app['seed.handler']->register( |
90
|
|
|
\Database\Seeds\BlockedItemsTableSeeder::class |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Publish files for Laravel Blocker. |
97
|
|
|
* |
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
|
|
private function publishFiles() |
101
|
|
|
{ |
102
|
|
|
$publishTag = $this->_packageTag; |
103
|
|
|
|
104
|
|
|
$this->publishes([ |
105
|
|
|
__DIR__.'/config/'.$this->_packageTag.'.php' => base_path('config/'.$this->_packageTag.'.php'), |
|
|
|
|
106
|
|
|
], $publishTag.'-config'); |
107
|
|
|
|
108
|
|
|
$this->publishes([ |
109
|
|
|
__DIR__.'/resources/views' => base_path('resources/views/vendor/'), |
110
|
|
|
], $publishTag.'-views'); |
111
|
|
|
|
112
|
|
|
$this->publishes([ |
113
|
|
|
__DIR__.'/resources/lang' => base_path('resources/lang/vendor/'.$this->_packageTag), |
114
|
|
|
], $publishTag.'-lang'); |
115
|
|
|
|
116
|
|
|
$this->publishes([ |
117
|
|
|
__DIR__.'/database/migrations' => database_path('migrations'), |
|
|
|
|
118
|
|
|
], $publishTag.'-migrations'); |
119
|
|
|
|
120
|
|
|
$this->publishes([ |
121
|
|
|
__DIR__.'/database/seeds/publish' => database_path('seeds'), |
122
|
|
|
], $publishTag.'-seeds'); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|