1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD; |
4
|
|
|
|
5
|
|
|
use Route; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
|
8
|
|
|
class CrudServiceProvider extends ServiceProvider |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Indicates if loading of the provider is deferred. |
12
|
|
|
* |
13
|
|
|
* @var bool |
14
|
|
|
*/ |
15
|
|
|
protected $defer = false; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Perform post-registration booting of services. |
19
|
|
|
* |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
|
public function boot() |
23
|
|
|
{ |
24
|
|
|
// LOAD THE VIEWS |
25
|
|
|
|
26
|
|
|
// - first the published/overwritten views (in case they have any changes) |
27
|
|
|
$this->loadViewsFrom(resource_path('views/vendor/backpack/crud'), 'crud'); |
28
|
|
|
// - then the stock views that come with the package, in case a published view might be missing |
29
|
|
|
$this->loadViewsFrom(realpath(__DIR__.'/resources/views'), 'crud'); |
30
|
|
|
|
31
|
|
|
$this->loadTranslationsFrom(realpath(__DIR__.'/resources/lang'), 'backpack'); |
32
|
|
|
|
33
|
|
|
// PUBLISH FILES |
34
|
|
|
|
35
|
|
|
// publish lang files |
36
|
|
|
$this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang'); |
37
|
|
|
|
38
|
|
|
// publish views |
39
|
|
|
$this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/crud')], 'views'); |
40
|
|
|
|
41
|
|
|
// publish config file |
42
|
|
|
$this->publishes([__DIR__.'/config' => config_path()], 'config'); |
43
|
|
|
|
44
|
|
|
// publish public Backpack CRUD assets |
45
|
|
|
$this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public'); |
46
|
|
|
|
47
|
|
|
// publish custom files for elFinder |
48
|
|
|
$this->publishes([ |
49
|
|
|
__DIR__.'/config/elfinder.php' => config_path('elfinder.php'), |
50
|
|
|
__DIR__.'/resources/views-elfinder' => resource_path('views/vendor/elfinder'), |
51
|
|
|
], 'elfinder'); |
52
|
|
|
|
53
|
|
|
// AUTO PUBLISH |
54
|
|
|
if (\App::environment('local')) { |
55
|
|
|
if ($this->shouldAutoPublishPublic()) { |
56
|
|
|
\Artisan::call('vendor:publish', [ |
57
|
|
|
'--provider' => 'Backpack\CRUD\CrudServiceProvider', |
58
|
|
|
'--tag' => 'public', |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// use the vendor configuration file as fallback |
64
|
|
|
$this->mergeConfigFrom( |
65
|
|
|
__DIR__.'/config/backpack/crud.php', |
66
|
|
|
'backpack.crud' |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Register any package services. |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function register() |
76
|
|
|
{ |
77
|
|
|
$this->app->bind('CRUD', function ($app) { |
78
|
|
|
return new CRUD($app); |
79
|
|
|
}); |
80
|
|
|
|
81
|
|
|
// register its dependencies |
82
|
|
|
$this->app->register(\Backpack\Base\BaseServiceProvider::class); |
83
|
|
|
$this->app->register(\Collective\Html\HtmlServiceProvider::class); |
84
|
|
|
$this->app->register(\Barryvdh\Elfinder\ElfinderServiceProvider::class); |
85
|
|
|
$this->app->register(\Intervention\Image\ImageServiceProvider::class); |
86
|
|
|
|
87
|
|
|
// register their aliases |
88
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
89
|
|
|
$loader->alias('CRUD', \Backpack\CRUD\CrudServiceProvider::class); |
|
|
|
|
90
|
|
|
$loader->alias('Form', \Collective\Html\FormFacade::class); |
91
|
|
|
$loader->alias('Html', \Collective\Html\HtmlFacade::class); |
92
|
|
|
$loader->alias('Image', \Intervention\Image\Facades\Image::class); |
93
|
|
|
|
94
|
|
|
// map the elfinder prefix |
95
|
|
|
if (! \Config::get('elfinder.route.prefix')) { |
96
|
|
|
\Config::set('elfinder.route.prefix', \Config::get('backpack.base.route_prefix').'/elfinder'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function resource($name, $controller, array $options = []) |
101
|
|
|
{ |
102
|
|
|
return new CrudRouter($name, $controller, $options); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Checks to see if we should automatically publish |
107
|
|
|
* vendor files from the public tag. |
108
|
|
|
* |
109
|
|
|
* @return bool |
110
|
|
|
*/ |
111
|
|
|
private function shouldAutoPublishPublic() |
112
|
|
|
{ |
113
|
|
|
$crudPubPath = public_path('vendor/backpack/crud'); |
114
|
|
|
|
115
|
|
|
if (! is_dir($crudPubPath)) { |
|
|
|
|
116
|
|
|
return true; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return false; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This check looks for accesses to local static members using the fully qualified name instead of
self::
.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBC
could just as well be replaced byself::TRIPLEDES_CBC
. Referencing local members withself::
assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.