Completed
Push — master ( a5e67f...50b64d )
by Maxime
18:42
created

LayoutManager::initStaticPart()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 23
ccs 18
cts 18
cp 1
rs 9.0856
cc 3
eloc 11
nc 3
nop 1
crap 3
1
<?php namespace Distilleries\Expendable\Layouts;
2
3
use Closure;
4
use Distilleries\Expendable\Contracts\LayoutManagerContract;
5
use Distilleries\Expendable\Contracts\StateDisplayerContract;
6
use Illuminate\Contracts\View\Factory;
7
use Illuminate\Filesystem\Filesystem;
8
use PhpParser\Node\Expr\Cast\Object;
9
10
class LayoutManager implements LayoutManagerContract {
11
12
13
    protected $config;
14
    protected $view;
15
    protected $state;
16
    protected $filesystem;
17
    protected $items = [];
18
    protected $layout = null;
19
20 316
    public function __construct(array $config, Factory $view, Filesystem $filesystem, StateDisplayerContract $state)
21
    {
22 316
        $this->config     = $config;
23 316
        $this->view       = $view;
24 316
        $this->filesystem = $filesystem;
25 316
        $this->state      = $state;
26 316
    }
27
28
29 316
    public function setupLayout($layout)
30
    {
31 316
        $this->layout = $layout;
32 316
    }
33
34 316
    public function initInterfaces(array $interfaces, $class)
35
    {
36
37 316
        foreach ($interfaces as $interface)
38
        {
39 256
            if (strpos($interface, 'StateContract') !== false)
40 256
            {
41 256
                $this->state->setState($interface);
42 256
            }
43 316
        }
44
45 316
        $this->state->setClass($class);
46 316
    }
47
48 316
    public function initStaticPart(Closure $closure = null)
49
    {
50 316
        if (!is_null($this->layout))
51 316
        {
52 316
            $header = $this->view->make('expendable::admin.part.header')->with([
53 4
                'title'   => ''
54 316
            ]);
55 316
            $footer = $this->view->make('expendable::admin.part.footer')->with([
56
                'title'   => ''
57 316
            ]);
58
59 316
            $this->add([
60 316
                'header' => $header,
61 316
                'footer' => $footer,
62 316
            ]);
63
64 316
            if (!empty($closure))
65 316
            {
66 256
                $closure($this);
67 256
            }
68
69 316
        }
70 316
    }
71
72 316
    public function add(array $items)
73
    {
74 316
        $this->items = array_merge($this->items, $items);
75 316
    }
76
77 100
    public function render()
78
    {
79 100
        return $this->view->make($this->layout, $this->items);
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function getConfig()
86
    {
87
        return $this->config;
88
    }
89
90
    /**
91
     * @return Factory
92
     */
93 256
    public function getView()
94
    {
95 256
        return $this->view;
96
    }
97
98
    /**
99
     * @return StateDisplayerContract
100
     */
101 256
    public function getState()
102
    {
103 256
        return $this->state;
104
    }
105
106
    /**
107
     * @return Filesystem
108
     */
109
    public function getFilesystem()
110
    {
111
        return $this->filesystem;
112
    }
113
114
115
}