|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Chuckbe\Chuckcms; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Routing\Router; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
8
|
|
|
use Illuminate\Support\ServiceProvider; |
|
9
|
|
|
|
|
10
|
|
|
use Chuckbe\Chuckcms\Commands\GenerateSite; |
|
11
|
|
|
use Chuckbe\Chuckcms\Commands\GenerateSitemap; |
|
12
|
|
|
use Chuckbe\Chuckcms\Commands\GenerateSuperAdmin; |
|
13
|
|
|
use Chuckbe\Chuckcms\Commands\GenerateRolesPermissions; |
|
14
|
|
|
|
|
15
|
|
|
use Spatie\Permission\Middlewares\RoleMiddleware; |
|
16
|
|
|
use Spatie\Permission\Middlewares\PermissionMiddleware; |
|
17
|
|
|
use Spatie\Permission\Middlewares\RoleOrPermissionMiddleware; |
|
18
|
|
|
|
|
19
|
|
|
class ChuckcmsServiceProvider extends ServiceProvider |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Bootstrap the application services. |
|
23
|
|
|
* |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
|
|
public function boot() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->doPublishing(); |
|
29
|
|
|
|
|
30
|
|
|
$this->loadMigrationsFrom(__DIR__.'/../database/migrations'); |
|
31
|
|
|
|
|
32
|
|
|
$router = $this->app->make(Router::class); |
|
33
|
|
|
$router->aliasMiddleware('role', RoleMiddleware::class); |
|
34
|
|
|
$router->aliasMiddleware('permission', PermissionMiddleware::class); |
|
35
|
|
|
$router->aliasMiddleware('role_or_permission', RoleOrPermissionMiddleware::class); |
|
36
|
|
|
|
|
37
|
|
|
if ($this->app->runningInConsole()) { |
|
38
|
|
|
$this->commands([ |
|
39
|
|
|
GenerateSuperAdmin::class, |
|
40
|
|
|
GenerateSite::class, |
|
41
|
|
|
GenerateSitemap::class, |
|
42
|
|
|
GenerateRolesPermissions::class, |
|
43
|
|
|
]); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Register the application services. |
|
49
|
|
|
* |
|
50
|
|
|
* @return void |
|
51
|
|
|
*/ |
|
52
|
|
|
public function register() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->app['App\User'] = $this->app['Chuckbe\Chuckcms\Models\User']; |
|
55
|
|
|
|
|
56
|
|
|
// $this->app->make('Chuckbe\Chuckcms\Controllers\PageController'); |
|
57
|
|
|
// $this->app->make('Chuckbe\Chuckcms\Controllers\Auth\ForgotPasswordController'); |
|
58
|
|
|
// $this->app->make('Chuckbe\Chuckcms\Controllers\Auth\LoginController'); |
|
59
|
|
|
// $this->app->make('Chuckbe\Chuckcms\Controllers\Auth\RegisterController'); |
|
60
|
|
|
// $this->app->make('Chuckbe\Chuckcms\Controllers\Auth\ResetPasswordController'); |
|
61
|
|
|
|
|
62
|
|
|
$this->loadViewsFrom(__DIR__.'/views', 'chuckcms'); |
|
63
|
|
|
// publish error views + publish updated lfm views |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/chuckcms.php', 'chuckcms'); |
|
67
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/menu.php', 'menu'); |
|
68
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/lfm.php', 'lfm'); |
|
69
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/lang.php', 'lang'); |
|
70
|
|
|
|
|
71
|
|
|
$this->app->register( |
|
72
|
|
|
'Chuckbe\Chuckcms\Providers\ChuckSiteServiceProvider' |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$this->app->register( |
|
76
|
|
|
'Chuckbe\Chuckcms\Providers\ChuckTemplateServiceProvider' |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$this->app->register( |
|
80
|
|
|
'Chuckbe\Chuckcms\Providers\ChuckConfigServiceProvider' |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$this->app->register( |
|
84
|
|
|
'Chuckbe\Chuckcms\Providers\ChuckServiceProvider' |
|
85
|
|
|
); |
|
86
|
|
|
|
|
87
|
|
|
$this->app->register( |
|
88
|
|
|
'Chuckbe\Chuckcms\Providers\ChuckMenuServiceProvider' |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
$this->app->register( |
|
92
|
|
|
'Chuckbe\Chuckcms\Providers\ChuckRepeaterServiceProvider' |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
$this->app->register( |
|
96
|
|
|
'Chuckbe\Chuckcms\Providers\ChuckDashboardSidebarViewComposerServiceProvider' |
|
97
|
|
|
); |
|
98
|
|
|
|
|
99
|
|
|
$this->app->register( |
|
100
|
|
|
'Msurguy\Honeypot\HoneypotServiceProvider' |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
|
104
|
|
|
$loader->alias('ChuckSite', 'Chuckbe\Chuckcms\Facades\Site'); |
|
105
|
|
|
$loader->alias('Chuck', 'Chuckbe\Chuckcms\Facades\Chuck'); |
|
106
|
|
|
$loader->alias('ChuckRepeater', 'Chuckbe\Chuckcms\Facades\Repeater'); |
|
107
|
|
|
$loader->alias('ChuckTemplate', 'Chuckbe\Chuckcms\Facades\Template'); |
|
108
|
|
|
$loader->alias('ChuckMenu', 'Chuckbe\Chuckcms\Facades\Menu'); |
|
109
|
|
|
$loader->alias('Honeypot', 'Msurguy\Honeypot\HoneypotFacade'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function doPublishing() |
|
113
|
|
|
{ |
|
114
|
|
|
if (!function_exists('config_path')) { |
|
115
|
|
|
// function not available and 'publish' not relevant in Lumen (credit: Spatie) |
|
116
|
|
|
return; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$this->publishes([ |
|
120
|
|
|
__DIR__.'/resources' => public_path('chuckbe/chuckcms'), |
|
121
|
|
|
], 'chuckcms-public'); |
|
122
|
|
|
|
|
123
|
|
|
$this->publishes([ |
|
124
|
|
|
__DIR__.'/../config/chuckcms.php' => config_path('chuckcms.php'), |
|
125
|
|
|
__DIR__.'/../config/menu.php' => config_path('menu.php'), |
|
126
|
|
|
__DIR__.'/../config/lfm.php' => config_path('lfm.php'), |
|
127
|
|
|
__DIR__.'/../config/lang.php' => config_path('lang.php'), |
|
128
|
|
|
], 'chuckcms-config'); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Returns existing migration file if found, else uses the current timestamp. |
|
133
|
|
|
* |
|
134
|
|
|
* @return string |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getMigrationFileName($migrationFileName): string |
|
137
|
|
|
{ |
|
138
|
|
|
$timestamp = date('Y_m_d_His'); |
|
139
|
|
|
|
|
140
|
|
|
$filesystem = $this->app->make(Filesystem::class); |
|
141
|
|
|
|
|
142
|
|
|
return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR) |
|
143
|
|
|
->flatMap(function ($path) use ($filesystem, $migrationFileName) { |
|
144
|
|
|
return $filesystem->glob($path.'*_'.$migrationFileName); |
|
145
|
|
|
}) |
|
146
|
|
|
->push($this->app->databasePath()."/migrations/{$timestamp}_{$migrationFileName}") |
|
147
|
|
|
->first(); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|