forked from Laravel-Backpack/Base
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseServiceProvider.php
More file actions
134 lines (112 loc) · 4.4 KB
/
Copy pathBaseServiceProvider.php
File metadata and controls
134 lines (112 loc) · 4.4 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
<?php
namespace Backpack\Base;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
use Route;
class BaseServiceProvider extends ServiceProvider
{
/**
* 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->registerAdminMiddleware($this->app->router);
$this->setupRoutes($this->app->router);
$this->publishFiles();
}
/**
* 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 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);
// register their aliases
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
$loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class);
$loader->alias('Date', \Jenssegers\Date\Date::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');
}
}
}
public function registerAdminMiddleware(Router $router)
{
// in Laravel 5.4 and above
if (method_exists($router, 'pushMiddlewareToGroup')) {
Route::pushMiddlewareToGroup('admin', \Backpack\Base\app\Http\Middleware\Admin::class);
}
// in Laravel 5.3 and below
else {
Route::middleware('admin', \Backpack\Base\app\Http\Middleware\Admin::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');
// publish public AdminLTE assets
$this->publishes([base_path('vendor/almasaeed2010/adminlte') => public_path('vendor/adminlte')], 'adminlte');
}
}