PluginProbe
User Access Manager / 2.3.16
User Access Manager v2.3.16
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Config/Config.php +24 -16 trunk2.3.16 View file →
@@ -4,13 +4,13 @@
4 4
5 5 namespace UserAccessManager\Config;
6 6
7 7 use Exception;
8 -use UserAccessManager\Config\Parameter\ConfigParameter;
9 8 use UserAccessManager\Wrapper\Wordpress;
10 9
11 10 class Config
12 11 {
12 + protected string $key;
13 13 protected array $wpOptions = [];
14 14 /**
15 15 * @var ConfigParameter[]
16 16 */
@@ -21,15 +21,16 @@
21 21 protected ?array $configParameters = null;
22 22
23 23 public function __construct(
24 24 private Wordpress $wordpress,
25 - protected string $key
25 + string $key
26 26 ) {
27 + $this->key = $key;
27 28 }
28 29
29 30 public function getWpOption(string $option): mixed
30 31 {
31 - if (isset($this->wpOptions[$option]) === false) {
32 + if (!isset($this->wpOptions[$option]) === true) {
32 33 $this->wpOptions[$option] = $this->wordpress->getOption($option);
33 34 }
34 35
35 36 return $this->wpOptions[$option];
@@ -55,23 +56,27 @@
55 56 * @return ConfigParameter[]
56 57 */
57 58 public function getConfigParameters(): array
58 59 {
59 - if ($this->configParameters !== null) {
60 - return $this->configParameters;
61 - }
60 + if ($this->configParameters === null) {
61 + $configParameters = $this->getDefaultConfigParameters();
62 + $currentOptions = (array) $this->getWpOption($this->key);
62 63
63 - $configParameters = $this->getDefaultConfigParameters();
64 + foreach ($currentOptions as $key => $option) {
65 + if (isset($configParameters[$key])) {
66 + $configParameters[$key]->setValue($option);
67 + }
68 + }
64 69
65 - foreach ((array) $this->getWpOption($this->key) as $key => $option) {
66 - if (isset($configParameters[$key]) === true) {
67 - $configParameters[$key]->setValue($option);
68 - }
70 + $this->configParameters = $configParameters;
69 71 }
70 72
71 - return $this->configParameters = $configParameters;
73 + return $this->configParameters;
72 74 }
73 75
76 + /**
77 + * @param array $rawParameters
78 + */
74 79 public function setConfigParameters(array $rawParameters): void
75 80 {
76 81 $configParameters = $this->getConfigParameters();
77 82
@@ -80,15 +85,17 @@
80 85 $configParameters[$key]->setValue($value);
81 86 }
82 87 }
83 88
84 - $persistableValues = [];
89 + $this->configParameters = $configParameters;
85 90
91 + $simpleConfigParameters = [];
92 +
86 93 foreach ($configParameters as $parameter) {
87 - $persistableValues[$parameter->getId()] = $parameter->getValue();
94 + $simpleConfigParameters[$parameter->getId()] = $parameter->getValue();
88 95 }
89 96
90 - $this->wordpress->updateOption($this->key, $persistableValues);
97 + $this->wordpress->updateOption($this->key, $simpleConfigParameters);
91 98 }
92 99
93 100 public function flushConfigParameters(): void
94 101 {
@@ -114,8 +121,9 @@
114 121 {
115 122 try {
116 123 return $this->getParameterValueRaw($parameterName);
117 124 } catch (Exception) {
118 - return null;
119 125 }
126 +
127 + return null;
120 128 }
121 129 }