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