-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
MediaManagerServiceProvider.php
129 lines (107 loc) · 3.29 KB
/
MediaManagerServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace ctf0\MediaManager;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
use ctf0\MediaManager\Commands\PackageSetup;
use ctf0\PackageChangeLog\PackageChangeLogServiceProvider;
class MediaManagerServiceProvider extends ServiceProvider
{
protected $file;
public function boot()
{
$this->file = $this->app['files'];
$this->packagePublish();
$this->socketRoute();
$this->viewComp();
$this->command();
}
/**
* publish package assets.
*
* @return [type] [description]
*/
protected function packagePublish()
{
// config
$this->publishes([
__DIR__ . '/config' => config_path(),
], 'config');
// database
$this->publishes([
__DIR__ . '/database/MediaManager.sqlite' => database_path('MediaManager.sqlite'),
], 'db');
$this->publishes([
__DIR__ . '/database/migrations' => database_path('migrations'),
], 'migration');
// resources
$this->publishes([
__DIR__ . '/resources/assets' => resource_path('assets/vendor/MediaManager'),
], 'assets');
// trans
$this->loadTranslationsFrom(__DIR__ . '/resources/lang', 'MediaManager');
$this->publishes([
__DIR__ . '/resources/lang' => resource_path('lang/vendor/MediaManager'),
], 'trans');
// views
$this->loadViewsFrom(__DIR__ . '/resources/views', 'MediaManager');
$this->publishes([
__DIR__ . '/resources/views' => resource_path('views/vendor/MediaManager'),
], 'view');
}
protected function socketRoute()
{
Broadcast::channel('User.{id}.media', function ($user, $id) {
return $user->id == $id;
});
}
/**
* share data with view.
*
* @return [type] [description]
*/
protected function viewComp()
{
$data = [];
// base url
$config = $this->app['config']->get('mediaManager');
$url = $this->app['filesystem']
->disk($config['storage_disk'])
->url('/');
$data['base_url'] = preg_replace('/\/+$/', '/', $url);
// upload panel bg patterns
$pattern_path = public_path('assets/vendor/MediaManager/patterns');
if ($this->file->exists($pattern_path)) {
$patterns = collect(
$this->file->allFiles($pattern_path)
)->map(function ($item) {
$name = str_replace('\\', '/', $item->getPathName());
return preg_replace('/.*\/patterns/', '/assets/vendor/MediaManager/patterns', $name);
});
$data['patterns'] = json_encode($patterns);
}
// share
view()->composer('MediaManager::_manager', function ($view) use ($data) {
$view->with($data);
});
}
/**
* package commands.
*
* @return [type] [description]
*/
protected function command()
{
$this->commands([
PackageSetup::class,
]);
}
/**
* extra functionality.
*
* @return [type] [description]
*/
public function register()
{
$this->app->register(PackageChangeLogServiceProvider::class);
}
}