1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Chay22\RecSelMeter; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
class Config |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* @var array $rank |
10
|
|
|
*/ |
11
|
|
|
private $rank = [ |
|
|
|
|
12
|
|
|
'auto banned' => -100, |
13
|
|
|
'kaskus addict' => 2, |
14
|
|
|
'kaskus maniac' => 3, |
15
|
|
|
'kaskus geek' => 7, |
16
|
|
|
'kaskus freak' => 10, |
17
|
|
|
'made in kaskus' => 15, |
18
|
|
|
'kaskus plus' => 15, |
19
|
|
|
'reg. leader' => 15, |
20
|
|
|
'moderator' => 15, |
21
|
|
|
'kaskus online bazaar' => 200, |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var array $feedback |
26
|
|
|
*/ |
27
|
|
|
private $feedback = [10]; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array $feedbackPercent |
31
|
|
|
*/ |
32
|
|
|
private $feedbackPercent = [10]; |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string $accountAge |
36
|
|
|
*/ |
37
|
|
|
private $accountAge = 5; |
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array $storeActive |
41
|
|
|
*/ |
42
|
|
|
private $storeActive = [ |
|
|
|
|
43
|
|
|
7 => 1, |
44
|
|
|
3 => 5, |
45
|
|
|
1 => 8, |
46
|
|
|
0 => 10, |
47
|
|
|
]; |
48
|
|
|
/** |
49
|
|
|
* @var string $imageCount |
50
|
|
|
*/ |
51
|
|
|
private $imageCount = 1; |
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var array $sold |
55
|
|
|
*/ |
56
|
|
|
private $sold = [ |
|
|
|
|
57
|
|
|
0 => 0, |
58
|
|
|
1 => 20, |
59
|
|
|
5 => 50, |
60
|
|
|
10 => 100, |
61
|
|
|
]; |
62
|
|
|
/** |
63
|
|
|
* @var string $cod |
64
|
|
|
*/ |
65
|
|
|
private $cod = 10; |
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Return set of configuration data (properties) |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
4 |
|
public function data() |
73
|
|
|
{ |
74
|
4 |
|
return get_object_vars($this); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Create/add/modify chosen property value |
79
|
|
|
* |
80
|
|
|
* @see ::create() |
81
|
|
|
* @see ::add() |
82
|
|
|
* @see ::set() |
83
|
|
|
*/ |
84
|
3 |
|
public function __call($name, $args = []) |
85
|
|
|
{ |
86
|
|
|
//Throw error if property is not found |
87
|
3 |
|
if (!$args = $this->validateArgs($args)) { |
88
|
|
|
throw new \Exception('Parameters need to be an array!'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
//Change ::new() to ::create() since it's a reserved word |
92
|
3 |
|
if (stripos($name, 'new') !== false) { |
93
|
1 |
|
$name = str_replace('new', 'create', $name); |
94
|
1 |
|
} |
95
|
3 |
|
$method = $this->getMethod($name); |
96
|
3 |
|
$property = explode($method, $name); |
97
|
3 |
|
$property = end($property); |
98
|
3 |
|
$config['name'] = $this->getArgs($property); |
|
|
|
|
99
|
3 |
|
$config['value'] = $args[0]; |
100
|
|
|
|
101
|
3 |
|
return $this->{$method}($config); |
102
|
|
|
} |
103
|
|
|
|
104
|
3 |
|
private function validateArgs($args) |
105
|
|
|
{ |
106
|
3 |
|
if (!is_array($args)) { |
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
3 |
|
foreach ($args[0] as $value) { |
111
|
3 |
|
if (!is_int($value)) { |
112
|
|
|
return false; |
113
|
|
|
} |
114
|
3 |
|
} |
115
|
|
|
|
116
|
3 |
|
return array_change_key_case($args, CASE_LOWER); |
117
|
|
|
} |
118
|
|
|
|
119
|
3 |
|
private function getMethod($name) |
120
|
|
|
{ |
121
|
3 |
|
foreach(get_class_methods($this) as $method) { |
122
|
3 |
|
if(stripos($name, $method) !== false) { |
123
|
3 |
|
return $method; |
124
|
|
|
} |
125
|
3 |
|
} |
126
|
|
|
|
127
|
|
|
throw new \Exception('Method not found'); |
128
|
|
|
} |
129
|
|
|
|
130
|
3 |
|
private function getArgs($name) |
131
|
|
|
{ |
132
|
3 |
|
foreach(get_object_vars($this) as $property => $value) { |
133
|
3 |
|
if (stripos($property, $name) !== false) { |
134
|
3 |
|
return $property; |
135
|
|
|
} |
136
|
1 |
|
} |
137
|
|
|
|
138
|
|
|
throw new \Exception('Property not found'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Add new key and value for chosen config (property) |
143
|
|
|
* |
144
|
|
|
* @param array $config name of config and it's key and value |
145
|
|
|
* @return void |
146
|
|
|
*/ |
147
|
1 |
|
private function add($config = []) |
148
|
|
|
{ |
149
|
1 |
|
$this->{$config['name']} += $config['value']; |
150
|
1 |
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Overwrite default configuration (key and) value |
154
|
|
|
* |
155
|
|
|
* @uses ::new() |
156
|
|
|
* @param array $config name of config and it's key and value |
157
|
|
|
* @return void |
158
|
|
|
*/ |
159
|
1 |
|
private function create($config = []) |
160
|
|
|
{ |
161
|
1 |
|
$this->{$config['name']} = $config['value']; |
162
|
1 |
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Modify value of configuration key |
166
|
|
|
* |
167
|
|
|
* @param array $config name of config and it's key and value |
168
|
|
|
* @return void |
169
|
|
|
*/ |
170
|
1 |
|
private function set($config = []) |
171
|
|
|
{ |
172
|
1 |
|
$this->{$config['name']} = $config['value'] + $this->{$config['name']}; |
173
|
1 |
|
} |
174
|
|
|
} |
175
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.