Completed
Push — master ( 296a16...4bfed2 )
by Arjay
24:39 queued 09:40
created

ViewComposerServiceProvider::getFileDirectories()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 9.4285
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
     * Bootstrap the application services.
18
     *
19
     * @return void
20
     */
21
    public function boot()
22
    {
23
        $this->bootAdministratorViewComposer();
24
25
        view()->composer('*', function (View $view) {
26
            $view->with('active_menu', session('active_menu', new Menu));
27
        });
28
    }
29
30
    /**
31
     * Register administrator view composers.
32
     */
33
    protected function bootAdministratorViewComposer()
34
    {
35
        view()->composer('administrator.widgets.*', function (View $view) {
36
            /** @var \Yajra\CMS\Themes\Repositories\Repository $themes */
37
            $themes    = $this->app['themes'];
38
            $theme     = $themes->current();
39
            $positions = $theme->positions;
40
            $data      = [];
41
            foreach ($positions as $position) {
42
                $data[$position] = Str::title($position);
43
            }
44
45
            $view->with('widget_positions', $data);
46
            $view->with('theme', $theme);
47
48
            /** @var \Yajra\CMS\Repositories\Extension\Repository $extensions */
49
            $extensions = $this->app['extensions'];
50
            $widgets    = $extensions->allWidgets()->filter(function ($extension) {
51
                return $extension->enabled;
52
            });
53
            $view->with('extensions', $widgets);
54
        });
55
56
        view()->composer(['administrator.partials.permissions'], function (View $view) {
57
            $view->with('permissions', Permission::orderBy('resource')->get());
58
        });
59
    }
60
61
    /**
62
     * Register the application services.
63
     *
64
     * @return void
65
     */
66
    public function register()
67
    {
68
        //
69
    }
70
}
71