1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\Base; |
4
|
|
|
|
5
|
|
|
use Illuminate\Routing\Router; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Route; |
8
|
|
|
|
9
|
|
|
class BaseServiceProvider extends ServiceProvider |
10
|
|
|
{ |
11
|
|
|
protected $commands = [ |
12
|
|
|
\Backpack\Base\app\Console\Commands\Install::class, |
13
|
|
|
\Backpack\Base\app\Console\Commands\AddSidebarContent::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
|
|
|
// LOAD THE VIEWS |
38
|
|
|
// - first the published views (in case they have any changes) |
39
|
|
|
$this->loadViewsFrom(resource_path('views/vendor/backpack/base'), 'backpack'); |
40
|
|
|
// - then the stock views that come with the package, in case a published view might be missing |
41
|
|
|
$this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'backpack'); |
42
|
|
|
|
43
|
|
|
$this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack'); |
44
|
|
|
|
45
|
|
|
// use the vendor configuration file as fallback |
46
|
|
|
$this->mergeConfigFrom( |
47
|
|
|
__DIR__.'/config/backpack/base.php', 'backpack.base' |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
// add the root disk to filesystem configuration |
51
|
|
|
app()->config['filesystems.disks.root'] = [ |
52
|
|
|
'driver' => 'local', |
53
|
|
|
'root' => base_path(), |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$this->registerMiddlewareGroup($this->app->router); |
|
|
|
|
57
|
|
|
$this->setupRoutes($this->app->router); |
|
|
|
|
58
|
|
|
$this->publishFiles(); |
59
|
|
|
$this->loadHelpers(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Load the Backpack helper methods, for convenience. |
64
|
|
|
*/ |
65
|
|
|
public function loadHelpers() |
66
|
|
|
{ |
67
|
|
|
require_once __DIR__.'/helpers.php'; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Define the routes for the application. |
72
|
|
|
* |
73
|
|
|
* @param \Illuminate\Routing\Router $router |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function setupRoutes(Router $router) |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
// by default, use the routes file provided in vendor |
80
|
|
|
$routeFilePathInUse = __DIR__.$this->routeFilePath; |
81
|
|
|
|
82
|
|
|
// but if there's a file with the same name in routes/backpack, use that one |
83
|
|
|
if (file_exists(base_path().$this->routeFilePath)) { |
84
|
|
|
$routeFilePathInUse = base_path().$this->routeFilePath; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$this->loadRoutesFrom($routeFilePathInUse); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Register any package services. |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
public function register() |
96
|
|
|
{ |
97
|
|
|
// register the current package |
98
|
|
|
$this->app->bind('base', function ($app) { |
99
|
|
|
return new Base($app); |
100
|
|
|
}); |
101
|
|
|
|
102
|
|
|
// register its dependencies |
103
|
|
|
$this->app->register(\Jenssegers\Date\DateServiceProvider::class); |
104
|
|
|
$this->app->register(\Prologue\Alerts\AlertsServiceProvider::class); |
105
|
|
|
$this->app->register(\Creativeorange\Gravatar\GravatarServiceProvider::class); |
106
|
|
|
|
107
|
|
|
// register their aliases |
108
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
109
|
|
|
$loader->alias('Alert', \Prologue\Alerts\Facades\Alert::class); |
110
|
|
|
$loader->alias('Date', \Jenssegers\Date\Date::class); |
111
|
|
|
$loader->alias('Gravatar', \Creativeorange\Gravatar\Facades\Gravatar::class); |
112
|
|
|
|
113
|
|
|
// register the services that are only used for development |
114
|
|
|
if ($this->app->environment() == 'local') { |
115
|
|
|
if (class_exists('Laracasts\Generators\GeneratorsServiceProvider')) { |
116
|
|
|
$this->app->register('Laracasts\Generators\GeneratorsServiceProvider'); |
117
|
|
|
} |
118
|
|
|
if (class_exists('Backpack\Generators\GeneratorsServiceProvider')) { |
119
|
|
|
$this->app->register('Backpack\Generators\GeneratorsServiceProvider'); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// register the artisan commands |
124
|
|
|
$this->commands($this->commands); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function registerMiddlewareGroup(Router $router) |
128
|
|
|
{ |
129
|
|
|
$middleware_key = config('backpack.base.middleware_key'); |
130
|
|
|
$middleware_class = config('backpack.base.middleware_class'); |
131
|
|
|
|
132
|
|
|
if (!is_array($middleware_class)) { |
133
|
|
|
$router->pushMiddlewareToGroup($middleware_key, $middleware_class); |
134
|
|
|
|
135
|
|
|
return; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
foreach ($middleware_class as $middleware_class) { |
139
|
|
|
$router->pushMiddlewareToGroup($middleware_key, $middleware_class); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function publishFiles() |
144
|
|
|
{ |
145
|
|
|
$error_views = [__DIR__.'/resources/error_views' => resource_path('views/errors')]; |
146
|
|
|
$backpack_base_views = [__DIR__.'/resources/views' => resource_path('views/vendor/backpack/base')]; |
147
|
|
|
$backpack_public_assets = [__DIR__.'/public' => public_path('vendor/backpack')]; |
148
|
|
|
$backpack_lang_files = [__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')]; |
149
|
|
|
$backpack_config_files = [__DIR__.'/config' => config_path()]; |
150
|
|
|
|
151
|
|
|
// sidebar_content view, which is the only view most people need to overwrite |
152
|
|
|
$backpack_sidebar_contents_view = [__DIR__.'/resources/views/inc/sidebar_content.blade.php' => resource_path('views/vendor/backpack/base/inc/sidebar_content.blade.php')]; |
153
|
|
|
|
154
|
|
|
// calculate the path from current directory to get the vendor path |
155
|
|
|
$vendorPath = dirname(__DIR__, 3); |
156
|
|
|
$adminlte_assets = [$vendorPath.'/almasaeed2010/adminlte' => public_path('vendor/adminlte')]; |
157
|
|
|
$gravatar_assets = [$vendorPath.'/creativeorange/gravatar/config' => config_path()]; |
158
|
|
|
|
159
|
|
|
// establish the minimum amount of files that need to be published, for Backpack to work; there are the files that will be published by the install command |
160
|
|
|
$minimum = array_merge( |
161
|
|
|
$error_views, |
162
|
|
|
// $backpack_base_views, |
163
|
|
|
$backpack_public_assets, |
164
|
|
|
// $backpack_lang_files, |
165
|
|
|
$backpack_config_files, |
166
|
|
|
$backpack_sidebar_contents_view, |
167
|
|
|
$adminlte_assets, |
168
|
|
|
$gravatar_assets |
169
|
|
|
); |
170
|
|
|
|
171
|
|
|
// register all possible publish commands and assign tags to each |
172
|
|
|
$this->publishes($backpack_config_files, 'config'); |
173
|
|
|
$this->publishes($backpack_lang_files, 'lang'); |
174
|
|
|
$this->publishes($backpack_base_views, 'views'); |
175
|
|
|
$this->publishes($backpack_sidebar_contents_view, 'sidebar_content'); |
176
|
|
|
$this->publishes($error_views, 'errors'); |
177
|
|
|
$this->publishes($backpack_public_assets, 'public'); |
178
|
|
|
$this->publishes($adminlte_assets, 'adminlte'); |
179
|
|
|
$this->publishes($gravatar_assets, 'gravatar'); |
180
|
|
|
$this->publishes($minimum, 'minimum'); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.