|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Library\System\Setting; |
|
4
|
|
|
|
|
5
|
|
|
use Leonidas\Contracts\System\Setting\SettingBuilderInterface; |
|
6
|
|
|
use Leonidas\Contracts\System\Setting\SettingHandlerInterface; |
|
7
|
|
|
use Leonidas\Library\System\Setting\Traits\HasSettingDataTrait; |
|
8
|
|
|
|
|
9
|
|
|
class SettingBuilder implements SettingBuilderInterface |
|
10
|
|
|
{ |
|
11
|
|
|
use HasSettingDataTrait; |
|
12
|
|
|
|
|
13
|
|
|
protected ?SettingHandlerInterface $handler = null; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct(string $optionName) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->optionName = $optionName; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function optionGroup(string $optionGroup) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->optionGroup = $optionGroup; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function optionName(string $optionName) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->optionName = $optionName; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function type(?string $type) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->type = $type; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function description(?string $description) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->description = $description; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function schema($schema) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->restSchema = $schema; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function default($default) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->defaultValue = $default; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function extra(?array $extraArgs) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->extraArgs = $extraArgs; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function handler(?SettingHandlerInterface $handler) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->handler = $handler; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getHandler(): ?SettingHandlerInterface |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->handler; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function get(): Setting |
|
66
|
|
|
{ |
|
67
|
|
|
return new Setting( |
|
68
|
|
|
$this->getOptionGroup(), |
|
69
|
|
|
$this->getOptionName(), |
|
70
|
|
|
$this->getType(), |
|
71
|
|
|
$this->getDescription(), |
|
72
|
|
|
$this->getHandler(), |
|
73
|
|
|
$this->getRestSchema(), |
|
74
|
|
|
$this->getDefaultValue(), |
|
75
|
|
|
$this->getExtraArgs() |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public static function for(string $optionName): SettingBuilder |
|
80
|
|
|
{ |
|
81
|
|
|
return new static($optionName); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|