1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\Base; |
4
|
|
|
|
5
|
|
|
use Config; |
6
|
|
|
use Illuminate\Routing\Router; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use Route; |
9
|
|
|
|
10
|
|
|
class BaseServiceProvider extends ServiceProvider |
11
|
|
|
{ |
12
|
|
|
protected $commands = [ |
13
|
|
|
\Backpack\Base\app\Console\Commands\Install::class, |
14
|
|
|
]; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Indicates if loading of the provider is deferred. |
18
|
|
|
* |
19
|
|
|
* @var bool |
20
|
|
|
*/ |
21
|
|
|
protected $defer = false; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Where the route file lives, both inside the package and in the app (if overwritten). |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $routeFilePath = '/routes/backpack/base.php'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Perform post-registration booting of services. |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function boot(\Illuminate\Routing\Router $router) |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
// ------------- |
38
|
|
|
// LOAD THE VIEWS |
39
|
|
|
// ------------- |
40
|
|
|
// first the published views (in case they have any changes) |
41
|
|
|
$this->loadViewsFrom(resource_path('views/vendor/backpack/base'), 'backpack'); |
42
|
|
|
// then the stock views that come with the package, in case a published view might be missing |
43
|
|
|
$this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backpack'); |
44
|
|
|
|
45
|
|
|
$this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack'); |
46
|
|
|
|
47
|
|
|
// use the vendor configuration file as fallback |
48
|
|
|
$this->mergeConfigFrom( |
49
|
|
|
__DIR__.'/config/backpack/base.php', |
50
|
|
|
'backpack.base' |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$this->registerGuards(); |
54
|
|
|
$this->registerMiddleware($this->app->router); |
|
|
|
|
55
|
|
|
$this->setupRoutes($this->app->router); |
|
|
|
|
56
|
|
|
$this->publishFiles(); |
57
|
|
|
$this->loadHelpers(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Load the Backpack helper methods, for convenience. |
62
|
|
|
*/ |
63
|
|
|
public function loadHelpers() |
64
|
|
|
{ |
65
|
|
|
require_once __DIR__.'/helpers.php'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Define the routes for the application. |
70
|
|
|
* |
71
|
|
|
* @param \Illuminate\Routing\Router $router |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function setupRoutes(Router $router) |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
// by default, use the routes file provided in vendor |
78
|
|
|
$routeFilePathInUse = __DIR__.$this->routeFilePath; |
79
|
|
|
|
80
|
|
|
// but if there's a file with the same name in routes/backpack, use that one |
81
|
|
|
if (file_exists(base_path().$this->routeFilePath)) { |
82
|
|
|
$routeFilePathInUse = base_path().$this->routeFilePath; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->loadRoutesFrom($routeFilePathInUse); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Register custom backpack authentication guard. |
90
|
|
|
*/ |
91
|
|
|
public function registerGuards() |
92
|
|
|
{ |
93
|
|
|
$backpackAuthGuard = Config::get('backpack.base.admin_guard'); |
94
|
|
|
$existingGuards = Config::get('auth.guards'); |
95
|
|
|
$existingGuards[$backpackAuthGuard['name']] = $backpackAuthGuard; |
96
|
|
|
|
97
|
|
|
Config::set('auth.guards', $existingGuards); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Register any package services. |
102
|
|
|
* |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
public function register() |
106
|
|
|
{ |
107
|
|
|
// register the current package |
108
|
|
|
$this->app->bind('base', function ($app) { |
109
|
|
|
return new Base($app); |
110
|
|
|
}); |
111
|
|
|
|
112
|
|
|
// register its dependencies |
113
|
|
|
$this->app->register(\Jenssegers\Date\DateServiceProvider::class); |
114
|
|
|
$this->app->register(\Prologue\Alerts\AlertsServiceProvider::class); |
115
|
|
|
$this->app->register(\Creativeorange\Gravatar\GravatarServiceProvider::class); |
116
|
|
|
|
117
|
|
|
// register their aliases |
118
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
119
|
|
|
$loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class); |
120
|
|
|
$loader->alias('Date', \Jenssegers\Date\Date::class); |
121
|
|
|
$loader->alias('Gravatar', \Creativeorange\Gravatar\Facades\Gravatar::class); |
122
|
|
|
|
123
|
|
|
// register the services that are only used for development |
124
|
|
|
if ($this->app->environment() == 'local') { |
125
|
|
|
if (class_exists('Laracasts\Generators\GeneratorsServiceProvider')) { |
126
|
|
|
$this->app->register('Laracasts\Generators\GeneratorsServiceProvider'); |
127
|
|
|
} |
128
|
|
|
if (class_exists('Backpack\Generators\GeneratorsServiceProvider')) { |
129
|
|
|
$this->app->register('Backpack\Generators\GeneratorsServiceProvider'); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
// register the artisan commands |
134
|
|
|
$this->commands($this->commands); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function registerMiddleware(Router $router) |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
Route::aliasMiddleware('backpack.auth', \Backpack\Base\app\Http\Middleware\BackpackAuth::class); |
140
|
|
|
|
141
|
|
|
if (config('backpack.base.separate_admin_session')) { |
142
|
|
|
Route::aliasMiddleware('backpack.auth.guard', \Backpack\Base\app\Http\Middleware\BackpackAuthGuard::class); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function publishFiles() |
147
|
|
|
{ |
148
|
|
|
// publish config file |
149
|
|
|
$this->publishes([__DIR__.'/config' => config_path()], 'config'); |
150
|
|
|
|
151
|
|
|
// publish lang files |
152
|
|
|
// $this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang'); |
|
|
|
|
153
|
|
|
|
154
|
|
|
// publish views |
155
|
|
|
$this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/base')], 'views'); |
156
|
|
|
|
157
|
|
|
// publish error views |
158
|
|
|
$this->publishes([__DIR__.'/resources/error_views' => resource_path('views/errors')], 'errors'); |
159
|
|
|
|
160
|
|
|
// publish public Backpack assets |
161
|
|
|
$this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public'); |
162
|
|
|
|
163
|
|
|
// calculate the path from current directory to get the vendor path |
164
|
|
|
$vendorPath = dirname(__DIR__, 3); |
165
|
|
|
|
166
|
|
|
// publish public AdminLTE assets |
167
|
|
|
$this->publishes([$vendorPath.'/almasaeed2010/adminlte' => public_path('vendor/adminlte')], 'adminlte'); |
168
|
|
|
|
169
|
|
|
// publish public Gravatar assets |
170
|
|
|
$this->publishes([$vendorPath.'/creativeorange/gravatar/config' => config_path()], 'gravatar'); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.