Completed
Push — master ( 81e1a1...0dbe46 )
by ARCANEDEV
30:13
created

SidebarComposer::compose()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 12
ccs 0
cts 11
cp 0
rs 9.4286
cc 3
eloc 6
nc 3
nop 1
crap 12
1
<?php namespace Arcanesoft\Foundation\ViewComposers;
2
3
use Arcanesoft\Core\Helpers\Sidebar\Contracts\Sidebar;
4
use Illuminate\View\View;
5
6
/**
7
 * Class     SidebarComposer
8
 *
9
 * @package  Arcanesoft\Foundation\ViewComposers
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class SidebarComposer
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Properties
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * The Sidebar Helper instance.
20
     *
21
     * @var \Arcanesoft\Core\Helpers\Sidebar\Contracts\Sidebar
22
     */
23
    protected $sidebar;
24
25
    /* ------------------------------------------------------------------------------------------------
26
     |  Constructor
27
     | ------------------------------------------------------------------------------------------------
28
     */
29
    /**
30
     * SidebarComposer constructor.
31
     *
32
     * @param  \Arcanesoft\Core\Helpers\Sidebar\Contracts\Sidebar  $sidebar
33
     */
34
    public function __construct(Sidebar $sidebar)
35
    {
36
        $this->sidebar = $sidebar;
37
    }
38
39
    /* ------------------------------------------------------------------------------------------------
40
     |  Main Functions
41
     | ------------------------------------------------------------------------------------------------
42
     */
43
    /**
44
     * Bind data to the view.
45
     *
46
     * @param  \Illuminate\View\View  $view
47
     */
48
    public function compose(View $view)
49
    {
50
        foreach ($this->getSidebarItems() as $sidebarKey) {
51
            if (config()->has($sidebarKey)) {
52
                $this->sidebar->add(config($sidebarKey));
53
            }
54
        }
55
56
        $this->sidebar->setCurrent(
57
            array_get($view->getData(), 'current_page', '')
58
        );
59
    }
60
61
    /* ------------------------------------------------------------------------------------------------
62
     |  Other Functions
63
     | ------------------------------------------------------------------------------------------------
64
     */
65
    /**
66
     * Get sidebar items.
67
     *
68
     * @return array
69
     */
70
    private function getSidebarItems()
71
    {
72
        return config('arcanesoft.foundation.sidebar.items', []);
73
    }
74
}
75