1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Afrittella\BackProject; |
4
|
|
|
|
5
|
|
|
use Afrittella\BackProject\Models\Attachment; |
6
|
|
|
use Afrittella\BackProject\Models\Observers\RemoveAttachableWheDeletingAttachment; |
7
|
|
|
use Afrittella\BackProject\Models\Observers\RemoveFileWhenDeletingAttachment; |
8
|
|
|
use Afrittella\BackProject\Models\Observers\SaveFileWhenAddingAttachment; |
9
|
|
|
use Afrittella\BackProject\Services\MediaManager; |
10
|
|
|
use Afrittella\BackProject\Services\BackProject; |
11
|
|
|
use Afrittella\BackProject\Services\SlugGenerator; |
12
|
|
|
use Illuminate\Support\ServiceProvider; |
13
|
|
|
use Illuminate\Routing\Router; |
14
|
|
|
use function Symfony\Component\HttpKernel\Tests\controller_func; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class BackProjectServiceProvider extends ServiceProvider |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
protected $defer = false; |
21
|
|
|
|
22
|
|
|
protected $migrations = [ |
23
|
|
|
'ModifyUsersTable' => 'modify_users_table', |
24
|
|
|
'CreateMenusTable' => 'create_menus_table', |
25
|
|
|
'CreateAttachmentsTable' => 'create_attachments_table', |
26
|
|
|
'CreateSocialAccountsTable' => 'create_social_accounts_table', |
27
|
|
|
'UsersAddSocial' => 'users_add_social' |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
protected $helpers = [ |
31
|
|
|
'icons' |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
public function boot() |
35
|
|
|
{ |
36
|
|
|
// LOAD THE VIEWS |
37
|
|
|
// - first the published views (in case they have any changes) |
38
|
|
|
$this->loadViewsFrom(resource_path('views/vendor/back-project/base'), 'back-project'); |
39
|
|
|
// - then the stock views that come with the package, in case a published view might be missing |
40
|
|
|
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'back-project'); |
41
|
|
|
// Load Translations |
42
|
|
|
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'back-project'); |
43
|
|
|
|
44
|
|
|
// use the vendor configuration file as fallback |
45
|
|
|
$this->mergeConfigFrom( |
46
|
|
|
__DIR__ . '/../config/config.php', 'back-project' |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$this->routes(); |
50
|
|
|
|
51
|
|
|
$this->publishFiles(); |
52
|
|
|
|
53
|
|
|
//$this->handleMigrations(); |
|
|
|
|
54
|
|
|
$this->loadMigrationsFrom(realpath(__DIR__.'/../database/migrations')); |
55
|
|
|
|
56
|
|
|
$this->registerEvents(); |
57
|
|
|
|
58
|
|
|
$this->registerCommands(); |
59
|
|
|
|
60
|
|
|
$this->registerViewComposers(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function register() |
64
|
|
|
{ |
65
|
|
|
$this->app->singleton('media-manager', function ($app) { |
|
|
|
|
66
|
|
|
return new MediaManager(); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
// TODO |
70
|
|
|
/*$this->app->singleton('back-project', function ($app) { |
|
|
|
|
71
|
|
|
return new BackProject(); |
72
|
|
|
}); |
73
|
|
|
|
74
|
|
|
$this->app->singleton('slug-generator', function ($app) { |
75
|
|
|
return new SlugGenerator(); |
76
|
|
|
});*/ |
77
|
|
|
|
78
|
|
|
// register dependencies |
79
|
|
|
$this->app->register(\Prologue\Alerts\AlertsServiceProvider::class); |
80
|
|
|
$this->app->register(\Spatie\Permission\PermissionServiceProvider::class); |
81
|
|
|
$this->app->register(\PendoNL\LaravelFontAwesome\LaravelFontAwesomeServiceProvider::class); |
82
|
|
|
$this->app->register(\Collective\Html\HtmlServiceProvider::class); |
83
|
|
|
$this->app->register(\Laravolt\Avatar\ServiceProvider::class); |
84
|
|
|
$this->app->register(\Intervention\Image\ImageServiceProvider::class); |
85
|
|
|
$this->app->register(\Laravel\Socialite\SocialiteServiceProvider::class); |
86
|
|
|
|
87
|
|
|
// register their aliases |
88
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
89
|
|
|
$loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class); |
90
|
|
|
$loader->alias('FontAwesome', \PendoNL\LaravelFontAwesome\Facade::class); |
91
|
|
|
$loader->alias('Form', \Collective\Html\FormFacade::class); |
92
|
|
|
$loader->alias('Html', \Collective\Html\HtmlFacade::class); |
93
|
|
|
$loader->alias('Avatar', \Laravolt\Avatar\Facade::class); |
94
|
|
|
$loader->alias('MediaManager', \Afrittella\BackProject\Facades\MediaManager::class); |
95
|
|
|
$loader->alias('SlugGenerator', \Afrittella\BackProject\Facades\SlugGenerator::class); |
96
|
|
|
$loader->alias('Image', \Intervention\Image\Facades\Image::class); |
97
|
|
|
$loader->alias('Socialite', \Laravel\Socialite\Facades\Socialite::class); |
98
|
|
|
|
99
|
|
|
$this->loadHelpers(); |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/*** Internal function ***/ |
104
|
|
|
|
105
|
|
|
public function publishFiles() |
106
|
|
|
{ |
107
|
|
|
// publish config file |
108
|
|
|
$this->publishes([__DIR__ . '/../config/config.php' => config_path() . '/back-project.php'], 'config'); |
109
|
|
|
// publish lang files |
110
|
|
|
$this->publishes([__DIR__ . '/../resources/lang' => resource_path('lang/vendor/back-project')], 'lang'); |
111
|
|
|
// publish public BackProject assets |
112
|
|
|
$this->publishes([__DIR__ . '/../public' => public_path('vendor/back-project')], 'public'); |
113
|
|
|
// publish views |
114
|
|
|
$this->publishes([__DIR__ . '/../resources/views' => resource_path('views/vendor/back-project')], 'views'); |
115
|
|
|
// publish error views |
116
|
|
|
$this->publishes([__DIR__ . '/../resources/error_views' => resource_path('views/errors')], 'errors'); |
117
|
|
|
// publish public AdminLTE assets |
118
|
|
|
$this->publishes(['vendor/almasaeed2010/adminlte/bower_components/bootstrap/dist' => public_path('vendor/adminlte/bootstrap')], 'adminlte'); |
119
|
|
|
$this->publishes(['vendor/almasaeed2010/adminlte/dist' => public_path('vendor/adminlte/dist')], 'adminlte'); |
120
|
|
|
$this->publishes(['vendor/almasaeed2010/adminlte/plugins' => public_path('vendor/adminlte/plugins')], 'adminlte'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function routes() |
124
|
|
|
{ |
125
|
|
|
// Register Middleware |
126
|
|
|
$router = app('router'); |
|
|
|
|
127
|
|
|
|
128
|
|
|
//$router->aliasMiddleware('admin', \Afrittella\BackProject\Http\Middleware\Admin::class); |
|
|
|
|
129
|
|
|
//$router->aliasMiddleware('role', \Afrittella\BackProject\Http\Middleware\Role::class); |
|
|
|
|
130
|
|
|
|
131
|
|
|
$this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function handleMigrations() |
135
|
|
|
{ |
136
|
|
|
foreach ($this->migrations as $class => $file) { |
137
|
|
|
if (!class_exists($class)) { |
138
|
|
|
$timestamp = date('Y_m_d_His', time()); |
139
|
|
|
|
140
|
|
|
$this->publishes([ |
141
|
|
|
__DIR__ . '/../database/migrations/' . $file . '.php' => |
142
|
|
|
database_path('migrations/' . $timestamp . '_' . $file . '.php') |
143
|
|
|
], 'migrations'); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function registerEvents() |
149
|
|
|
{ |
150
|
|
|
// User notification can use queues or not |
151
|
|
|
if (config('back-project.use_queue')) { |
152
|
|
|
\Event::listen('Afrittella\BackProject\Events\UserRegistered', 'Afrittella\BackProject\Listeners\SendRegistrationEmail'); |
153
|
|
|
} else { |
154
|
|
|
\Event::listen('Afrittella\BackProject\Events\UserRegistered', 'Afrittella\BackProject\Listeners\SendRegistrationEmailNoQueue'); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
// Register Observers |
158
|
|
|
Attachment::observe(SaveFileWhenAddingAttachment::class); |
159
|
|
|
Attachment::observe(RemoveFileWhenDeletingAttachment::class); |
160
|
|
|
Attachment::observe(RemoveAttachableWheDeletingAttachment::class); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function registerCommands() |
164
|
|
|
{ |
165
|
|
|
if ($this->app->runningInConsole()) { |
166
|
|
|
$this->commands([ |
167
|
|
|
\Afrittella\BackProject\Console\Commands\SeedDefaultMenus::class, |
168
|
|
|
\Afrittella\BackProject\Console\Commands\SeedPermissions::class |
169
|
|
|
]); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function registerViewComposers() |
174
|
|
|
{ |
175
|
|
|
\View::composer(['back-project::layouts.admin'], 'Afrittella\BackProject\Http\ViewComposers\AdminMenuComposer'); |
176
|
|
|
\View::composer(['back-project::layouts.admin'], 'Afrittella\BackProject\Http\ViewComposers\UserComposer'); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function loadHelpers() |
180
|
|
|
{ |
181
|
|
|
foreach ($this->helpers as $helper): |
182
|
|
|
$file = __DIR__ . '/Helpers/' . $helper . '.php'; |
183
|
|
|
|
184
|
|
|
if (file_exists($file)) { |
185
|
|
|
require_once($file); |
186
|
|
|
} |
187
|
|
|
endforeach; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
} |
191
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.