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
|
|
|
// PUBLISH FILES |
32
|
|
|
|
33
|
|
|
// publish lang files |
34
|
|
|
$this->publishes([__DIR__.'/resources/lang' => resource_path('lang/vendor/backpack')], 'lang'); |
35
|
|
|
|
36
|
|
|
// publish views |
37
|
|
|
$this->publishes([__DIR__.'/resources/views' => resource_path('views/vendor/backpack/crud')], 'views'); |
38
|
|
|
|
39
|
|
|
// publish config file |
40
|
|
|
$this->publishes([__DIR__.'/config' => config_path()], 'config'); |
41
|
|
|
|
42
|
|
|
// publish public Backpack CRUD assets |
43
|
|
|
$this->publishes([__DIR__.'/public' => public_path('vendor/backpack')], 'public'); |
44
|
|
|
|
45
|
|
|
// publish custom files for elFinder |
46
|
|
|
$this->publishes([ |
47
|
|
|
__DIR__.'/config/elfinder.php' => config_path('elfinder.php'), |
48
|
|
|
__DIR__.'/resources/views-elfinder' => resource_path('views/vendor/elfinder'), |
49
|
|
|
], 'elfinder'); |
50
|
|
|
|
51
|
|
|
// AUTO PUBLISH |
52
|
|
|
if (\App::environment('local')) { |
53
|
|
|
if ($this->shouldAutoPublishPublic()) { |
54
|
|
|
\Artisan::call('vendor:publish', [ |
55
|
|
|
'--provider' => 'Backpack\CRUD\CrudServiceProvider', |
56
|
|
|
'--tag' => 'public', |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// use the vendor configuration file as fallback |
62
|
|
|
$this->mergeConfigFrom( |
63
|
|
|
__DIR__.'/config/backpack/crud.php', |
64
|
|
|
'backpack.crud' |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Register any package services. |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
public function register() |
74
|
|
|
{ |
75
|
|
|
$this->app->bind('CRUD', function ($app) { |
76
|
|
|
return new CRUD($app); |
77
|
|
|
}); |
78
|
|
|
|
79
|
|
|
// register its dependencies |
80
|
|
|
$this->app->register(\Backpack\Base\BaseServiceProvider::class); |
81
|
|
|
$this->app->register(\Collective\Html\HtmlServiceProvider::class); |
82
|
|
|
$this->app->register(\Barryvdh\Elfinder\ElfinderServiceProvider::class); |
83
|
|
|
$this->app->register(\Intervention\Image\ImageServiceProvider::class); |
84
|
|
|
|
85
|
|
|
// register their aliases |
86
|
|
|
$loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
87
|
|
|
$loader->alias('CRUD', \Backpack\CRUD\CrudServiceProvider::class); |
|
|
|
|
88
|
|
|
$loader->alias('Form', \Collective\Html\FormFacade::class); |
89
|
|
|
$loader->alias('Html', \Collective\Html\HtmlFacade::class); |
90
|
|
|
$loader->alias('Image', \Intervention\Image\Facades\Image::class); |
91
|
|
|
|
92
|
|
|
// map the elfinder prefix |
93
|
|
|
if (! \Config::get('elfinder.route.prefix')) { |
94
|
|
|
\Config::set('elfinder.route.prefix', \Config::get('backpack.base.route_prefix').'/elfinder'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public static function resource($name, $controller, array $options = []) |
99
|
|
|
{ |
100
|
|
|
return new CrudRouter($name, $controller, $options); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Checks to see if we should automatically publish |
105
|
|
|
* vendor files from the public tag. |
106
|
|
|
* |
107
|
|
|
* @return bool |
108
|
|
|
*/ |
109
|
|
|
private function shouldAutoPublishPublic() |
110
|
|
|
{ |
111
|
|
|
$crudPubPath = public_path('vendor/backpack/crud'); |
112
|
|
|
|
113
|
|
|
if (! is_dir($crudPubPath)) { |
|
|
|
|
114
|
|
|
return true; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return false; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
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.