|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\View\View; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
use Illuminate\Support\Str; |
|
8
|
|
|
use Yajra\Acl\Models\Permission; |
|
9
|
|
|
use Yajra\CMS\Entities\Category; |
|
10
|
|
|
use Yajra\CMS\Entities\Configuration; |
|
11
|
|
|
use Yajra\CMS\Entities\Menu; |
|
12
|
|
|
use Symfony\Component\Finder\Finder; |
|
13
|
|
|
|
|
14
|
|
|
class ViewComposerServiceProvider extends ServiceProvider |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Media public storage. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
public $mediaPath = 'app/public/media'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Bootstrap the application services. |
|
25
|
|
|
* |
|
26
|
|
|
* @return void |
|
27
|
|
|
*/ |
|
28
|
|
|
public function boot() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->bootAdministratorViewComposer(); |
|
31
|
|
|
|
|
32
|
|
|
view()->composer('*', function(View $view) { |
|
|
|
|
|
|
33
|
|
|
$view->with('active_menu', session('active_menu', new Menu)); |
|
34
|
|
|
}); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Register administrator view composers. |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function bootAdministratorViewComposer() |
|
41
|
|
|
{ |
|
42
|
|
|
view()->composer('administrator.widgets.*', function (View $view) { |
|
|
|
|
|
|
43
|
|
|
/** @var \Yajra\CMS\Themes\Repositories\Repository $themes */ |
|
44
|
|
|
$themes = $this->app['themes']; |
|
45
|
|
|
$theme = $themes->current(); |
|
46
|
|
|
$positions = $theme->positions; |
|
47
|
|
|
$data = []; |
|
48
|
|
|
foreach ($positions as $position) { |
|
49
|
|
|
$data[$position] = Str::title($position); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$view->with('widget_positions', $data); |
|
53
|
|
|
$view->with('theme', $theme); |
|
54
|
|
|
|
|
55
|
|
|
/** @var \Yajra\CMS\Repositories\Extension\Repository $extensions */ |
|
56
|
|
|
$extensions = $this->app['extensions']; |
|
57
|
|
|
$widgets = $extensions->allWidgets()->filter(function ($extension) { |
|
58
|
|
|
return $extension->enabled; |
|
59
|
|
|
}); |
|
60
|
|
|
$view->with('extensions', $widgets); |
|
61
|
|
|
}); |
|
62
|
|
|
|
|
63
|
|
|
view()->composer(['administrator.partials.permissions'], function (View $view) { |
|
|
|
|
|
|
64
|
|
|
$view->with('permissions', Permission::all()); |
|
65
|
|
|
}); |
|
66
|
|
|
|
|
67
|
|
|
view()->composer(['system.macro.image-browser'], function (View $view) { |
|
|
|
|
|
|
68
|
|
|
$view->with('mediaDirectories', $this->getFileDirectories()); |
|
69
|
|
|
}); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Show all directories on media path. |
|
74
|
|
|
* |
|
75
|
|
|
* @return array |
|
76
|
|
|
*/ |
|
77
|
|
View Code Duplication |
protected function getFileDirectories() |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
$mediaFiles['/'] = '/'; |
|
|
|
|
|
|
80
|
|
|
$path = storage_path($this->mediaPath); |
|
81
|
|
|
foreach ($this->getFiles($path)->directories() as $file) { |
|
82
|
|
|
$strFile = str_replace($path, '', $file->getRealPath()); |
|
83
|
|
|
$mediaFiles[$strFile] = $strFile; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $mediaFiles; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Symfony file finder. |
|
91
|
|
|
* Show all files in selected $path directory. |
|
92
|
|
|
* Sort by file type. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $path |
|
95
|
|
|
* @return \Symfony\Component\Finder\Finder |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function getFiles($path) |
|
98
|
|
|
{ |
|
99
|
|
|
return Finder::create()->in($path)->sortByType(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Register the application services. |
|
104
|
|
|
* |
|
105
|
|
|
* @return void |
|
106
|
|
|
*/ |
|
107
|
|
|
public function register() |
|
108
|
|
|
{ |
|
109
|
|
|
// |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: