|
1
|
|
|
<?php |
|
2
|
|
|
namespace Malezha\Menu\Factory; |
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Contracts\Config\Repository; |
|
5
|
|
|
use Illuminate\Contracts\Container\Container; |
|
6
|
|
|
use Malezha\Menu\Contracts\ElementFactory; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class AbstractElementFactory |
|
10
|
|
|
* @package Malezha\Menu\Factory |
|
11
|
|
|
*/ |
|
12
|
|
|
abstract class AbstractElementFactory implements ElementFactory |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var Container |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $app; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $parameters = []; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @inheritdoc |
|
26
|
|
|
*/ |
|
27
|
27 |
|
public function __construct(Container $container) |
|
28
|
|
|
{ |
|
29
|
27 |
|
$this->app = $container; |
|
30
|
27 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $class |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
27 |
|
protected function getElementConfig($class) |
|
37
|
|
|
{ |
|
38
|
27 |
|
return $this->app->make(Repository::class)->get('menu.elements')[$class]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $name |
|
43
|
|
|
* @return mixed |
|
44
|
|
|
*/ |
|
45
|
12 |
|
protected function getParameter($name) |
|
46
|
|
|
{ |
|
47
|
12 |
|
if (array_key_exists($name, $this->parameters)) { |
|
48
|
12 |
|
return $this->parameters[$name]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return null; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $name |
|
56
|
|
|
* @param mixed $value |
|
57
|
|
|
* @return $this |
|
58
|
|
|
*/ |
|
59
|
26 |
|
protected function setParameter($name, $value) |
|
60
|
|
|
{ |
|
61
|
26 |
|
$this->parameters[$name] = $value; |
|
62
|
|
|
|
|
63
|
26 |
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $name |
|
68
|
|
|
* @return $this |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function unsetParameter($name) |
|
71
|
|
|
{ |
|
72
|
|
|
unset($this->parameters[$name]); |
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string $name |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function existsParameter($name) |
|
82
|
|
|
{ |
|
83
|
|
|
return array_key_exists($name, $this->parameters); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param array $parameters |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
22 |
|
protected function mergeParameters($parameters = []) |
|
91
|
|
|
{ |
|
92
|
22 |
|
return array_merge($this->parameters, $parameters); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @inheritDoc |
|
97
|
|
|
*/ |
|
98
|
12 |
|
function __get($name) |
|
99
|
|
|
{ |
|
100
|
12 |
|
return $this->getParameter($name); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @inheritDoc |
|
105
|
|
|
*/ |
|
106
|
26 |
|
function __set($name, $value) |
|
107
|
|
|
{ |
|
108
|
26 |
|
$this->setParameter($name, $value); |
|
109
|
26 |
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @inheritDoc |
|
113
|
|
|
*/ |
|
114
|
|
|
function __isset($name) |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->existsParameter($name); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @inheritDoc |
|
121
|
|
|
*/ |
|
122
|
|
|
function __unset($name) |
|
123
|
|
|
{ |
|
124
|
|
|
$this->unsetParameter($name); |
|
125
|
|
|
} |
|
126
|
|
|
} |