|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author oliverde8<[email protected]> |
|
4
|
|
|
* @category @category oliverde8/ComfyBundle |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace oliverde8\ComfyBundle\Model; |
|
8
|
|
|
|
|
9
|
|
|
use oliverde8\ComfyBundle\Manager\ConfigManagerInterface; |
|
10
|
|
|
use Symfony\Component\Validator\Constraint; |
|
|
|
|
|
|
11
|
|
|
use Symfony\Component\Validator\Constraints\Collection; |
|
|
|
|
|
|
12
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank; |
|
|
|
|
|
|
13
|
|
|
use Symfony\Component\Validator\ConstraintViolationListInterface; |
|
|
|
|
|
|
14
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class TextConfig implements ConfigInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var ConfigManagerInterface */ |
|
19
|
|
|
protected $confgManager; |
|
20
|
|
|
|
|
21
|
|
|
/** @var ValidatorInterface */ |
|
22
|
|
|
protected $validator; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
protected $path; |
|
26
|
|
|
|
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
private $name; |
|
29
|
|
|
|
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
private $description; |
|
32
|
|
|
|
|
33
|
|
|
/** @var int */ |
|
34
|
|
|
private $scope; |
|
35
|
|
|
|
|
36
|
|
|
/** @var bool */ |
|
37
|
|
|
private $isHidden; |
|
38
|
|
|
|
|
39
|
|
|
/** @var string|null */ |
|
40
|
|
|
private $defaultValue; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* AbstractConfig constructor. |
|
44
|
|
|
* @param ConfigManagerInterface $configManager |
|
45
|
|
|
* @param ValidatorInterface $validator |
|
46
|
|
|
* @param string $path |
|
47
|
|
|
* @param string $name |
|
48
|
|
|
* @param string $description |
|
49
|
|
|
* @param int $scope |
|
50
|
|
|
* @param string|null $defaultValue |
|
51
|
|
|
* @param bool $isHidden |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct( |
|
54
|
|
|
ConfigManagerInterface $configManager, |
|
55
|
|
|
ValidatorInterface $validator, |
|
56
|
|
|
string $path, |
|
57
|
|
|
string $name, |
|
58
|
|
|
string $description = "", |
|
59
|
|
|
int $scope = PHP_INT_MAX, |
|
60
|
|
|
?string $defaultValue = null, |
|
61
|
|
|
bool $isHidden = false |
|
62
|
|
|
) { |
|
63
|
|
|
$this->confgManager = $configManager; |
|
64
|
|
|
$this->validator = $validator; |
|
65
|
|
|
$this->path = $path; |
|
66
|
|
|
$this->name = $name; |
|
67
|
|
|
$this->description = $description; |
|
68
|
|
|
$this->scope = $scope; |
|
69
|
|
|
$this->isHidden = $isHidden; |
|
70
|
|
|
$this->defaultValue = $defaultValue; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @inheritDoc |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getPath(): string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->path; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @inheritDoc |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getName(): string |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->name; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @inheritDoc |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getDescription(): string |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->description; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @inheritDoc |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getScope(): int |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->scope; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @inheritDoc |
|
107
|
|
|
*/ |
|
108
|
|
|
public function isHidden(): bool |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->isHidden; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @inheritDoc |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getDefaultValue() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->defaultValue; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @inheritDoc |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getRawValue(string $scope = null): ?string |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->confgManager->get($this->path, $scope); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @inheritDoc |
|
131
|
|
|
*/ |
|
132
|
|
|
public function set($value, string $scope = null): ConfigInterface |
|
133
|
|
|
{ |
|
134
|
|
|
if (is_null($value)) { |
|
135
|
|
|
// Don't serialize null value when setting new value in the config manager. Null is null. |
|
136
|
|
|
$this->confgManager->set($this->path, null, $scope); |
|
137
|
|
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
$this->confgManager->set($this->path, $this->serialize($value), $scope); |
|
140
|
|
|
|
|
141
|
|
|
return $this; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @inheritDoc |
|
146
|
|
|
*/ |
|
147
|
|
|
public function validate(&$value, string $scope = null): ConstraintViolationListInterface |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->validator->validate($value, $this->getValidationConstraints()); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @inheritDoc |
|
154
|
|
|
*/ |
|
155
|
|
|
public function get(string $scope = null) |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->deserialize($this->confgManager->get($this->path, $scope)); |
|
158
|
|
|
} |
|
159
|
|
|
/** |
|
160
|
|
|
* @inheritDoc |
|
161
|
|
|
*/ |
|
162
|
|
|
public function doesInherit(string $scope = null) |
|
163
|
|
|
{ |
|
164
|
|
|
return $this->confgManager->doesInhertit($this->path, $scope); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Serialize value to save it in Database. |
|
169
|
|
|
* |
|
170
|
|
|
* @param $value |
|
171
|
|
|
* |
|
172
|
|
|
* @return string|null |
|
173
|
|
|
*/ |
|
174
|
|
|
protected function serialize($value): ?string |
|
175
|
|
|
{ |
|
176
|
|
|
return $value; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Deserialize value read from database. |
|
181
|
|
|
* |
|
182
|
|
|
* @param string|null $value |
|
183
|
|
|
* |
|
184
|
|
|
* @return mixed|null |
|
185
|
|
|
*/ |
|
186
|
|
|
protected function deserialize(?string $value) |
|
187
|
|
|
{ |
|
188
|
|
|
return $value; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Get validaiton constraints. |
|
193
|
|
|
* |
|
194
|
|
|
* @return Constraint |
|
195
|
|
|
*/ |
|
196
|
|
|
protected function getValidationConstraints() |
|
197
|
|
|
{ |
|
198
|
|
|
return new NotBlank(); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths