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