|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Settings Manager |
|
5
|
|
|
* |
|
6
|
|
|
* @license http://opensource.org/licenses/MIT |
|
7
|
|
|
* @link https://github.com/caseyamcl/settings-manager |
|
8
|
|
|
* @package caseyamcl/settings-manager |
|
9
|
|
|
* @author Casey McLaughlin <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
12
|
|
|
* file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* ------------------------------------------------------------------ |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
declare(strict_types=1); |
|
18
|
|
|
|
|
19
|
|
|
namespace SettingsManager\Provider; |
|
20
|
|
|
|
|
21
|
|
|
use SettingsManager\Behavior\SettingProviderTrait; |
|
22
|
|
|
use SettingsManager\Contract\SettingProvider; |
|
23
|
|
|
use SettingsManager\Model\SettingValue; |
|
24
|
|
|
use SettingsManager\Registry\SettingDefinitionRegistry; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Defaults Provider |
|
28
|
|
|
* |
|
29
|
|
|
* Reads default values |
|
30
|
|
|
* |
|
31
|
|
|
* @author Casey McLaughlin <[email protected]> |
|
32
|
|
|
*/ |
|
33
|
|
|
class DefaultValuesProvider implements SettingProvider |
|
34
|
|
|
{ |
|
35
|
|
|
use SettingProviderTrait; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var SettingDefinitionRegistry |
|
39
|
|
|
*/ |
|
40
|
|
|
private $registry; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* DefaultProvider constructor. |
|
44
|
|
|
* @param SettingDefinitionRegistry $registry |
|
45
|
|
|
*/ |
|
46
|
60 |
|
public function __construct(SettingDefinitionRegistry $registry) |
|
47
|
|
|
{ |
|
48
|
60 |
|
$this->registry = $registry; |
|
49
|
60 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
57 |
|
public function getName(): string |
|
55
|
|
|
{ |
|
56
|
57 |
|
return 'defaults'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
3 |
|
public function getDisplayName(): string |
|
63
|
|
|
{ |
|
64
|
3 |
|
return 'Default setting values'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Return a key/value set of setting names/values |
|
69
|
|
|
* |
|
70
|
|
|
* @return iterable|SettingValue[] |
|
71
|
|
|
*/ |
|
72
|
54 |
|
public function getSettingValues(): iterable |
|
73
|
|
|
{ |
|
74
|
54 |
|
$out = []; |
|
75
|
|
|
|
|
76
|
54 |
|
foreach ($this->registry->getIterator() as $setting) { |
|
77
|
54 |
|
$out[$setting->getName()] = new SettingValue($setting->getName(), $this, true, $setting->getDefault()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
54 |
|
return $out; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
18 |
|
public function findValueInstance(string $settingName): ?SettingValue |
|
84
|
|
|
{ |
|
85
|
18 |
|
return ($this->getSettingValues()[$settingName]) ?? null; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|