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